Author: jm
Date: 2012-06-14 12:57:25 -0700 (Thu, 14 Jun 2012)
New Revision: 29565
Modified:
core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyTable.java
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/available/dummies/DummyTable.java
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/DefaultTablesNetwork.java
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/CyTableProjection.java
Log:
Fixes #1111: Added API for deleting CyRows. Deleting graph elements causes
corresponding CyRows to be deleted.
Modified:
core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyTable.java
===================================================================
--- core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyTable.java
2012-06-14 18:37:01 UTC (rev 29564)
+++ core3/api/trunk/model-api/src/main/java/org/cytoscape/model/CyTable.java
2012-06-14 19:57:25 UTC (rev 29565)
@@ -214,6 +214,14 @@
boolean rowExists(Object primaryKey);
/**
+ * Deletes the rows corresponding to the given primary keys and returns
true if
+ * at least one row was deleted.
+ * @param primaryKeys The primary keys of the rows to delete.
+ * @return true if at least one row was deleted.
+ */
+ boolean deleteRows(Collection<?> primaryKeys);
+
+ /**
* Return a list of all the rows stored in this data table.
* @return a list of all the rows stored in this data table.
*/
Modified:
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/available/dummies/DummyTable.java
===================================================================
---
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/available/dummies/DummyTable.java
2012-06-14 18:37:01 UTC (rev 29564)
+++
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/available/dummies/DummyTable.java
2012-06-14 19:57:25 UTC (rev 29565)
@@ -33,4 +33,5 @@
public SavePolicy getSavePolicy() { return null; }
public void setSavePolicy(SavePolicy policy) {}
public void swap(CyTable otherTable) {}
+ public boolean deleteRows(Collection<?> primaryKeys) { return false; }
}
Modified:
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
===================================================================
---
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
2012-06-14 18:37:01 UTC (rev 29564)
+++
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
2012-06-14 19:57:25 UTC (rev 29565)
@@ -1049,6 +1049,38 @@
return name;
}
+ @Override
+ public boolean deleteRows(Collection<?> primaryKeys) {
+ boolean changed = false;
+ synchronized(this) {
+ for (Object key : primaryKeys) {
+ checkKey(key);
+
+ CyRow row = rows.remove(key);
+ if (row != null) {
+ changed = true;
+ }
+
+ for (CyColumn col : getColumns()) {
+ final String normalizedColName =
normalizeColumnName(col.getName());
+ final Map<Object, Object> keyToValueMap =
attributes.get(normalizedColName);
+ if (keyToValueMap != null) {
+ Object val = keyToValueMap.remove(key);
+ SetMultimap<Object,Object> valueToKeysMap =
reverse.get(normalizedColName);
+ if (valueToKeysMap != null) {
+ Set<Object> keys = valueToKeysMap.get(val);
+ if (keys != null) {
+ keys.remove(key);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return changed;
+ }
+
private final class InternalRow implements CyRow {
private final Object key;
Modified:
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/DefaultTablesNetwork.java
===================================================================
---
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/DefaultTablesNetwork.java
2012-06-14 18:37:01 UTC (rev 29564)
+++
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/DefaultTablesNetwork.java
2012-06-14 19:57:25 UTC (rev 29565)
@@ -30,6 +30,8 @@
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.Collection;
import org.cytoscape.model.CyEdge;
import org.cytoscape.model.CyIdentifiable;
@@ -169,5 +171,34 @@
return InitialTableSize.SMALL;
}
-
+ @Override
+ protected boolean removeNodesInternal(Collection<CyNode> nodes) {
+ boolean result = super.removeNodesInternal(nodes);
+ if (!result)
+ return false;
+
+ removeRows(nodes, CyNode.class);
+ return result;
+ }
+
+ @Override
+ protected boolean removeEdgesInternal(Collection<CyEdge> edges) {
+ boolean result = super.removeEdgesInternal(edges);
+ if (!result)
+ return false;
+
+ removeRows(edges, CyEdge.class);
+ return result;
+ }
+
+ private <T extends CyIdentifiable> void removeRows(Collection<T> items,
Class<? extends T> type) {
+ Collection<Long> primaryKeys = new ArrayList<Long>();
+ for (T item : items) {
+ primaryKeys.add(item.getSUID());
+ }
+
+ for (CyTable table :
networkTableManager.getTables(networkRef.get(), type).values()) {
+ table.deleteRows(primaryKeys);
+ }
+ }
}
Modified:
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/CyTableProjection.java
===================================================================
---
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/CyTableProjection.java
2012-06-14 18:37:01 UTC (rev 29564)
+++
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/CyTableProjection.java
2012-06-14 19:57:25 UTC (rev 29565)
@@ -378,4 +378,9 @@
public void setPublic(boolean isPublic) {
throw new UnsupportedOperationException("setPublic(boolean
isPublic) method not supported!");
}
+
+ @Override
+ public boolean deleteRows(Collection<?> primaryKeys) {
+ throw new UnsupportedOperationException("deleteRows() method
not supported!");
+ }
}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.