Author: kono
Date: 2009-11-20 16:24:36 -0800 (Fri, 20 Nov 2009)
New Revision: 18533

Modified:
   cytoscape/trunk/src/cytoscape/CyNode.java
   cytoscape/trunk/src/cytoscape/Cytoscape.java
Log:
New events for Nested Network API had been added.  Also, 
CyNode.setNestedNetwork() accepts null as an argument to remove nested network.

Modified: cytoscape/trunk/src/cytoscape/CyNode.java
===================================================================
--- cytoscape/trunk/src/cytoscape/CyNode.java   2009-11-20 23:28:55 UTC (rev 
18532)
+++ cytoscape/trunk/src/cytoscape/CyNode.java   2009-11-21 00:24:36 UTC (rev 
18533)
@@ -242,21 +242,47 @@
         * Assign a graph perspective reference to this node.
         */
        public void setNestedNetwork(final GraphPerspective graphPerspective) {
+               // Sanity check.
+               if (graphPerspective == this.graphPerspective)
+                       return;
+               
+               // create a Node Attribute "nested.network.id" for this Node
+               final String networkID = ((CyNetwork)(graphPerspective == null 
? this.graphPerspective
+                                                                               
        : graphPerspective)).getIdentifier();
                this.graphPerspective = graphPerspective;
                
-               // create a Node Attribute "nested.network.id" for this Node
-               String networkID = ((CyNetwork) 
this.graphPerspective).getIdentifier();
                
Cytoscape.getNodeAttributes().setAttribute(this.getIdentifier(), 
NESTED_NETWORK_ID_ATTR, networkID);
                
-               // create a Network Attribute "parent.node.name.list" for the 
Network           
-               final List<String> nodeNameList = new ArrayList<String>();
-               final int[] indices = 
this.graphPerspective.getNodeIndicesArray();
+               // create or update Network Attribute "parent.node.name.list" 
for the Network   
+               final String[] attributeNames = 
Cytoscape.getNetworkAttributes().getAttributeNames();
+               boolean attrFound = false;
+               for (String name: attributeNames) {
+                       if (name.equals(PARENT_NODES_ATTR)) {
+                               attrFound = true;
+                               break;
+                       }
+               }
+               List<String> parentNodeList;
+               if (!attrFound) {
+                       parentNodeList = new ArrayList<String>();
+                       parentNodeList.add(this.getIdentifier());
+               } else {
+                       parentNodeList = (List<String>) 
Cytoscape.getNetworkAttributes().getListAttribute(networkID, PARENT_NODES_ATTR);
+                       if (this.graphPerspective != null) {
+                               parentNodeList.add(this.getIdentifier());
+                       } else {
+                               parentNodeList.remove(this.getIdentifier());
+                       }
+               }
+               Cytoscape.getNetworkAttributes().setListAttribute(networkID, 
PARENT_NODES_ATTR, parentNodeList);
                
-               for (int i=0; i< indices.length; i++){
-                       
nodeNameList.add(this.graphPerspective.getNode(indices[i]).getIdentifier());
+               // Let listeners know nested network was assigned to this node.
+               if (this.graphPerspective == null) {
+                       
Cytoscape.getPropertyChangeSupport().firePropertyChange(Cytoscape.NESTED_NETWORK_DESTROYED,
 this, null);
+               } else {
+                       
Cytoscape.getPropertyChangeSupport().firePropertyChange(Cytoscape.NESTED_NETWORK_CREATED,
 this, graphPerspective);
+       
                }
-               
-               Cytoscape.getNetworkAttributes().setListAttribute(networkID, 
PARENT_NODES_ATTR, nodeNameList);
        }
        
                

Modified: cytoscape/trunk/src/cytoscape/Cytoscape.java
===================================================================
--- cytoscape/trunk/src/cytoscape/Cytoscape.java        2009-11-20 23:28:55 UTC 
(rev 18532)
+++ cytoscape/trunk/src/cytoscape/Cytoscape.java        2009-11-21 00:24:36 UTC 
(rev 18533)
@@ -221,6 +221,21 @@
         * internet have been changed.
         */
        public static final String PROXY_MODIFIED = "PROXY_MODIFIED";
+       
+       /**
+        * Fired every time a nested network is assigned to a node.
+        * This event contains the following values:
+        * <ul>
+        *      <li>oldValue - CyNode whose nested network was set.
+        *      <li>newValue - The network assigned to the node above.
+        * </ul>
+        */
+       public static final String NESTED_NETWORK_CREATED = 
"NESTED_NETWORK_CREATED";
+       
+       /**
+        * Fired every time a nested network is removed from a node.
+        */
+       public static final String NESTED_NETWORK_DESTROYED = 
"NESTED_NETWORK_DESTROYED";
 
        /**
         * When creating a network, use one of the standard suffixes to have it

--

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


Reply via email to