Author: scooter
Date: 2008-10-31 13:05:18 -0700 (Fri, 31 Oct 2008)
New Revision: 15155

Modified:
   csplugins/trunk/ucsf/scooter/metaNodePlugin2/resources/plugin.props
   
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/MetaNodePlugin2.java
   
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/model/MetaNode.java
Log:
Significantly enhanced to behave better across multiple views



Modified: csplugins/trunk/ucsf/scooter/metaNodePlugin2/resources/plugin.props
===================================================================
--- csplugins/trunk/ucsf/scooter/metaNodePlugin2/resources/plugin.props 
2008-10-31 18:48:48 UTC (rev 15154)
+++ csplugins/trunk/ucsf/scooter/metaNodePlugin2/resources/plugin.props 
2008-10-31 20:05:18 UTC (rev 15155)
@@ -13,7 +13,7 @@
 pluginDescription=This plugin provides a viewer for groups that implements a 
collapse/expand abstraction
 
 # Plugin version number, this must be two numbers separated by a decimlal.  
Ex. 0.2, 14.03
-pluginVersion=1.2
+pluginVersion=1.3
 
 # Compatible Cytoscape version
 cytoscapeVersion=2.6.1
@@ -31,4 +31,4 @@
 pluginAuthorsIntsitutions=John "Scooter" Morris:UCSF
 
 # Date this plugin/plugin version was released
-releaseDate=July 18, 2008
+releaseDate=October 31, 2008

Modified: 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/MetaNodePlugin2.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/MetaNodePlugin2.java
       2008-10-31 18:48:48 UTC (rev 15154)
+++ 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/MetaNodePlugin2.java
       2008-10-31 20:05:18 UTC (rev 15155)
@@ -173,14 +173,14 @@
         * @param group the CyGroup that was just created
         */
        public void groupCreated(CyGroup group) { 
-               // logger.info("groupCreated("+group+")");
+               // logger.debug("groupCreated("+group+")");
                if (MetaNode.getMetaNode(group) == null) {
                        MetaNode newNode = new MetaNode(group);
                }
                // Update the attributes of the group node
-               // logger.info("registering");
+               // logger.debug("registering");
                registerWithGroupPanel();
-               // logger.info("done");
+               // logger.debug("done");
        }
 
        /**
@@ -193,7 +193,7 @@
         * @param view the CyNetworkView that is being created
         */
        public void groupCreated(CyGroup group, CyNetworkView myview) { 
-               // logger.info("groupCreated("+group+", view)");
+               // logger.debug("groupCreated("+group+", view)");
                if (MetaNode.getMetaNode(group) == null) {
                        MetaNode newNode = new MetaNode(group);
 
@@ -208,9 +208,9 @@
                                network.hideNode(group.getGroupNode());
                        }
                }
-               // logger.info("registering");
+               // logger.debug("registering");
                registerWithGroupPanel();
-               // logger.info("done");
+               // logger.debug("done");
        }
 
        /**
@@ -223,10 +223,9 @@
         */
        public void groupWillBeRemoved(CyGroup group) { 
                MetaNode mn = MetaNode.getMetaNode(group);
-               // Expand the group
-               if (group.getState() == COLLAPSED) {
-                       mn.expand(true, null, true);
-               }
+               // Expand the group in any views that it's collapsed
+               mn.expand(true, null, true);
+
                // Get rid of the MetaNode
                MetaNode.removeMetaNode(mn);
        }
@@ -265,6 +264,7 @@
        public void propertyChange (PropertyChangeEvent e) {
                if (e.getPropertyName() == 
CytoscapeDesktop.NETWORK_VIEW_CREATED) {
                        
((CyNetworkView)e.getNewValue()).addNodeContextMenuListener(this);
+                       MetaNode.newView((CyNetworkView)e.getNewValue());
                }
        }
 
