Author: mes
Date: 2011-11-22 16:16:28 -0800 (Tue, 22 Nov 2011)
New Revision: 27568

Added:
   
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/NameSetListener.java
Modified:
   
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ArrayGraph.java
   
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ArraySubGraph.java
Log:
added support for shared names

Modified: 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ArrayGraph.java
===================================================================
--- 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ArrayGraph.java
 2011-11-23 00:15:41 UTC (rev 27567)
+++ 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ArrayGraph.java
 2011-11-23 00:16:28 UTC (rev 27568)
@@ -49,6 +49,7 @@
 import org.cytoscape.model.Identifiable;
 import org.cytoscape.model.SUIDFactory;
 import org.cytoscape.model.events.ColumnCreatedListener;
+import org.cytoscape.model.events.RowsSetListener;
 import org.cytoscape.service.util.CyServiceRegistrar;
 import org.cytoscape.model.subnetwork.CyRootNetwork;
 import org.cytoscape.model.subnetwork.CySubNetwork;
@@ -132,15 +133,6 @@
                base = addSubNetwork(); 
        }
 
-       private void registerAllTables() {
-        for (final CyTable table : netTables.values())
-            tableMgr.addTable(table);
-        for (final CyTable table : nodeTables.values())
-            tableMgr.addTable(table);
-        for (final CyTable table : edgeTables.values())
-            tableMgr.addTable(table);
-       }
-
        private Map<String,CyTable> createNetworkTables(long suidx) {
                Map<String,CyTable> netAttrMgr = new HashMap<String, CyTable>();
         netAttrMgr.put(CyNetwork.DEFAULT_ATTRS, tableFactory.createTable(suidx 
+ " default network", Identifiable.SUID, Long.class, publicTables, false));
@@ -148,10 +140,10 @@
 
         
netAttrMgr.get(CyNetwork.DEFAULT_ATTRS).createColumn(CyTableEntry.NAME, 
String.class, true);
 
-               if ( suidx == suid ) 
+               if ( suidx == suid ) { 
                netAttrMgr.put(CyRootNetwork.SHARED_ATTRS, 
tableFactory.createTable(suidx + " shared network", Identifiable.SUID, 
Long.class, publicTables, false));
-                       
-               else    
+               
netAttrMgr.get(CyRootNetwork.SHARED_ATTRS).createColumn(CyRootNetwork.SHARED_NAME,
 String.class, true);
+               } else  
                        linkDefaultTables( 
netTables.get(CyRootNetwork.SHARED_ATTRS), 
                                           
netAttrMgr.get(CyNetwork.DEFAULT_ATTRS) );
 
@@ -166,9 +158,10 @@
         
nodeAttrMgr.get(CyNetwork.DEFAULT_ATTRS).createColumn(CyTableEntry.NAME, 
String.class, true);
         
nodeAttrMgr.get(CyNetwork.DEFAULT_ATTRS).createColumn(CyNetwork.SELECTED, 
Boolean.class, true, Boolean.FALSE);
 
-               if ( suidx == suid ) 
+               if ( suidx == suid ) {
                nodeAttrMgr.put(CyRootNetwork.SHARED_ATTRS, 
tableFactory.createTable(suidx + " shared node", Identifiable.SUID, Long.class, 
publicTables, false));
-               else
+               
nodeAttrMgr.get(CyRootNetwork.SHARED_ATTRS).createColumn(CyRootNetwork.SHARED_NAME,
 String.class, true);
+               } else
                        linkDefaultTables( 
nodeTables.get(CyRootNetwork.SHARED_ATTRS), 
                                           
nodeAttrMgr.get(CyNetwork.DEFAULT_ATTRS) );
                return nodeAttrMgr;
@@ -184,9 +177,10 @@
         
edgeAttrMgr.get(CyNetwork.DEFAULT_ATTRS).createColumn(CyNetwork.SELECTED, 
Boolean.class, true, Boolean.FALSE);
         
edgeAttrMgr.get(CyNetwork.DEFAULT_ATTRS).createColumn(CyEdge.INTERACTION, 
String.class, true);
 
-               if ( suidx == suid ) 
+               if ( suidx == suid ) { 
                edgeAttrMgr.put(CyRootNetwork.SHARED_ATTRS, 
tableFactory.createTable(suidx + " shared edge", Identifiable.SUID, Long.class, 
publicTables, false));
-               else    
+               
edgeAttrMgr.get(CyRootNetwork.SHARED_ATTRS).createColumn(CyRootNetwork.SHARED_NAME,
 String.class, true);
+               } else  
                        linkDefaultTables( 
edgeTables.get(CyRootNetwork.SHARED_ATTRS), 
                                           
edgeAttrMgr.get(CyNetwork.DEFAULT_ATTRS) );
 
@@ -201,6 +195,10 @@
                // virtual columns to any subsequent source columns added.
                serviceRegistrar.registerService(new 
VirtualColumnAdder(srcTable,tgtTable), 
                                                 ColumnCreatedListener.class, 
new Properties());
+
+               // Another listener tracks changes to the NAME column in local 
tables
+               serviceRegistrar.registerService(new 
NameSetListener(srcTable,tgtTable),
+                                                RowsSetListener.class, new 
Properties());
        }
 
        /**

Modified: 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ArraySubGraph.java
===================================================================
--- 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ArraySubGraph.java
      2011-11-23 00:15:41 UTC (rev 27567)
+++ 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/ArraySubGraph.java
      2011-11-23 00:16:28 UTC (rev 27568)
@@ -36,6 +36,7 @@
 //import org.cytoscape.model.builder.CyEdgeBuilder;
 
 import org.cytoscape.di.util.DIUtil;
+import org.cytoscape.model.Identifiable;
 import org.cytoscape.model.CyColumn;
 import org.cytoscape.model.CyNetwork;
 import org.cytoscape.model.CyTable;
@@ -539,6 +540,17 @@
             tableMgr.addTable(table);
         for (final CyTable table : edgeTables.values())
             tableMgr.addTable(table);
+
+               updateSharedNames( getDefaultNodeTable(), 
parent.getSharedNodeTable() );
+               updateSharedNames( getDefaultEdgeTable(), 
parent.getSharedEdgeTable() );
+               updateSharedNames( getDefaultNetworkTable(), 
parent.getSharedNetworkTable() );
+       }       
+
+       private void updateSharedNames(CyTable src, CyTable tgt) {
+               for ( CyRow sr : src.getAllRows() ) {
+                       CyRow tr = tgt.getRow( 
sr.get(Identifiable.SUID,Long.class) );
+                       tr.set( CyRootNetwork.SHARED_NAME, 
sr.get(CyNetwork.NAME,String.class) );
+               }
        }
 
        /**

Added: 
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
                            (rev 0)
+++ 
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/NameSetListener.java
    2011-11-23 00:16:28 UTC (rev 27568)
@@ -0,0 +1,76 @@
+
+/*
+ Copyright (c) 2008, 2010-2011, The Cytoscape Consortium (www.cytoscape.org)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications.  In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage.  See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+package org.cytoscape.model.internal;
+
+
+import org.cytoscape.model.subnetwork.CyRootNetwork;
+import org.cytoscape.model.CyTable;
+import org.cytoscape.model.CyTableEntry;
+import org.cytoscape.model.CyRow;
+import org.cytoscape.model.Identifiable;
+import org.cytoscape.model.events.RowsSetListener;
+import org.cytoscape.model.events.RowsSetEvent;
+import org.cytoscape.model.events.RowSetRecord;
+
+/**
+ * Any time that the CyTableEntry.NAME column is set
+ * in a local table, update the shared table with the
+ * new name.
+ */
+class NameSetListener implements RowsSetListener {
+
+       private final CyTable shared;
+       private final CyTable local;
+
+       NameSetListener(CyTable shared, CyTable local) {
+               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!");
+               this.shared = shared;
+               this.local = local;
+       }
+
+       public void handleEvent(RowsSetEvent e) {
+               if ( e.getSource() != local )
+                       return;
+               for ( RowSetRecord record : e.getPayloadCollection() ) {
+                       // assume payload collection is for same column
+                       if ( !record.getColumn().equals(CyTableEntry.NAME) )
+                               return;
+
+                       CyRow r = shared.getRow( record.getRow().get( 
Identifiable.SUID, Long.class ) );
+                       if ( r != null ) 
+                               r.set(CyRootNetwork.SHARED_NAME, 
record.getValue());
+               }
+       }
+}
+

-- 
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.

Reply via email to