Author: scooter
Date: 2010-08-11 15:31:47 -0700 (Wed, 11 Aug 2010)
New Revision: 21338
Modified:
csplugins/trunk/ucsf/scooter/namedSelection/src/namedSelection/ui/GroupTree.java
csplugins/trunk/ucsf/scooter/namedSelection/src/namedSelection/ui/GroupTreeModel.java
csplugins/trunk/ucsf/scooter/namedSelection/src/namedSelection/ui/GroupTreeUtils.java
Log:
Working well for level-3 case
Modified:
csplugins/trunk/ucsf/scooter/namedSelection/src/namedSelection/ui/GroupTree.java
===================================================================
---
csplugins/trunk/ucsf/scooter/namedSelection/src/namedSelection/ui/GroupTree.java
2010-08-11 22:22:51 UTC (rev 21337)
+++
csplugins/trunk/ucsf/scooter/namedSelection/src/namedSelection/ui/GroupTree.java
2010-08-11 22:31:47 UTC (rev 21338)
@@ -104,6 +104,7 @@
setShowsRootHandles(false);
// setRootVisible(false);
setToggleClickCount(0); // Disable multi-click
+ setExpandsSelectedPaths(false);
setBackground(Cytoscape.getDesktop().getBackground());
}
@@ -173,6 +174,8 @@
Object userObject = treeNode.getUserObject();
boolean selected = e.isAddedPath(path);
+ // System.out.println("valueChanged: "+path+":
"+selected);
+
// Get the type of object
if (userObject instanceof CyNetwork) {
// This is either the root, the global network
or a network name
@@ -184,14 +187,16 @@
Cytoscape.setCurrentNetworkView(network.getIdentifier());
}
} else if (userObject instanceof CyGroup) {
- // Group
- // System.out.println("Group");
// select the group
CyGroup group = (CyGroup) userObject;
- if (selected)
+ if (selected) {
+ // System.out.println("valuchanged:
Selecting group: "+group);
group.setState(NamedSelection.SELECTED);
- else if (group.getState() ==
NamedSelection.SELECTED)
+ GroupTreeUtils.selectAllChildren(this,
path);
+ } else if (group.getState() ==
NamedSelection.SELECTED) {
+ // System.out.println("valuchanged:
Deselecting group: "+group);
group.setState(NamedSelection.UNSELECTED);
+ }
} else if (userObject instanceof CyNode) {
// Node
CyNode node = (CyNode)userObject;
@@ -205,6 +210,17 @@
GroupTreeUtils.selectNetworkNode(this,
parentNode, path, node, selected);
}
}
+
+ // OK, now, before we turn on updates again, sync the network
up if we've changed the
+ // state of a group
+ for (TreePath path: e.getPaths()) {
+ DefaultMutableTreeNode treeNode =
(DefaultMutableTreeNode)path.getLastPathComponent();
+ Object userObject = treeNode.getUserObject();
+ if (userObject instanceof CyGroup) {
+ GroupTreeUtils.syncNodesToPath(this, path,
(CyGroup)userObject);
+ }
+ }
+
setUpdates(true);
}
@@ -224,7 +240,7 @@
// If we are selected, select all of our children
if (isPathSelected(treePath)) {
GroupTreeUtils.selectAllChildren(this,
treePath);
- removeSelectionPath(treePath);
+ // removeSelectionPath(treePath);
}
}
setUpdates(true);
Modified:
csplugins/trunk/ucsf/scooter/namedSelection/src/namedSelection/ui/GroupTreeModel.java
===================================================================
---
csplugins/trunk/ucsf/scooter/namedSelection/src/namedSelection/ui/GroupTreeModel.java
2010-08-11 22:22:51 UTC (rev 21337)
+++
csplugins/trunk/ucsf/scooter/namedSelection/src/namedSelection/ui/GroupTreeModel.java
2010-08-11 22:31:47 UTC (rev 21338)
@@ -144,29 +144,43 @@
public void setTreeDepth(int depth, TreePath path) {
DefaultMutableTreeNode treeNode =
(DefaultMutableTreeNode)
path.getLastPathComponent();
+
navTree.expandPath(path);
for (int child = 0; child < treeNode.getChildCount(); child++) {
DefaultMutableTreeNode childNode =
(DefaultMutableTreeNode)treeNode.getChildAt(child);
- CyNode node = (CyNode)childNode.getUserObject();
- if (!nodeMap.containsKey(node)) {
- continue;
+ Object userObject = childNode.getUserObject();
+ TreePath pathToNode = null;
+ CyNode node = null;
+
+ if (userObject instanceof CyNetwork || userObject
instanceof String) {
+ // Get a treepath
+ pathToNode = path.pathByAddingChild(childNode);
+ } else if (userObject instanceof CyGroup) {
+ CyGroup group = (CyGroup)userObject;
+ node = group.getGroupNode();
+ } else if (userObject instanceof CyNode) {
+ node = (CyNode)userObject;
}
- // A node could be in mulitple paths, but we only want
- // the immediate descendant of "path"
- List<TreePath> pathsToNode = nodeMap.get(node);
- TreePath pathToNode = pathsToNode.get(0);
- for (int p = 1; p < pathsToNode.size(); p++) {
- if
(pathsToNode.get(p).getParentPath().equals(path)) {
- pathToNode = pathsToNode.get(p);
- break;
+ if (node != null && nodeMap.containsKey(node)) {
+ // A node could be in mulitple paths, but we
only want
+ // the immediate descendant of "path"
+ List<TreePath> pathsToNode = nodeMap.get(node);
+ pathToNode = pathsToNode.get(0);
+ for (int p = 1; p < pathsToNode.size(); p++) {
+ if
(pathsToNode.get(p).getParentPath().equals(path)) {
+ pathToNode = pathsToNode.get(p);
+ break;
+ }
}
}
- if (depth == 1) {
+ if (pathToNode != null) {
+ if (depth == 1) {
navTree.collapsePath(pathToNode);
- } else {
- setTreeDepth(depth-1, pathToNode);
+ } else {
+ setTreeDepth(depth-1, pathToNode);
+ }
}
}
}
Modified:
csplugins/trunk/ucsf/scooter/namedSelection/src/namedSelection/ui/GroupTreeUtils.java
===================================================================
---
csplugins/trunk/ucsf/scooter/namedSelection/src/namedSelection/ui/GroupTreeUtils.java
2010-08-11 22:22:51 UTC (rev 21337)
+++
csplugins/trunk/ucsf/scooter/namedSelection/src/namedSelection/ui/GroupTreeUtils.java
2010-08-11 22:31:47 UTC (rev 21338)
@@ -84,12 +84,19 @@
if (checkForPromotion(navTree, groupTreeNode, selected)) {
// System.out.println("Promoting");
navTree.addSelectionPath(path.getParentPath());
+ // System.out.println("Setting group "+group+"s state
to selected");
group.setState(NamedSelection.SELECTED);
} else {
- // System.out.println("Demoting");
+ // We don't want to promote, but we only want to demote
if we're
+ // deselecting and the group is selected
+ if (selected || group.getState() !=
NamedSelection.SELECTED)
+ return; // We were selecting, just ignore
this...
+
+ // OK, we were deselecting and our group was selected
navTree.removeSelectionPath(path.getParentPath());
// Unselect the group -- this will deselect all nodes
+ // System.out.println("Setting group "+group+"s state
to unselected");
group.setState(NamedSelection.UNSELECTED);
// Reselect the individual nodes based on our selected
paths
@@ -154,10 +161,13 @@
public static void selectTreeNode(GroupTree navTree, TreePath path,
boolean select) {
DefaultMutableTreeNode treeNode =
(DefaultMutableTreeNode)path.getLastPathComponent();
DefaultMutableTreeNode parentNode =
(DefaultMutableTreeNode)treeNode.getParent();
- if (select)
+ if (select) {
+ // System.out.println("Selecting "+path);
navTree.addSelectionPath(path);
- else
+ } else {
+ // System.out.println("Deselecting "+path);
navTree.removeSelectionPath(path);
+ }
handlePromotion(navTree, parentNode, path, select);
}
@@ -172,8 +182,10 @@
*/
public static void selectNetworkNode(GroupTree navTree,
DefaultMutableTreeNode groupNode,
TreePath treePath, CyNode node,
boolean selected) {
+ // System.out.println("selectNetworkNode:
"+node+"@"+treePath+": "+selected);
CyGroup group = (CyGroup)groupNode.getUserObject();
CyNetwork net = group.getNetwork();
+ handlePromotion(navTree, groupNode, treePath, selected);
if (net == null) {
for (CyNetwork network: Cytoscape.getNetworkSet()) {
// System.out.println("Setting node "+node+"s
state to "+selected);
@@ -185,15 +197,15 @@
net.setSelectedNodeState(node, selected);
Cytoscape.getNetworkView(net.getIdentifier()).updateView();
}
- handlePromotion(navTree, groupNode, treePath, selected);
}
public static void syncNodesToPath(GroupTree navTree, TreePath path,
CyGroup group) {
+ // System.out.println("Synching nodes to path: "+path);
DefaultMutableTreeNode groupTreeNode =
(DefaultMutableTreeNode)path.getLastPathComponent();
for (Enumeration<DefaultMutableTreeNode> e =
groupTreeNode.children(); e.hasMoreElements();) {
DefaultMutableTreeNode treeNode = e.nextElement();
TreePath childPath = new TreePath(treeNode.getPath());
- if (navTree.isPathSelected(path)) {
+ if (navTree.isPathSelected(childPath)) {
if (treeNode.getUserObject() instanceof CyNode)
{
selectNetworkNode(navTree,
groupTreeNode, childPath, (CyNode)treeNode.getUserObject(), true);
} else if (treeNode.getUserObject() instanceof
CyGroup) {
--
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.