@@ -406,6 +406,7 @@
                private void addMenuItem(JMenu menu, Command command, 
List<CyGroup>groupList,
                                            CyNode contextNode, String label) {
 
+                       CyNetworkView view = Cytoscape.getCurrentNetworkView();
                        if (groupList == null || groupList.size() == 0) {
                                if (contextNode == null) {
                                JMenuItem item = new JMenuItem(label);
@@ -435,13 +436,16 @@
                        } else if (contextNode.isaGroup() && command == 
Command.EXPAND) {
                                // Get the groups this group is a member of
                                CyGroup group = 
CyGroupManager.findGroup(contextNode.getIdentifier());
-                               if (group.getState() == COLLAPSED) {
+                               // Get the MetaNode
+                               MetaNode metaNode = 
MetaNode.getMetaNode(group.getGroupNode());
+                               if (metaNode.isCollapsed(view)) {
                                        addSubMenu(menu, label+" 
"+group.getGroupName(), 
                                                   command, group, contextNode);
                                }
                        } else if (CyGroupManager.isaGroup(contextNode) && 
command == Command.EXPANDNEW) {
                                CyGroup group = 
CyGroupManager.findGroup(contextNode.getIdentifier());
-                               if (group.getState() == COLLAPSED) {
+                               MetaNode metaNode = 
MetaNode.getMetaNode(group.getGroupNode());
+                               if (metaNode.isCollapsed(view)) {
                                        addSubMenu(menu, label+" 
"+group.getGroupName()+" into new network", 
                                                   command, group, contextNode);
                                }
@@ -502,6 +506,7 @@
                        List<CyGroup>nodeGroups = null;
                        boolean foundItem = false;
                        if (groupList == null) return false;
+                       CyNetworkView view = Cytoscape.getCurrentNetworkView();
 
                        if (command == Command.ADD && node != null) {
                                nodeGroups = node.getGroups();
@@ -512,15 +517,17 @@
                                List<CyGroup> parents = groupNode.getGroups();
                                if (group.getViewer() != null && 
group.getViewer().equals(groupViewer.getViewerName())) {
                                        // Only present reasonable choices to 
the user
-                                       if ((command == Command.COLLAPSE && 
group.getState() == COLLAPSED) ||
-                                           (command == Command.EXPAND && 
group.getState() == EXPANDED)) 
+                                       MetaNode metaNode = 
MetaNode.getMetaNode(group.getGroupNode());
+                                       if ((command == Command.COLLAPSE && 
metaNode.isCollapsed(view)) ||
+                                           (command == Command.EXPAND && 
metaNode.isCollapsed(view))) 
                                                continue;
                                        // If command is expand and we're a 
child of a group that isn't
                                        // yet expanded, don't give this as an 
option
                                        if ((command == Command.EXPAND) && 
(parents != null) && (parents.size() > 0)) {
                                                boolean parentCollapsed = false;
                                                for (CyGroup parent: parents) {
-                                                       if 
(groupList.contains(parent) && (parent.getState() == COLLAPSED)) {
+                                                       MetaNode metaParent = 
MetaNode.getMetaNode(parent.getGroupNode());
+                                                       if 
(groupList.contains(parent) && (metaParent.isCollapsed(view))) {
                                                                parentCollapsed 
= true;
                                                                break;
                                                        }
@@ -529,7 +536,7 @@
                                        }
 
                                        if (command == Command.ADD) {
-                                               MetaNode metaNode = null;
+                                               metaNode = null;
                                                // Are we already in this group?
                                                if ((nodeGroups != null) && 
(nodeGroups.contains(group)))
                                                        continue;
@@ -634,7 +641,7 @@
                        }
                        MetaNode newNode = new MetaNode(group);
                        groupCreated(group);
-                       newNode.collapse(recursive, multipleEdges, true, null);
+                       newNode.collapse(recursive, multipleEdges, true, 
Cytoscape.getCurrentNetworkView());
                }
 
                /**

Modified: 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/model/MetaNode.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/model/MetaNode.java
        2008-10-31 18:48:48 UTC (rev 15154)
+++ 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/model/MetaNode.java
        2008-10-31 20:05:18 UTC (rev 15155)
@@ -33,12 +33,13 @@
 package metaNodePlugin2.model;
 
 // System imports
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.ListIterator;
-import java.util.HashMap;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Collection;
+import java.util.Map;
 import java.awt.Dimension;
 
 // giny imports
@@ -78,7 +79,6 @@
 public class MetaNode {
        // Static variables
        private static HashMap<CyNode,MetaNode> metaMap = new HashMap();
-       private static HashMap<CyNode,Boolean> hiddenNodes = new HashMap();
        private static final boolean DEBUG = false;
 
        public static final String X_HINT_ATTR = "__metanodeHintX";
@@ -100,7 +100,7 @@
        private boolean multipleEdges = false;
        private boolean recursive = false;
 
-       protected boolean isCollapsed = false;
+       protected Map<CyNetworkView, Boolean> collapsedMap = null;
 
        private CyAttributes edgeAttributes = null;
        private CyAttributes nodeAttributes = null;
@@ -169,7 +169,7 @@
                CyNetworkView nView = Cytoscape.getCurrentNetworkView();
                Collection<MetaNode> metaNodes = metaMap.values();
                for (MetaNode mNode: metaNodes) {
-                       if (mNode.isCollapsed)
+                       if (mNode.isCollapsed(nView))
                                mNode.expand(true, nView, false);
                }
                // VisualMappingManager vizmapper = 
Cytoscape.getVisualMappingManager();
@@ -184,7 +184,7 @@
                CyNetworkView nView = Cytoscape.getCurrentNetworkView();
                Collection<MetaNode> metaNodes = metaMap.values();
                for (MetaNode mNode: metaNodes) {
-                       if (!mNode.isCollapsed)
+                       if (!mNode.isCollapsed(nView))
                                mNode.collapse(true, true, false, nView);
                }
                // VisualMappingManager vizmapper = 
Cytoscape.getVisualMappingManager();
@@ -192,8 +192,29 @@
                nView.updateView();
        }
 
+       /**
+        * Update the collapse/expand information for all metanodes
+        * in the provided view
+        *
+        * @param view the view to update
+        */
+       static public void newView(CyNetworkView view) {
+               CyNetwork net = view.getNetwork();
+               for (MetaNode mn: metaMap.values()) {
+                       CyNode groupNode = mn.getCyGroup().getGroupNode();
+                       // Is this actually collapsed in this view?
+                       if (net.containsNode(groupNode)) {
+                               // Yes, mark it as so
+                               mn.collapsedMap.put(view, Boolean.TRUE);
+                       } else {
+                               // No, make it so
+                               mn.collapsedMap.put(view, Boolean.FALSE);
+                       }
+               }
+       }
 
 
+
        /*****************************************************************
         *                    Public methods                             *
         ****************************************************************/
@@ -208,6 +229,7 @@
                groupNode = group.getGroupNode();
                metaMap.put(groupNode, this);
                metaEdgeMap = new HashMap();
+               collapsedMap = new HashMap();
                logger = CyLogger.getLogger(MetaNode.class);
 
                if (DEBUG) logger.debug("Creating meta-group 
"+group.getGroupName());
@@ -253,8 +275,7 @@
                            group.addOuterEdge(edge);
                        }
                }
-               // Note that this node is hidden
-               hiddenNodes.put(groupNode, Boolean.TRUE);
+               collapsedMap.put(networkView, Boolean.FALSE);
                updateAttributes();
                if (DEBUG) logger.debug("... done\n\n");
        }
@@ -335,7 +356,7 @@
 
                // Finally, if we're collapsed, hide this node (possibly 
recursively) and
                // update the display
-               if (!isCollapsed)
+               if (!isCollapsed(networkView))
                        return;
 
                // Get the X and Y coordinates of the metaNode
@@ -377,7 +398,7 @@
        public void nodeRemoved(CyNode node) {
                update(null);
                // If we're collapsed, unhide the node
-               if (isCollapsed) {
+               if (isCollapsed(networkView)) {
                        restoreNode(node, null);
                }
 
@@ -396,7 +417,7 @@
                                if (edge.getTarget() == node || 
edge.getSource() == node) {
                                        // Remove it from this metaEdge
                                        edgeIter.remove();
-                                       if (isCollapsed) {
+                                       if (isCollapsed(networkView)) {
                                                restoreEdge(edge);
                                        }
                                }
@@ -422,7 +443,7 @@
                                // Rats, looks like we need to create metaEdges 
for this node
                                CyEdge metaEdge = createMetaEdge(edge, null, 
false);
                                // If we're expanded, hide it
-                               if (!isCollapsed) {
+                               if (!isCollapsed(networkView)) {
                                        hideEdge(metaEdge);
                                }
                        }
@@ -449,7 +470,7 @@
                if (newEdgeMap == null)
                        createMetaEdges();
 
-               isCollapsed = true;
+               collapsedMap.put(view, Boolean.TRUE);
                expand(recursive, view, true);
                collapse(recursive, multipleEdges, false, view);
        }
@@ -465,15 +486,16 @@
         */
        public void collapse(boolean recursive, boolean multipleEdges, boolean 
updateNetwork,
                             CyNetworkView view) {
-               if (isCollapsed) 
+               // Initialize
+               update(view);
+
+               if (isCollapsed(networkView)) 
                        return;
 
                if (DEBUG) logger.debug("collapsing "+groupNode);
                // Profile prf = new Profile();
                // prf.start();
 
-               // Initialize
-               update(view);
                // prf.done("collapse: Update=");
 
                this.multipleEdges = multipleEdges;
@@ -487,7 +509,7 @@
                createMetaEdges();
                // prf.done("collapse: createMetaEdges=");
 
-               isCollapsed = true;
+               collapsedMap.put(view, Boolean.TRUE);
 
                // Set our state
                metaGroup.setState(MetaNodePlugin2.COLLAPSED);
@@ -506,14 +528,23 @@
         * @param update update the display?
         */
        public void expand(boolean recursive, CyNetworkView view, boolean 
update) {
-               if (!isCollapsed) 
+               if (view == null) {
+                       // Special case.  We're probably going away, so we need 
to expand ourselves
+                       // in *every* view
+                       for (CyNetworkView nView: collapsedMap.keySet()) {
+                               expand(recursive, nView, update);
+                       }
                        return;
+               }
 
-               if (DEBUG) logger.debug("Expanding "+groupNode);
-
                // Initialize
                update(view);
 
+               if (!isCollapsed(networkView)) 
+                       return;
+
+               if (DEBUG) logger.debug("Expanding "+groupNode);
+
                // First, find all of our edges.  This will include any 
metaEdges as well
                // as any edges that were created by external applications
                int [] edgeArray = 
network.getAdjacentEdgeIndicesArray(groupNode.getRootGraphIndex(),true,true,true);
@@ -546,7 +577,7 @@
                        updateDisplay();
                }
 
-               isCollapsed = false;
+               collapsedMap.put(view, Boolean.FALSE);
                metaGroup.setState(MetaNodePlugin2.EXPANDED);
 
                // Now, for any of our nodes that are metaNodes and were 
expanded when we
@@ -603,7 +634,7 @@
                                return null;
                        }
 
-                       if (!multipleEdges && 
metaEdgeMap.containsKey(parent.groupNode) && parent.isCollapsed) {
+                       if (!multipleEdges && 
metaEdgeMap.containsKey(parent.groupNode) && parent.isCollapsed(networkView)) {
                                // Already seen this?
                                if (DEBUG) logger.debug("... returning cached 
edge "+metaEdgeMap.get(parent.groupNode).getIdentifier());
                                return metaEdgeMap.get(parent.groupNode);
@@ -622,7 +653,7 @@
                        // one edge per partner
                        
                        // First make sure our partner is not an expanded 
metanode
-                       if (MetaNode.getMetaNode(partner) != null && 
!MetaNode.getMetaNode(partner).isCollapsed) {
+                       if (MetaNode.getMetaNode(partner) != null && 
!MetaNode.getMetaNode(partner).isCollapsed(networkView)) {
                                if (DEBUG) logger.debug("... returning null ");
                                // skip it
                                return null;
@@ -678,6 +709,19 @@
                new_view.fitContent();
        }
 
+       /**
+        * Determine if this metanode is collapsed in this view
+        *
+        * @param view the network view to check
+        * @return True if it is collapsed, False otherwise
+        */
+       public boolean isCollapsed(CyNetworkView view) {
+               if (collapsedMap.containsKey(view)) {
+                       return collapsedMap.get(view).booleanValue();
+               } else
+                       return false;
+       }
+
        /*****************************************************************
         *                   Private methods                             *
         ****************************************************************/
@@ -736,7 +780,7 @@
                        CyNode partner = getPartner(edge);
                        if (DEBUG) logger.debug("... partner is 
"+partner.getIdentifier());
                        // Is our partner an expanded metaNode?
-                       if (MetaNode.getMetaNode(partner) != null && 
!MetaNode.getMetaNode(partner).isCollapsed) {
+                       if (MetaNode.getMetaNode(partner) != null && 
!MetaNode.getMetaNode(partner).isCollapsed(networkView)) {
                                // Yes, just continue
                                continue;
                        } else if (isNodeHidden(partner)) {
@@ -820,7 +864,7 @@
                        Dimension d = new Dimension();
                        d.setSize(xValue, yValue);
                        // Is this already visible?
-                       if (hiddenNodes.containsKey(node) && 
hiddenNodes.get(node) == Boolean.FALSE)
+                       if (network.containsNode(node))
                                continue;
                        restoreNode(node, d);
                }
@@ -862,7 +906,7 @@
                        if (metaMap.containsKey(node)) {
                                // Yes, recurse down
                                MetaNode child = (MetaNode)metaMap.get(node);
-                               if (!child.isCollapsed) {
+                               if (!child.isCollapsed(networkView)) {
                                        if (childMetaNodes == null) {
                                                childMetaNodes = new 
ArrayList<MetaNode>();
                                        }
@@ -916,7 +960,6 @@
        private void hideNode(CyNode node) {
                if (DEBUG) logger.debug("Hiding node "+node.getIdentifier());
                network.hideNode(node);
-               hiddenNodes.put(node, Boolean.TRUE);
        }
 
        /**
@@ -930,7 +973,6 @@
                if (DEBUG) logger.debug("Restoring node "+node.getIdentifier());
 
                network.restoreNode(node);
-               hiddenNodes.put(node, Boolean.FALSE);
 
                if (center != null) {
                        // Get the nodeView
@@ -954,12 +996,7 @@
         * @return true if the node is hidden, false otherwise
         */
        private boolean isNodeHidden(CyNode node) {
-               if (hiddenNodes.containsKey(node) &&
-                         hiddenNodes.get(node) == Boolean.TRUE) { 
-                       return true;
-               }
-
-               return false;
+               return (!network.containsNode(node));
        }
 
        /**
@@ -1024,7 +1061,7 @@
                for (CyGroup group: groupList) {
                        if (metaMap.containsKey(group.getGroupNode())) {
                                MetaNode meta = 
metaMap.get(group.getGroupNode());
-                               if (meta != this && meta.isCollapsed) return 
meta;
+                               if (meta != this && 
meta.isCollapsed(networkView)) return meta;
                        }
                }
                return null;


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