Author: scooter
Date: 2012-07-19 19:03:42 -0700 (Thu, 19 Jul 2012)
New Revision: 29934

Modified:
   core3/impl/trunk/group-session-restore-shim/pom.xml
   
core3/impl/trunk/group-session-restore-shim/src/main/java/org/cytoscape/group/session/restore/shim/internal/SessionEventsListener.java
Log:
Update group position information.  Still need to transfer settings...



Modified: core3/impl/trunk/group-session-restore-shim/pom.xml
===================================================================
--- core3/impl/trunk/group-session-restore-shim/pom.xml 2012-07-19 23:32:17 UTC 
(rev 29933)
+++ core3/impl/trunk/group-session-restore-shim/pom.xml 2012-07-20 02:03:42 UTC 
(rev 29934)
@@ -73,6 +73,14 @@
                        <artifactId>session-api</artifactId>
                </dependency>
                <dependency>
+                       <groupId>org.cytoscape</groupId>
+                       <artifactId>viewmodel-api</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.cytoscape</groupId>
+                       <artifactId>presentation-api</artifactId>
+               </dependency>
+               <dependency>
                        <groupId>junit</groupId>
                        <artifactId>junit</artifactId>
                        <scope>test</scope>

Modified: 
core3/impl/trunk/group-session-restore-shim/src/main/java/org/cytoscape/group/session/restore/shim/internal/SessionEventsListener.java
===================================================================
--- 
core3/impl/trunk/group-session-restore-shim/src/main/java/org/cytoscape/group/session/restore/shim/internal/SessionEventsListener.java
      2012-07-19 23:32:17 UTC (rev 29933)
+++ 
core3/impl/trunk/group-session-restore-shim/src/main/java/org/cytoscape/group/session/restore/shim/internal/SessionEventsListener.java
      2012-07-20 02:03:42 UTC (rev 29934)
@@ -7,6 +7,7 @@
 import org.cytoscape.group.CyGroup;
 import org.cytoscape.group.CyGroupFactory;
 import org.cytoscape.group.CyGroupManager;
+import org.cytoscape.model.CyColumn;
 import org.cytoscape.model.CyEdge;
 import org.cytoscape.model.CyNetwork;
 import org.cytoscape.model.CyNetworkManager;
@@ -21,6 +22,9 @@
 import org.cytoscape.session.events.SessionAboutToBeSavedListener;
 import org.cytoscape.session.events.SessionLoadedEvent;
 import org.cytoscape.session.events.SessionLoadedListener;
+import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.view.model.View;
+import org.cytoscape.view.presentation.property.BasicVisualLexicon;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -31,6 +35,7 @@
        private final CyNetworkManager netMgr;
        private final CyRootNetworkManager rootNetMgr;
        private final String EXTERNAL_EDGE_ATTRIBUTE="__externalEdges";
+       private final String GROUP_COLLAPSED_ATTRIBUTE="__groupCollapsed";
        
        private static final Logger logger = 
LoggerFactory.getLogger(SessionEventsListener.class);
        
@@ -76,14 +81,35 @@
                                return;
 
                        boolean collapsed = false;
+                       boolean cy2group = false;
 
                        if (hnRow.isSet("__groupState")) {
                                Integer grState = hnRow.get("__groupState", 
Integer.class); // 2.x metadata
+                               cy2group = true;
                                if (grState.intValue() == 2) collapsed = true;
                        } else if (dnRow.isSet("__groupState")) {
                                Integer grState = dnRow.get("__groupState", 
Integer.class); // 2.x metadata
+                               cy2group = true;
                                if (grState.intValue() == 2) collapsed = true;
                        } 
+
+                       // Check to make sure the column exists
+                       if 
(rnRow.getTable().getColumn(GROUP_COLLAPSED_ATTRIBUTE) == null) {
+                               
rnRow.getTable().createListColumn(GROUP_COLLAPSED_ATTRIBUTE, String.class, 
true);
+                       }
+
+                       if (!rnRow.isSet(GROUP_COLLAPSED_ATTRIBUTE)) {
+                               // This is a 2.x group.  We need to recreate 
the 3.x structure
+                               List<String> collapsedList = 
rnRow.getList(GROUP_COLLAPSED_ATTRIBUTE, String.class);
+                               if (collapsedList == null) collapsedList = new 
ArrayList<String>();
+
+                               String netName = 
net.getDefaultNetworkTable().getRow(net.getSUID()).get(CyNetwork.NAME, 
String.class);
+                               if (netName == null)
+                                       netName = "(null)";
+
+                               collapsedList.add(netName+":"+collapsed);
+                               rnRow.set(GROUP_COLLAPSED_ATTRIBUTE, 
collapsedList);
+                       }
                        
                        // Create the group
                        final CyGroup group = groupFactory.createGroup(net, n, 
true);
@@ -108,22 +134,35 @@
                                group.addEdges(externalEdges);
                        }
                        
+                       /*
+                       // Disable nested network
+                       final boolean nestedNetVisible = 
dnRow.get("nested_network_is_visible", Boolean.class, Boolean.FALSE);
+                       if 
(dnRow.getTable().getColumn("nested_network_is_visible") == null) {
+                               
dnRow.getTable().createColumn("nested_network_is_visible", Boolean.class, 
false);
+                       }
+                       dnRow.set("nested_network_is_visible", Boolean.FALSE);
+                       */
+                       
                        // TODO: restore group's settings
