Author: rozagh
Date: 2012-04-10 11:41:14 -0700 (Tue, 10 Apr 2012)
New Revision: 28781
Added:
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ColumnSetListener.java
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/InteractionSetListener.java
Modified:
core3/api/trunk/model-api/src/main/java/org/cytoscape/model/subnetwork/CyRootNetwork.java
core3/api/trunk/model-api/src/test/java/org/cytoscape/model/subnetwork/AbstractCySubNetworkTest.java
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/AddEdgeTask.java
core3/impl/trunk/editor-impl/src/main/java/org/cytoscape/editor/internal/AddNodeTask.java
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyRootNetworkImpl.java
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CySubNetworkImpl.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/NameSetListener.java
Log:
fixes #733 #748 The copyDefaultAttribute method in CySubNetworkImpl was failed
because the required columns cannot be passed correctly from the root network.
Other bugs related to the table browser and the nameSetListener and adding edge
and node tasks are also fixed. A shared interaction column is added to the
CyRootNetwork to carry the interaction data between different subnetworks.
Modified:
core3/api/trunk/model-api/src/main/java/org/cytoscape/model/subnetwork/CyRootNetwork.java
===================================================================
---
core3/api/trunk/model-api/src/main/java/org/cytoscape/model/subnetwork/CyRootNetwork.java
2012-04-10 16:55:42 UTC (rev 28780)
+++
core3/api/trunk/model-api/src/main/java/org/cytoscape/model/subnetwork/CyRootNetwork.java
2012-04-10 18:41:14 UTC (rev 28781)
@@ -79,6 +79,13 @@
* as a join key for virtual columns to be added to the shared table.
*/
String SHARED_NAME = "shared name";
+
+ /**
+ * The name of the shared interaction column found in the SHARED_ATTRS
table. This
+ * column value will be updated any time the value of the
CyNetwork.EDGE
+ * column in a default table is set.
+ */
+ String SHARED_INTERACTION = "shared interaction";
/**
* Create an empty {@link CySubNetwork}.
Modified:
core3/api/trunk/model-api/src/test/java/org/cytoscape/model/subnetwork/AbstractCySubNetworkTest.java
===================================================================
---
core3/api/trunk/model-api/src/test/java/org/cytoscape/model/subnetwork/AbstractCySubNetworkTest.java
2012-04-10 16:55:42 UTC (rev 28780)
+++
core3/api/trunk/model-api/src/test/java/org/cytoscape/model/subnetwork/AbstractCySubNetworkTest.java
2012-04-10 18:41:14 UTC (rev 28781)
@@ -404,14 +404,13 @@
List<CyNode> subNodes = sub.getNodeList();
assertTrue(
sub.getRow(subNodes.get(0)).get(CyNetwork.SELECTED,Boolean.class) );
}
-/*
+
@Test
public void testEdgeAddedInSubnetworkHasNameAttr() {
n1 = root.addNode();
n2 = root.addNode();
e1 = root.addEdge(n1,n2,true);
root.getRow(e1).set(CyNetwork.NAME,"homer");
- root.getRow(e1).set(CyEdge.INTERACTION, "pp");
root.getSharedEdgeTable().getRow(e1.getSUID()).set(CyRootNetwork.SHARED_NAME,"homer");
@@ -429,17 +428,19 @@
final CyRow row = sub.getRow(newEdge);
assertEquals( "homer", row.get(CyRootNetwork.SHARED_NAME,
String.class));
- assertEquals( "homer", row.get(CyNetwork.NAME, String.class));
- assertEquals( "pp", row.get(CyEdge.INTERACTION, String.class));
+ assertEquals( "homer", row.get(CyNetwork.NAME, String.class));
}
-*/
+
+
@Test
public void testEdgeAddedInSubnetworkHasInteractionAttr() {
n1 = root.addNode();
n2 = root.addNode();
e1 = root.addEdge(n1,n2,true);
root.getRow(e1).set(CyEdge.INTERACTION,"marge");
+
root.getSharedEdgeTable().getRow(e1.getSUID()).set(CyRootNetwork.SHARED_INTERACTION,"marge");
+
sub = root.addSubNetwork();
sub.addNode(n1);
sub.addNode(n2);
@@ -448,7 +449,8 @@
List<CyEdge> subEdges = sub.getEdgeList();
assertEquals( "marge",
sub.getRow(subEdges.get(0)).get(CyEdge.INTERACTION,String.class) );
}
-/*
+
+
@Test
public void testEdgeAddedInSubnetworkHasSelectedAttr() {
n1 = root.addNode();
@@ -464,7 +466,7 @@
List<CyEdge> subEdges = sub.getEdgeList();
assertTrue(sub.getRow(subEdges.get(0)).get(CyNetwork.SELECTED,Boolean.class) );
}
-*/
+
/**
* Test for checking contents of tables in the subnetworks.
Modified:
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/AddEdgeTask.java
===================================================================
---
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/AddEdgeTask.java
2012-04-10 16:55:42 UTC (rev 28780)
+++
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/AddEdgeTask.java
2012-04-10 18:41:14 UTC (rev 28781)
@@ -22,6 +22,7 @@
public class AddEdgeTask extends AbstractNodeViewTask {
private static final Logger logger =
LoggerFactory.getLogger(AddEdgeTask.class);
+ private static int numberofedges = 1;
public AddEdgeTask(View<CyNode> nv, CyNetworkView view){
super(nv,view);
@@ -48,10 +49,14 @@
CyNode targetNode = nodeView.getModel();
CyEdge newEdge =
net.addEdge(sourceNode,targetNode,true);
- final String edgeName =
net.getRow(sourceNode).get(CyRootNetwork.SHARED_NAME, String.class)
+"_TO_"+net.getRow(targetNode).get(CyRootNetwork.SHARED_NAME, String.class);
+ final String interaction = "interaction";
+ String edgeName =
net.getRow(sourceNode).get(CyRootNetwork.SHARED_NAME, String.class);
+ edgeName+=" (" + interaction + ") ";
+ edgeName+=
net.getRow(targetNode).get(CyRootNetwork.SHARED_NAME, String.class);
CyRow edgeRow = net.getRow(newEdge,
CyNetwork.DEFAULT_ATTRS);
edgeRow.set(CyNetwork.NAME, edgeName);
+ edgeRow.set(CyEdge.INTERACTION, interaction);
netView.updateView();
AddEdgeStateMonitor.setSourceNode(netView,null);
Modified:
core3/impl/trunk/editor-impl/src/main/java/org/cytoscape/editor/internal/AddNodeTask.java
===================================================================
---
core3/impl/trunk/editor-impl/src/main/java/org/cytoscape/editor/internal/AddNodeTask.java
2012-04-10 16:55:42 UTC (rev 28780)
+++
core3/impl/trunk/editor-impl/src/main/java/org/cytoscape/editor/internal/AddNodeTask.java
2012-04-10 18:41:14 UTC (rev 28781)
@@ -49,11 +49,6 @@
final String nodeName = "Node "+ new_node_index;
new_node_index++;
-
- final CyRootNetwork parentNetwork = rnm.getRootNetwork(net);
- parentNetwork.getRow(n,
CyRootNetwork.SHARED_ATTRS).set(CyRootNetwork.SHARED_NAME, nodeName);
-
parentNetwork.getSharedNodeTable().getRow(n.getSUID()).set(CyRootNetwork.SHARED_NAME,
nodeName);
-
final CyRow nodeRow = net.getRow(n);
nodeRow.set(CyNetwork.NAME, nodeName);
Added:
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ColumnSetListener.java
===================================================================
---
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ColumnSetListener.java
(rev 0)
+++
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ColumnSetListener.java
2012-04-10 18:41:14 UTC (rev 28781)
@@ -0,0 +1,60 @@
+package org.cytoscape.model.internal;
+
+import java.util.List;
+
+import org.cytoscape.model.CyEdge;
+import org.cytoscape.model.CyIdentifiable;
+import org.cytoscape.model.CyRow;
+import org.cytoscape.model.CyTable;
+import org.cytoscape.model.events.RowSetRecord;
+import org.cytoscape.model.events.RowsSetEvent;
+import org.cytoscape.model.events.RowsSetListener;
+import org.cytoscape.model.subnetwork.CyRootNetwork;
+
+public class ColumnSetListener implements RowsSetListener {
+
+ private final WeakMapList<CyTable,CyTable> tables;
+ private final String columnName;
+ private final String sharedColumnName;
+
+ ColumnSetListener(final String columnName, final String
sharedColumnName) {
+ tables = new WeakMapList<CyTable,CyTable>();
+ this.columnName = columnName;
+ this.sharedColumnName = sharedColumnName;
+ }
+
+ public void handleEvent(RowsSetEvent e) {
+
+ final CyTable local = e.getSource();
+ final List<CyTable> sharedList = tables.get(local);
+
+ for ( CyTable shared : sharedList ) {
+ for ( RowSetRecord record : e.getPayloadCollection() ) {
+ // assume payload collection is for same column
+ if ( !record.getColumn().equals(columnName))
+ continue;
+ final CyRow r =
shared.getRow(record.getRow().get( CyIdentifiable.SUID, Long.class ));
+ if( r != null ) {
+ final Object name = record.getValue();
+ String sharedName =
r.get(sharedColumnName, String.class);
+ if(sharedName == null){
+ r.set(sharedColumnName, name);
+ }
+ }
+ }
+ }
+ }
+
+ public void addInterestedTables(CyTable local, CyTable shared) {
+
+ if ( shared == null )
+ throw new NullPointerException("source table is null");
+ if ( local == null )
+ throw new NullPointerException("target table is null");
+ if ( shared == local )
+ throw new IllegalArgumentException("source and target
tables cannot be the same!");
+
+ tables.put(local,shared);
+ }
+
+}
\ No newline at end of file
Modified:
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyRootNetworkImpl.java
===================================================================
---
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyRootNetworkImpl.java
2012-04-10 16:55:42 UTC (rev 28780)
+++
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyRootNetworkImpl.java
2012-04-10 18:41:14 UTC (rev 28781)
@@ -74,7 +74,8 @@
private final CyTableFactory tableFactory;
private final boolean publicTables;
private final VirtualColumnAdder columnAdder;
-// private final NameSetListener nameSetListener;
+ private final NameSetListener nameSetListener;
+ private final InteractionSetListener interactionSetListener;
private final NetworkAddedListenerDelegator
networkAddedListenerDelegator;
private int nextNodeIndex;
@@ -103,8 +104,10 @@
columnAdder = new VirtualColumnAdder();
serviceRegistrar.registerService(columnAdder,
ColumnCreatedListener.class, new Properties());
-// nameSetListener = new NameSetListener();
-// serviceRegistrar.registerService(nameSetListener,
RowsSetListener.class, new Properties());
+ nameSetListener = new NameSetListener();
+ serviceRegistrar.registerService(nameSetListener,
RowsSetListener.class, new Properties());
+ interactionSetListener = new InteractionSetListener();
+ serviceRegistrar.registerService(interactionSetListener,
RowsSetListener.class, new Properties());
networkAddedListenerDelegator = new
NetworkAddedListenerDelegator();
serviceRegistrar.registerService(networkAddedListenerDelegator,
NetworkAddedListener.class, new Properties());
@@ -128,6 +131,7 @@
networkTableMgr.setTable(this, CyEdge.class,
CyRootNetwork.SHARED_ATTRS, edgeSharedTable);
edgeSharedTable.createColumn(CyRootNetwork.SHARED_NAME,
String.class, true);
+ edgeSharedTable.createColumn(CyRootNetwork.SHARED_INTERACTION,
String.class, true);
//edgeSharedTable.addVirtualColumn(SHARED_NAME, NAME,
getDefaultEdgeTable(), SUID, false);
final CyTable networkSharedTable = tableFactory.createTable(suid
@@ -145,16 +149,17 @@
getRow(this).set(CyNetwork.NAME, "");
}
- private void linkDefaultTables(CyTable srcTable, CyTable tgtTable) {
+ private void linkDefaultTables(CyTable sharedTable, CyTable localTable)
{
// Add all columns from source table as virtual columns in
target table.
- tgtTable.addVirtualColumns(srcTable, CyIdentifiable.SUID, true);
+ localTable.addVirtualColumns(sharedTable, CyIdentifiable.SUID,
true);
// Now add a listener for column created events to add
// virtual columns to any subsequent source columns added.
- columnAdder.addInterestedTables(srcTable,tgtTable);
+ columnAdder.addInterestedTables(sharedTable,localTable);
// Another listener tracks changes to the NAME column in local
tables
- //nameSetListener.addInterestedTables(srcTable,tgtTable);
+ nameSetListener.addInterestedTables(localTable, sharedTable);
+
}
@Override
@@ -231,10 +236,12 @@
CyTable networkTable = networkTableMgr.getTable(this,
CyNetwork.class, CyRootNetwork.SHARED_ATTRS);
CyTable nodeTable = networkTableMgr.getTable(this,
CyNode.class, CyRootNetwork.SHARED_ATTRS);
CyTable edgeTable = networkTableMgr.getTable(this,
CyEdge.class, CyRootNetwork.SHARED_ATTRS);
-
+
linkDefaultTables(networkTable, sub.getDefaultNetworkTable());
linkDefaultTables(nodeTable, sub.getDefaultNodeTable());
linkDefaultTables(edgeTable, sub.getDefaultEdgeTable());
+ // Another listener tracks changes to the interaction column in
local tables
+
interactionSetListener.addInterestedTables(sub.getDefaultEdgeTable(),
edgeTable);
subNetworks.add(sub);
return sub;
Modified:
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CySubNetworkImpl.java
===================================================================
---
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CySubNetworkImpl.java
2012-04-10 16:55:42 UTC (rev 28780)
+++
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CySubNetworkImpl.java
2012-04-10 18:41:14 UTC (rev 28781)
@@ -182,13 +182,18 @@
return true;
}
-
+ /**
+ * This method is called when an edge or a node is added to the networks
+ * which is indeed a copy of another edge/node. Hence, it copies all of
the
+ * default attributes from the shared table referenced to that
edge/node to
+ * the new edge/node.
+ * @param graphObject
+ */
private void copyTableData(final CyIdentifiable graphObject) {
final String name = parent.getRow(graphObject).get(NAME,
String.class);
final CyRow sharedTableRow = parent.getRow(graphObject,
CyRootNetwork.SHARED_ATTRS);
final CyRow defaultTableRow = parent.getRow(graphObject);
final CyRow targetRow = this.getRow(graphObject);
- if(graphObject instanceof CyNode) {
// Step 1: Copy shared name as name of this new node
final String sharedName =
sharedTableRow.get(CyRootNetwork.SHARED_NAME, String.class);
@@ -199,10 +204,10 @@
// Step 2: Copy selection state
targetRow.set(CyNetwork.SELECTED,
defaultTableRow.get(CyNetwork.SELECTED, Boolean.class));
- }
+
// Step 3: Copy Interaction if edge
if(graphObject instanceof CyEdge) {
- final String interaction =
defaultTableRow.get(CyEdge.INTERACTION, String.class);
+ final String interaction =
sharedTableRow.get(CyRootNetwork.SHARED_INTERACTION, String.class);
targetRow.set(CyEdge.INTERACTION, interaction);
}
}
@@ -261,6 +266,7 @@
updateSharedNames( getDefaultNodeTable(),
parent.getSharedNodeTable() );
updateSharedNames( getDefaultEdgeTable(),
parent.getSharedEdgeTable() );
+ updateSharedInteractions(getDefaultEdgeTable(),
parent.getSharedEdgeTable() );
updateSharedNames( getDefaultNetworkTable(),
parent.getSharedNetworkTable() );
}
@@ -271,6 +277,12 @@
}
}
+ private void updateSharedInteractions(CyTable src, CyTable tgt) {
+ for ( CyRow sr : src.getAllRows() ) {
+ CyRow tr = tgt.getRow(
sr.get(CyIdentifiable.SUID,Long.class) );
+ tr.set( CyRootNetwork.SHARED_INTERACTION,
sr.get(CyEdge.INTERACTION,String.class) );
+ }
+ }
@Override
public boolean equals(final Object o) {
if (!(o instanceof CySubNetworkImpl))
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-04-10 16:55:42 UTC (rev 28780)
+++
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
2012-04-10 18:41:14 UTC (rev 28781)
@@ -576,11 +576,12 @@
}
private void setX(final Object key, final String columnName, final
Object value) {
+
if (columnName == null)
throw new NullPointerException("columnName must not be
null!");
if (value == null)
throw new NullPointerException("value must not be
null!");
-
+
Object newValue;
Object newRawValue;
Added:
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/InteractionSetListener.java
===================================================================
---
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/InteractionSetListener.java
(rev 0)
+++
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/InteractionSetListener.java
2012-04-10 18:41:14 UTC (rev 28781)
@@ -0,0 +1,23 @@
+package org.cytoscape.model.internal;
+
+import java.util.List;
+
+
+import org.cytoscape.model.CyEdge;
+import org.cytoscape.model.CyIdentifiable;
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyRow;
+import org.cytoscape.model.CyTable;
+import org.cytoscape.model.events.RowSetRecord;
+import org.cytoscape.model.events.RowsSetEvent;
+import org.cytoscape.model.events.RowsSetListener;
+import org.cytoscape.model.subnetwork.CyRootNetwork;
+
+public class InteractionSetListener extends ColumnSetListener {
+
+
+ InteractionSetListener() {
+ super(CyEdge.INTERACTION, CyRootNetwork.SHARED_INTERACTION);
+ }
+
+}
Modified:
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/NameSetListener.java
===================================================================
---
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/NameSetListener.java
2012-04-10 16:55:42 UTC (rev 28780)
+++
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/NameSetListener.java
2012-04-10 18:41:14 UTC (rev 28781)
@@ -46,44 +46,12 @@
* in a local table, update the shared table with the
* new name.
*/
-class NameSetListener implements RowsSetListener {
+class NameSetListener extends ColumnSetListener {
- private final WeakMapList<CyTable,CyTable> tables;
-
NameSetListener() {
- tables = new WeakMapList<CyTable,CyTable>();
+ super(CyNetwork.NAME, CyRootNetwork.SHARED_NAME);
}
- public void handleEvent(RowsSetEvent e) {
-
- final CyTable local = e.getSource();
- final List<CyTable> sharedList = tables.get(local);
-
- for ( CyTable shared : sharedList ) {
- for ( RowSetRecord record : e.getPayloadCollection() ) {
- // assume payload collection is for same column
- if ( !record.getColumn().equals(CyNetwork.NAME)
)
- continue;
- final CyRow r =
shared.getRow(record.getRow().get( CyIdentifiable.SUID, Long.class ));
- if( r != null ) {
- final Object name = record.getValue();
- r.set(CyRootNetwork.SHARED_NAME, name);
-
- }
- }
- }
- }
-
- public void addInterestedTables(CyTable local, CyTable shared) {
- if ( shared == null )
- throw new NullPointerException("source table is null");
- if ( local == null )
- throw new NullPointerException("target table is null");
- if ( shared == local )
- throw new IllegalArgumentException("source and target
tables cannot be the same!");
-
- tables.put(local,shared);
- }
-
+
}
--
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.