Author: rozagh
Date: 2012-04-16 15:31:30 -0700 (Mon, 16 Apr 2012)
New Revision: 28846
Added:
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/NetworkNameSetListener.java
Modified:
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyRootNetworkImpl.java
Log:
fixes #859 Adding a NetworkNameSetListener which implements
NetworkAddedListener and RowsSetListener. The tables are renamed based on the
network name. When a network is created for the first time first root network
is consructed which creates the base network immediately. Since when networks
are created the rowssetevent is not fired, the networkaddedlistener is
implemented which sets the name of the table at first. If the networkaddedevent
is for the base network, it sets the root network name as well as the base
network's table titles. By setting the name of the root network, a rowssetevent
gets fired which will update the title of the shared and default tables for the
root network.
Each time that a network name is updated, the rowsset event is fired which
updates the title of the default tables for that network.
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-16 21:04:13 UTC (rev 28845)
+++
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyRootNetworkImpl.java
2012-04-16 22:31:30 UTC (rev 28846)
@@ -76,8 +76,10 @@
private final VirtualColumnAdder columnAdder;
private final NameSetListener nameSetListener;
private final InteractionSetListener interactionSetListener;
- private final NetworkAddedListenerDelegator
networkAddedListenerDelegator;
+ private final NetworkAddedListenerDelegator
networkAddedListenerDelegator;
+ private final NetworkNameSetListener networkNameSetListener;
+
private int nextNodeIndex;
private int nextEdgeIndex;
@@ -111,6 +113,9 @@
networkAddedListenerDelegator = new
NetworkAddedListenerDelegator();
serviceRegistrar.registerService(networkAddedListenerDelegator,
NetworkAddedListener.class, new Properties());
+ networkNameSetListener = new NetworkNameSetListener(this);
+ serviceRegistrar.registerService(networkNameSetListener,
RowsSetListener.class, new Properties());
+ serviceRegistrar.registerService(networkNameSetListener,
NetworkAddedListener.class, new Properties());
base = addSubNetwork();
registerAllTables(networkTableMgr.getTables(this,
CyNetwork.class).values());
@@ -132,7 +137,6 @@
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
+ " shared network", CyIdentifiable.SUID,
Long.class, publicTables, false, InitialTableSize.SMALL);
@@ -147,6 +151,8 @@
nodeSharedTable.createColumn(CyRootNetwork.SHARED_NAME,
String.class, true);
getRow(this).set(CyNetwork.NAME, "");
+
+
}
private void linkDefaultTables(CyTable sharedTable, CyTable localTable)
{
@@ -159,7 +165,7 @@
// Another listener tracks changes to the NAME column in local
tables
nameSetListener.addInterestedTables(localTable, sharedTable);
-
+
}
@Override
@@ -230,7 +236,7 @@
final long newSUID = SUIDFactory.getNextSUID();
final CySubNetworkImpl sub = new
CySubNetworkImpl(this,newSUID,eventHelper,tableMgr,networkTableMgr,
-
tableFactory,publicTables,subNetworks.size());
+
tableFactory,publicTables,subNetworks.size());
networkAddedListenerDelegator.addListener(sub);
CyTable networkTable = networkTableMgr.getTable(this,
CyNetwork.class, CyRootNetwork.SHARED_ATTRS);
@@ -261,7 +267,6 @@
}
}
-
@Override
public synchronized void removeSubNetwork(final CySubNetwork sub) {
if ( sub == null )
Added:
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/NetworkNameSetListener.java
===================================================================
---
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/NetworkNameSetListener.java
(rev 0)
+++
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/NetworkNameSetListener.java
2012-04-16 22:31:30 UTC (rev 28846)
@@ -0,0 +1,126 @@
+package org.cytoscape.model.internal;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+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.NetworkAddedEvent;
+import org.cytoscape.model.events.NetworkAddedListener;
+import org.cytoscape.model.events.RowSetRecord;
+import org.cytoscape.model.events.RowsSetEvent;
+import org.cytoscape.model.events.RowsSetListener;
+import org.cytoscape.model.subnetwork.CyRootNetwork;
+
+/**
+ * NetworkNameSetListener implements NetworkAddedListener and RowsSetListener.
+ * The tables are renamed based on the network name. When a network is created
+ * for the first time first root network is consructed which creates the base
network
+ * immediately. Since when networks are created the rowssetevent is not fired,
the
+ * networkaddedlistener is implemented which sets the name of the table at
first.
+ * If the networkaddedevent is for the base network, it sets the root network
name
+ * as well as the base network's table titles. By setting the name of the root
network,
+ * a rowssetevent gets fired which will update the title of the shared and
default
+ * tables for the root network.
+ * Each time that a network name is updated, the rowsset event is fired which
+ * updates the title of the default tables for that network.
+ * @author rozagh
+ *
+ */
+public class NetworkNameSetListener implements RowsSetListener,
NetworkAddedListener{
+
+ final CyRootNetwork rootNetwork;
+
+ public NetworkNameSetListener(CyRootNetwork rootNetwork){
+ this.rootNetwork = rootNetwork;
+ }
+
+ @Override
+ public void handleEvent(RowsSetEvent e) {
+ CyTable sourceTable = e.getSource();
+
+ if (sourceTable.equals(rootNetwork.getDefaultNetworkTable())){
+ updateRootNetworkTableNames(e.getPayloadCollection());
+ }
+ else{
+ updateSubNetworkTableNames(e.getPayloadCollection(),
sourceTable);
+ }
+
+
+ }
+
+ private void updateSubNetworkTableNames( Collection<RowSetRecord>
payloadCollection, CyTable sourceTable) {
+
+ for (CyNetwork net: rootNetwork.getSubNetworkList()){
+ if (sourceTable.equals(net.getDefaultNetworkTable())){
+ for ( RowSetRecord record :payloadCollection) {
+ // assume payload collection is for
same column
+ if (
!record.getColumn().equals(CyNetwork.NAME))
+ break;
+
+ final Object name = record.getValue();
+ setTablesName(name.toString() + "
default ", net.getDefaultEdgeTable(), net.getDefaultNodeTable(),
net.getDefaultNetworkTable());
+
+ return; //assuming that this even is
fired only for a single row
+ }
+ }
+ }
+
+ }
+
+ private void updateRootNetworkTableNames(
+ Collection<RowSetRecord> payloadCollection) {
+
+ for ( RowSetRecord record : payloadCollection ) {
+ // assume payload collection is for same column
+ if ( !record.getColumn().equals(CyNetwork.NAME))
+ break;
+
+ final Object name = record.getValue();
+ setTablesName(name.toString() + " root shared ",
rootNetwork.getSharedEdgeTable(), rootNetwork.getSharedNodeTable(),
rootNetwork.getSharedNetworkTable());
+ setTablesName(name.toString() + " root default ",
rootNetwork.getDefaultEdgeTable(), rootNetwork.getDefaultNodeTable(),
rootNetwork.getDefaultNetworkTable());
+
+ return;
+
+ }
+
+ }
+
+ private void setTablesName (String name, CyTable edgeTable, CyTable
nodeTable, CyTable networkTable){
+ edgeTable.setTitle(name + " edge");
+ networkTable.setTitle(name + " network");
+ nodeTable.setTitle(name + " node");
+
+ }
+
+ //=========================NetworkAddedListener
Implementation========================
+ @Override
+ public void handleEvent(NetworkAddedEvent e) {
+
+ CyNetwork sourceNetwork = e.getNetwork();
+ String name =
sourceNetwork.getRow(sourceNetwork).get(CyNetwork.NAME, String.class);
+
+ if (sourceNetwork.equals( rootNetwork.getBaseNetwork())){
+ setRootNetworkName(name);
+ }
+
+ if(rootNetwork.containsNetwork(sourceNetwork))
+ updateSubNetworkTableNames(sourceNetwork, name);
+ }
+
+ private void setRootNetworkName(String name) {
+ rootNetwork.getRow(rootNetwork).set(CyRootNetwork.NAME, name);
+ }
+
+ private void updateSubNetworkTableNames(CyNetwork net, String name){
+
+ net.getDefaultEdgeTable().setTitle(name + " default edge");
+ net.getDefaultNetworkTable().setTitle(name + " default
network");
+ net.getDefaultNodeTable().setTitle(name + " default node");
+ }
+}
--
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.