-                       // final boolean nestedNetVisible = 
dnRow.get("nested_network_is_visible", Boolean.class, Boolean.FALSE);
-//                     groupSettings.setUseNestedNetworks(nestedNetVisible, 
group);
-                       
-                       // So the group node is removed from the network when 
it is expanded:
-                       // TODO: Shouldn't the group factory automatically 
remove the provided group node, since the initial state
-                       // should be the same as expanded?
-                       /*
-                       group.collapse(net);
+                       // Some special handling for cy2 groups.  We need to 
restore the X,Y coordinates of the nodes
+                       // if we're collapsed.
+                       if (cy2group) {
+                               // Copy all of the tables for the group
+                               copyTables(netPointer, net, n);
 
-                       if (!collapsed) {
-                               // Expanded...
-                               group.expand(net);
+                               // If the group is collapsed, we need to 
provide the location information so
+                               // we can expand it
+                               if (collapsed) {
+                                       
updateGroupNodeLocation(getNetworkView(sess, net), n);
+                               }
                        }
-                       */
                }
+
+               // TODO: If this is a 2.x group, clean up
+               if (net.getDefaultNodeTable().getColumn("__groupState") != null)
+                       net.getDefaultNodeTable().deleteColumn("__groupState");
+               if (net.getDefaultNodeTable().getColumn("__groupIsLocal") != 
null)
+                       
net.getDefaultNodeTable().deleteColumn("__groupIsLocal");
        }
 
        public void handleEvent(SessionAboutToBeSavedEvent e) {
@@ -162,4 +201,80 @@
                        }
                }
        }
+
+       private void copyTables(CyNetwork netPointer, CyNetwork net, CyNode 
groupNode) {
+               // Copy the tables from the subnetwork
+               CyTable subTable = netPointer.getDefaultNodeTable();
+               CyTable nodeTable = net.getDefaultNodeTable();
+
+               CyTable hiddenSubTable = netPointer.getTable(CyNode.class, 
CyNetwork.HIDDEN_ATTRS);
+               CyTable hiddenTable = net.getTable(CyNode.class, 
CyNetwork.HIDDEN_ATTRS);
+
+               // The group code stores location information in the root table
+               CyRootNetwork rootNetwork = 
((CySubNetwork)net).getRootNetwork();
+               CyTable hiddenRootTable = rootNetwork.getTable(CyNode.class, 
CyNetwork.HIDDEN_ATTRS);
+
+               for (CyNode child: netPointer.getNodeList()) {
+                       CyRow row = netPointer.getRow(child);
+                       CyRow nodeRow = nodeTable.getRow(child.getSUID());
+                       for (CyColumn col: subTable.getColumns()) {
+                               String name = col.getName();
+                               if (nodeTable.getColumn(name) != null && 
+                                   
!nodeTable.getColumn(name).getVirtualColumnInfo().isVirtual()) {
+                                       nodeRow.set(col.getName(), 
row.get(name, col.getType()));
+                               }
+                       }
+
+                       CyRow hiddenRow = hiddenTable.getRow(child.getSUID());
+                       CyRow hiddenSubRow = 
hiddenSubTable.getRow(child.getSUID());
+                       CyRow hiddenRootRow = 
hiddenRootTable.getRow(child.getSUID());
+                       for (CyColumn col: hiddenSubTable.getColumns()) {
+                               String name = col.getName();
+                               // Look for child node location information
+                               if (name.equals("__metanodeHintX")) {
+                                       Double offset = hiddenSubRow.get(name, 
Double.class);
+                                       createColumn(hiddenRootRow, 
"__xOffset", Double.class);
+                                       hiddenRootRow.set("__xOffset", offset);
+                               } else if (name.equals("__metanodeHintY")) {
+                                       Double offset = hiddenSubRow.get(name, 
Double.class);
+                                       createColumn(hiddenRootRow, 
"__yOffset", Double.class);
+                                       hiddenRootRow.set("__yOffset", offset);
+                               } else if (hiddenTable.getColumn(name) != null 
&& 
+                                          
!hiddenTable.getColumn(name).getVirtualColumnInfo().isVirtual()) {
+                                       hiddenSubRow.set(col.getName(), 
hiddenRow.get(name, col.getType()));
+                               }
+                       }
+               }
+       }
+
+       private CyNetworkView getNetworkView(CySession sess, CyNetwork net) {
+               for (CyNetworkView view: sess.getNetworkViews()) {
+                       if (view.getModel().equals(net)) {
+                               return view;
+                       }
+               }
+               return null;
+       }
+
+       private void updateGroupNodeLocation(CyNetworkView view, CyNode 
groupNode) {
+               if (view == null) return;
+
+               CyRootNetwork rootNetwork = 
((CySubNetwork)view.getModel()).getRootNetwork();
+               View<CyNode> nView = view.getNodeView(groupNode);
+               double x = 
nView.getVisualProperty(BasicVisualLexicon.NODE_X_LOCATION);
+               double y = 
nView.getVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION);
+               // Save it
+               CyRow hRow = rootNetwork.getRow(groupNode, 
CyNetwork.HIDDEN_ATTRS);
+               createColumn(hRow, "__xLocation", Double.class);
+               createColumn(hRow, "__yLocation", Double.class);
+               hRow.set("__xLocation", new Double(x));
+               hRow.set("__yLocation", new Double(y));
+       }
+
+       private void createColumn(CyRow row, String column, Class type) {
+               CyTable table = row.getTable();
+               if (table.getColumn(column) == null) {
+                       table.createColumn(column, type, false);
+               }
+       }
 }

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