Author: mes
Date: 2011-03-08 15:27:00 -0800 (Tue, 08 Mar 2011)
New Revision: 24342

Modified:
   
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/ArrayGraph.java
   
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/ArraySubGraph.java
   
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyNodeImpl.java
Log:
added better support for groups/metanodes based on mini retreat discussion

Modified: 
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/ArrayGraph.java
===================================================================
--- 
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/ArrayGraph.java
      2011-03-08 23:26:51 UTC (rev 24341)
+++ 
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/ArrayGraph.java
      2011-03-08 23:27:00 UTC (rev 24342)
@@ -128,10 +128,6 @@
                                                                      
String.class, true);
                
nodeAttrMgr.get(CyNetwork.DEFAULT_ATTRS).createColumn(CyNetwork.SELECTED,
                                                                      
Boolean.class, true);
-               
nodeAttrMgr.get(CyNetwork.DEFAULT_ATTRS).createColumn(CyNode.NESTED_NETWORK_ATTR,
-                                                                     
String.class, true);
-               
nodeAttrMgr.get(CyNetwork.DEFAULT_ATTRS).createColumn(CyNode.HAS_NESTED_NETWORK_ATTR,
-                                                                     
Boolean.class, true);
 
                edgeAttrMgr = new HashMap<String, CyTable>();
                edgeAttrMgr.put(CyNetwork.DEFAULT_ATTRS,
@@ -835,6 +831,22 @@
        /**
         * {@inheritDoc}
         */
+       public CySubNetwork addSubNetwork(final Iterable<CyNode> nodes, final 
Iterable<CyEdge> edges) {
+               // Only addSubNetwork() modifies the internal state of 
ArrayGraph (this object), 
+               // so because it's synchronized, we don't need to synchronize 
this method.
+               final CySubNetwork sub = addSubNetwork();
+               if ( nodes != null ) 
+                       for ( CyNode n : nodes )
+                               sub.addNode(n);
+               if ( edges != null ) 
+                       for ( CyEdge e : edges )
+                               sub.addEdge(e);
+               return sub;
+       }
+
+       /**
+        * {@inheritDoc}
+        */
        public synchronized CySubNetwork addSubNetwork() {
                final int newId = ++numSubNetworks;
                final ArraySubGraph sub = new 
ArraySubGraph(this,newId,eventHelper);
@@ -902,4 +914,11 @@
        public CyTable getDefaultEdgeTable() {
                return edgeAttrMgr.get(CyNetwork.DEFAULT_ATTRS);
        }
+
+       /**
+        * {@inheritDoc}
+        */
+       public synchronized boolean containsNetwork(final CyNetwork net) {
+               return subNetworks.contains(net);
+       }
 }

Modified: 
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/ArraySubGraph.java
===================================================================
--- 
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/ArraySubGraph.java
   2011-03-08 23:26:51 UTC (rev 24341)
+++ 
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/ArraySubGraph.java
   2011-03-08 23:27:00 UTC (rev 24342)
@@ -307,12 +307,13 @@
                        if (!parent.containsEdge(edge))
                                throw new IllegalArgumentException("edge is not 
contained in parent network!");
 
-                       if (!containsNode(edge.getSource()))
-                               throw new IllegalArgumentException("source node 
of edge is not contained in network!");
+                       // This will: 
+                       // -- add the node if it doesn't already exist
+                       // -- do nothing if the node does exist 
+                       // -- throw an exception if the node isn't part of the 
root network
+                       addNode(edge.getSource());
+                       addNode(edge.getTarget());
 
-                       if (!containsNode(edge.getTarget()))
-                               throw new IllegalArgumentException("target node 
of edge is not contained in network!");
-
                        // add edge 
                        internalEdgeCount++;
                        edgeSet.add(edge);

Modified: 
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyNodeImpl.java
===================================================================
--- 
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyNodeImpl.java
      2011-03-08 23:26:51 UTC (rev 24341)
+++ 
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyNodeImpl.java
      2011-03-08 23:27:00 UTC (rev 24342)
@@ -51,8 +51,6 @@
                index = ind;
                nestedNet = null;
                this.eventHelper = eventHelper;
-
-               getCyRow().set(HAS_NESTED_NETWORK_ATTR, Boolean.valueOf(false));
        }
 
        /**
@@ -74,27 +72,24 @@
                return "Node suid: " + getSUID() + " index: " + index;
        }
 
-       public synchronized CyNetwork getNestedNetwork() {
+       public synchronized CyNetwork getNetwork() {
                return nestedNet;
        }
 
-       public synchronized void setNestedNetwork(final CyNetwork n) {
-               if (n == nestedNet)
-                       return;
+       public void setNetwork(final CyNetwork n) {
+               final CyNetwork orig; 
+       
+               synchronized (this) {
+                       orig = nestedNet;
+                       if (n == nestedNet)
+                               return;
+                       else
+                               nestedNet = n;
+               }
 
+               if (orig != null)
+                       eventHelper.fireSynchronousEvent(new 
UnsetNestedNetworkEvent(this, orig));
                if (nestedNet != null)
-                       eventHelper.fireSynchronousEvent(new 
UnsetNestedNetworkEvent(this, nestedNet));
-               if (n != null)
-                       eventHelper.fireSynchronousEvent(new 
SetNestedNetworkEvent(this, n));
-               nestedNet = n;
-
-               final CyRow row = getCyRow();
-               if (n == null) {
-                       row.set(NESTED_NETWORK_ATTR, null);
-                       row.set(HAS_NESTED_NETWORK_ATTR, 
Boolean.valueOf(false));
-               } else {
-                       row.set(NESTED_NETWORK_ATTR, 
Long.valueOf(n.getSUID()).toString());
-                       row.set(HAS_NESTED_NETWORK_ATTR, Boolean.valueOf(true));
-               }
+                       eventHelper.fireSynchronousEvent(new 
SetNestedNetworkEvent(this, nestedNet));
        }
 }

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