Author: scooter
Date: 2010-08-04 11:04:14 -0700 (Wed, 04 Aug 2010)
New Revision: 21188
Added:
cytoscape/trunk/application/src/main/java/cytoscape/groups/GroupPropertyChangeListener.java
Modified:
cytoscape/trunk/application/src/main/java/cytoscape/data/readers/XGMMLReader.java
cytoscape/trunk/application/src/main/java/cytoscape/data/writers/XGMMLWriter.java
cytoscape/trunk/application/src/main/java/cytoscape/dialogs/logger/LoggerDialog.java
cytoscape/trunk/application/src/main/java/cytoscape/groups/CyGroup.java
cytoscape/trunk/application/src/main/java/cytoscape/groups/CyGroupImpl.java
cytoscape/trunk/application/src/main/java/cytoscape/groups/CyGroupManager.java
cytoscape/trunk/application/src/main/java/cytoscape/groups/CyGroupViewer.java
Log:
First round of changes for groups
Modified:
cytoscape/trunk/application/src/main/java/cytoscape/data/readers/XGMMLReader.java
===================================================================
---
cytoscape/trunk/application/src/main/java/cytoscape/data/readers/XGMMLReader.java
2010-08-04 17:51:37 UTC (rev 21187)
+++
cytoscape/trunk/application/src/main/java/cytoscape/data/readers/XGMMLReader.java
2010-08-04 18:04:14 UTC (rev 21188)
@@ -671,9 +671,9 @@
/**
- * DOCUMENT ME!
+ * This method does all of our postprocessing after reading and
parsing the file
*
- * @param network DOCUMENT ME!
+ * @param network the network we've read in
*/
public void doPostProcessing(final CyNetwork network) {
parser.setMetaData(network);
@@ -696,7 +696,13 @@
for (CyNode groupNode : groupMap.keySet()) {
List<CyNode> childList =
groupMap.get(groupNode);
viewer =
nodeAttributes.getStringAttribute(groupNode.getIdentifier(),
CyGroup.GROUP_VIEWER_ATTR);
+ boolean isLocal =
nodeAttributes.getBooleanAttribute(groupNode.getIdentifier(),
CyGroup.GROUP_LOCAL_ATTR);
+ CyNetwork groupNetwork = null;
+
+ if (isLocal)
+ groupNetwork = network;
+
// Note that we need to leave the group node in
the network so that the saved
// location information (if there is any) can
be utilized by the group viewer.
// This means that it will be the
responsibility of the group viewer to remove
@@ -705,13 +711,13 @@
// Do we already have a view?
if (view == null || view ==
Cytoscape.getNullNetworkView()) {
// No, just create the group, but don't
assign a viewer
- newGroup =
CyGroupManager.createGroup(groupNode, childList, null);
+ newGroup =
CyGroupManager.createGroup(groupNode, childList, null, groupNetwork);
} else {
// Yes, see if the group already exists
newGroup =
CyGroupManager.getCyGroup(groupNode);
if (newGroup == null) {
// No, OK so create it and pass
down the viewer
-
CyGroupManager.createGroup(groupNode, childList, viewer);
+ newGroup =
CyGroupManager.createGroup(groupNode, childList, viewer, groupNetwork);
} else {
// Either the group doesn't
have a viewer or it has a different viewer -- change it
CyGroupManager.setGroupViewer(newGroup, viewer, view, false);
Modified:
cytoscape/trunk/application/src/main/java/cytoscape/data/writers/XGMMLWriter.java
===================================================================
---
cytoscape/trunk/application/src/main/java/cytoscape/data/writers/XGMMLWriter.java
2010-08-04 17:51:37 UTC (rev 21187)
+++
cytoscape/trunk/application/src/main/java/cytoscape/data/writers/XGMMLWriter.java
2010-08-04 18:04:14 UTC (rev 21188)
@@ -257,7 +257,7 @@
for (int i = 0; i < 20; i++)
indentString += " ";
- doFullEncoding = Boolean.valueOf(System.getProperty(ENCODE_PROPERTY,
"true"));
+ doFullEncoding =
Boolean.valueOf(System.getProperty(ENCODE_PROPERTY, "true"));
}
/**
@@ -304,8 +304,14 @@
// Output our nodes
writeNodes();
- writeGroups();
+ // Output any global groups
+ writeGroups(null);
+
+ // Now, output our groups
+ // Output any global groups
+ writeGroups(network);
+
// Create edge objects
writeEdges();
@@ -430,7 +436,7 @@
* @param node the node to output
* @throws IOException
*/
- private void writeNode(CyNode node, List<CyNode> groupList) throws
IOException {
+ private void writeNode(CyNode node, CyGroup group) throws IOException {
// Make sure this node is in this network
// if (!node.isaGroup() && !network.containsNode(node))
// return;
@@ -449,32 +455,14 @@
writeAttribute(node.getIdentifier(),
nodeAttributes, nodeAttNames[att]);
}
- if (groupList != null && groupList.size() > 0) {
- // If we're a group, output the graph attribute now
- writeElement("<att>\n");
- depth++;
- writeElement("<graph>\n");
- depth++;
- for (CyNode childNode: groupList) {
- if (childNode.isaGroup()) {
- // We have an embedded group -- recurse
- CyGroup childGroup =
CyGroupManager.getCyGroup(childNode);
- writeNode(childGroup.getGroupNode(),
childGroup.getNodes());
- } else {
- if (nodeMap.containsKey(childNode))
- writeElement("<node
xlink:href=\"#"+childNode.getRootGraphIndex()+"\"/>\n");
- else
- writeNode(childNode, null);
- }
- }
- depth--; writeElement("</graph>\n");
- depth--; writeElement("</att>\n");
+ if (group != null) {
+ writeGroup(group);
}
- if (networkView != null) {
- // Output the node graphics if we have a view
- writeNodeGraphics(node, (NodeView)networkView.getNodeView(node));
- }
+ if (networkView != null) {
+ // Output the node graphics if we have a view
+ writeNodeGraphics(node,
(NodeView)networkView.getNodeView(node));
+ }
depth--;
writeElement("</node>\n");
@@ -565,17 +553,19 @@
networkView.hideGraphObject(nodeView);
}
- private void writeGroups() throws IOException {
+ private void writeGroups(CyNetwork groupNetwork) throws IOException {
// Two pass approach. First, walk through the list
// and see if any of the children of a group are
// themselves a group. If so, remove them from
// the list & will pick them up on recursion, but only
// if all of the non-group node members are in
// this graph perspective
- List <CyGroup> groupList = (ArrayList)
CyGroupManager.getGroupList();
- if ((groupList == null) || groupList.isEmpty())
+ List <CyGroup> groupList = (ArrayList)
CyGroupManager.getGroupList(groupNetwork);
+
+ if ((groupList == null) || groupList.isEmpty()) {
return;
+ }
HashMap<CyGroup,CyGroup> embeddedGroupList = new HashMap();
List<CyGroup> groupsToWrite = new ArrayList();
@@ -606,23 +596,39 @@
if (embeddedGroupList.containsKey(group))
continue; // Yes, skip it
- writeNode(group.getGroupNode(), group.getNodes());
+ writeNode(group.getGroupNode(), group);
}
}
/**
- * Output Cytoscape edges as XGMML
+ * Write out a group
*
+ * @param group the group to output
* @throws IOException
*/
- private void writeEdges() throws IOException {
- for (CyEdge curEdge: (List<CyEdge>)network.edgesList()) {
- edgeMap.put(curEdge,curEdge);
- writeEdge(curEdge);
- }
+ private void writeGroup(CyGroup group) throws IOException {
- // Now add all of the group edges in case they're hidden
- for (CyGroup group: CyGroupManager.getGroupList()) {
+ List<CyNode> groupList = group.getNodes();
+ if (groupList != null && groupList.size() > 0) {
+ // If we're a group, output the graph attribute now
+ writeElement("<att>\n");
+ depth++;
+ writeElement("<graph>\n");
+ depth++;
+ for (CyNode childNode: groupList) {
+ if (childNode.isaGroup()) {
+ // We have an embedded group -- recurse
+ CyGroup childGroup =
CyGroupManager.getCyGroup(childNode);
+ writeNode(childGroup.getGroupNode(),
childGroup);
+ } else {
+ if (nodeMap.containsKey(childNode))
+ writeElement("<node
xlink:href=\"#"+childNode.getRootGraphIndex()+"\"/>\n");
+ else
+ writeNode(childNode, null);
+ }
+ }
+
+ // Now, output the edges for this group
for (CyEdge edge: group.getInnerEdges()) {
if (!edgeMap.containsKey(edge)) {
edgeMap.put(edge,edge);
@@ -635,10 +641,25 @@
writeEdge(edge);
}
}
+
+ depth--; writeElement("</graph>\n");
+ depth--; writeElement("</att>\n");
}
}
/**
+ * Output Cytoscape edges as XGMML
+ *
+ * @throws IOException
+ */
+ private void writeEdges() throws IOException {
+ for (CyEdge curEdge: (List<CyEdge>)network.edgesList()) {
+ edgeMap.put(curEdge,curEdge);
+ writeEdge(curEdge);
+ }
+ }
+
+ /**
* Output a Cytoscape edge as XGMML
*
* @param curEdge the edge to output
@@ -663,10 +684,10 @@
writeAttribute(curEdge.getIdentifier(),
edgeAttributes, edgeAttNames[att]);
}
- if (networkView != null) {
- // Write the edge graphics
- writeEdgeGraphics(curEdge,
(EdgeView)networkView.getEdgeView(curEdge));
- }
+ if (networkView != null) {
+ // Write the edge graphics
+ writeEdgeGraphics(curEdge,
(EdgeView)networkView.getEdgeView(curEdge));
+ }
depth--;
writeElement("</edge>\n");
Modified:
cytoscape/trunk/application/src/main/java/cytoscape/dialogs/logger/LoggerDialog.java
===================================================================
---
cytoscape/trunk/application/src/main/java/cytoscape/dialogs/logger/LoggerDialog.java
2010-08-04 17:51:37 UTC (rev 21187)
+++
cytoscape/trunk/application/src/main/java/cytoscape/dialogs/logger/LoggerDialog.java
2010-08-04 18:04:14 UTC (rev 21188)
@@ -110,8 +110,8 @@
private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) {
for (LogLevel key : this.messageMap.keySet()) {
this.messageMap.get(key).clear();
- ((JEditorPane)
this.logTabMap.get(key).getViewport().getView()).setText(
- "");
+ if
(this.logTabMap.containsKey(key))
+ ((JEditorPane)
this.logTabMap.get(key).getViewport().getView()).setText("");
}
}
Modified:
cytoscape/trunk/application/src/main/java/cytoscape/groups/CyGroup.java
===================================================================
--- cytoscape/trunk/application/src/main/java/cytoscape/groups/CyGroup.java
2010-08-04 17:51:37 UTC (rev 21187)
+++ cytoscape/trunk/application/src/main/java/cytoscape/groups/CyGroup.java
2010-08-04 18:04:14 UTC (rev 21188)
@@ -41,6 +41,7 @@
import java.util.List;
import cytoscape.CyEdge;
+import cytoscape.CyNetwork;
import cytoscape.CyNode;
@@ -70,6 +71,11 @@
*/
public static final String GROUP_STATE_ATTR = "__groupState";
+ /**
+ * The attribute that indicates that this is a local group
+ */
+ public static final String GROUP_LOCAL_ATTR = "__groupIsLocal";
+
// Public methods
/**
@@ -113,6 +119,21 @@
public List<CyEdge> getOuterEdges();
/**
+ * Get the network for this group
+ *
+ * @return network for this group or "null" if this is a global group
+ */
+ public CyNetwork getNetwork();
+
+ /**
+ * Set the network for this group
+ *
+ * @param network the network for this group or "null" if this is a
global group
+ * @param notify notify listeners of the change
+ */
+ public void setNetwork(CyNetwork network, boolean notify);
+
+ /**
* Add an outer edge to the map. Some viewers may need to do this
* if they add and remove edges, for example.
*
Modified:
cytoscape/trunk/application/src/main/java/cytoscape/groups/CyGroupImpl.java
===================================================================
--- cytoscape/trunk/application/src/main/java/cytoscape/groups/CyGroupImpl.java
2010-08-04 17:51:37 UTC (rev 21187)
+++ cytoscape/trunk/application/src/main/java/cytoscape/groups/CyGroupImpl.java
2010-08-04 18:04:14 UTC (rev 21188)
@@ -86,6 +86,12 @@
private HashMap<CyNode,List<CyEdge>> nodeToEdgeMap;
/**
+ * This is the network that this group is part of. If this
+ * is null, it's a global group.
+ */
+ private CyNetwork network = null;
+
+ /**
* The node that represents this group
*/
private CyNode groupNode = null;
@@ -122,6 +128,7 @@
this.nodeToEdgeMap = new HashMap();
this.innerEdgeMap = new HashMap();
this.outerEdgeMap = new HashMap();
+ this.network = null;
}
/**
@@ -153,13 +160,11 @@
* @param groupNode the group node to use for this group
* @param nodeList the initial set of nodes for this group
*/
- protected CyGroupImpl(CyNode groupNode, List nodeList) {
+ protected CyGroupImpl(CyNode groupNode, List<CyNode> nodeList) {
this(groupNode); // Create all of the necessary structures
- Iterator iter = nodeList.iterator();
-
- while (iter.hasNext()) {
- this.addNodeToGroup ( (CyNode)iter.next() );
+ for (CyNode node: nodeList) {
+ this.addNodeToGroup ( node );
}
}
@@ -264,6 +269,41 @@
}
/**
+ * Get the network this group is a member of
+ *
+ * @return the network, or null if this is a global group
+ */
+ public CyNetwork getNetwork() {
+ return network;
+ }
+
+ /**
+ * Set (or change) the network fro this group
+ *
+ * @param network the network to change this group to
+ * @param notify whether to notify any viewers
+ */
+ public void setNetwork(CyNetwork network, boolean notify) {
+
+ // Change our attribute
+ CyAttributes nodeAttributes = Cytoscape.getNodeAttributes();
+ if (network != null)
+ nodeAttributes.setAttribute(groupNode.getIdentifier(),
CyGroup.GROUP_LOCAL_ATTR, Boolean.TRUE);
+ else
+ nodeAttributes.setAttribute(groupNode.getIdentifier(),
CyGroup.GROUP_LOCAL_ATTR, Boolean.FALSE);
+
+ if (notify && this.network != network) {
+ // Get our viewer
+ CyGroupViewer v =
CyGroupManager.getGroupViewer(this.viewer);
+ if (v != null) {
+ // Tell the viewer that something has changed
+ v.groupChanged(this, null,
CyGroupViewer.ChangeType.NETWORK_CHANGED);
+ }
+ }
+ this.network = network;
+ }
+
+ /**
* Determine if a node is a member of this group
*
* @param node the CyNode to test
@@ -370,22 +410,22 @@
* @param node the node to add
*/
public void addNode ( CyNode node ) {
+ // First see if this node is already in this group
+ if (nodeToEdgeMap.containsKey(node))
+ return;
+
// We need to go throught our outerEdgeMap first to see if this
// node has outer edges and proactively move them to inner
edges.
// this needs to be done here because some viewers might have
// hidden edges on us, so the the call to
getAdjacentEdgeIndices in
// addNodeToGroup won't return all of the edges.
List <CyEdge> eMove = new ArrayList<CyEdge>();
- Iterator <CyEdge>edgeIter = outerEdgeMap.keySet().iterator();
- while (edgeIter.hasNext()) {
- CyEdge edge = edgeIter.next();
+ for (CyEdge edge: outerEdgeMap.keySet()) {
if (edge.getTarget() == node || edge.getSource() ==
node) {
eMove.add(edge);
}
}
- edgeIter = eMove.iterator();
- while (edgeIter.hasNext()) {
- CyEdge edge = edgeIter.next();
+ for (CyEdge edge: eMove) {
outerEdgeMap.remove(edge);
innerEdgeMap.put(edge,edge);
}
@@ -428,7 +468,11 @@
private void addNodeToGroup ( CyNode node ) {
// Put this node in our map
nodeMap.put(node, node);
- CyNetwork network = Cytoscape.getCurrentNetwork();
+ CyNetwork groupNetwork = this.network;
+
+ if (groupNetwork == null)
+ groupNetwork = Cytoscape.getCurrentNetwork();
+
List <CyEdge>edgeList = null;
if (nodeToEdgeMap.containsKey(node)) {
@@ -438,11 +482,11 @@
}
// Add all of the edges
- int [] edgeArray =
network.getAdjacentEdgeIndicesArray(node.getRootGraphIndex(),true,true,true);
+ int [] edgeArray =
groupNetwork.getAdjacentEdgeIndicesArray(node.getRootGraphIndex(),true,true,true);
if (edgeArray == null)
edgeArray = new int[]{};
for (int edgeIndex = 0; edgeIndex < edgeArray.length;
edgeIndex++) {
- CyEdge edge =
(CyEdge)network.getEdge(edgeArray[edgeIndex]);
+ CyEdge edge =
(CyEdge)groupNetwork.getEdge(edgeArray[edgeIndex]);
// Not sure if this is faster or slower than going
through the entire loop
if (edgeList.contains(edge))
continue;
@@ -486,8 +530,7 @@
// Get the list of edges
List <CyEdge>edgeArray = nodeToEdgeMap.get(node);
- for (Iterator <CyEdge>iter = edgeArray.iterator();
iter.hasNext(); ) {
- CyEdge edge = iter.next();
+ for (CyEdge edge: edgeArray) {
if (innerEdgeMap.containsKey(edge)) {
innerEdgeMap.remove(edge);
outerEdgeMap.put(edge,edge);
Modified:
cytoscape/trunk/application/src/main/java/cytoscape/groups/CyGroupManager.java
===================================================================
---
cytoscape/trunk/application/src/main/java/cytoscape/groups/CyGroupManager.java
2010-08-04 17:51:37 UTC (rev 21187)
+++
cytoscape/trunk/application/src/main/java/cytoscape/groups/CyGroupManager.java
2010-08-04 18:04:14 UTC (rev 21188)
@@ -40,7 +40,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -78,10 +77,25 @@
private static Map<CyGroupViewer, List<CyGroup>> groupViewerMap = new
HashMap<CyGroupViewer, List<CyGroup>>();
/**
+ * The list of groups, indexed by the network
+ */
+ private static Map<CyNetwork, List<CyGroup>> networkGroupMap = new
HashMap<CyNetwork, List<CyGroup>>();
+
+ /**
* The list of group change listeners
*/
private static List<CyGroupChangeListener> changeListeners = new
ArrayList<CyGroupChangeListener>();
+ /**
+ * The internal group map for global groups
+ */
+ private static CyNetwork GLOBAL_GROUPS = Cytoscape.getNullNetwork();
+
+ /**
+ * Initialize our property change listener
+ */
+ private static GroupPropertyChangeListener gpcl = new
GroupPropertyChangeListener();
+
// Static methods
/**
* getCyGroup is a static method that returns a CyGroup structure when
@@ -106,11 +120,8 @@
*/
public static List<CyGroup> getGroup(CyNode memberNode) {
List<CyGroup> groupList = new ArrayList<CyGroup>();
- final Iterator<CyGroup> groupIter =
groupMap.values().iterator();
- while (groupIter.hasNext()) {
- CyGroup group = groupIter.next();
-
+ for (CyGroup group: groupMap.values()) {
if (group.contains(memberNode))
groupList.add(group);
}
@@ -133,6 +144,24 @@
}
/**
+ * Return the list of all groups for this network
+ *
+ * @param network the network we're interested in. If network is null,
return
+ * the list of global groups
+ * @return the list of groups
+ */
+ public static List<CyGroup> getGroupList(CyNetwork network) {
+ if (network == null) {
+ network = GLOBAL_GROUPS;
+ }
+
+ if (networkGroupMap.containsKey(network))
+ return networkGroupMap.get(network);
+
+ return new ArrayList();
+ }
+
+ /**
* Return the list of all groups managed by a particular viewer
*
* @param viewer the CyGroupViewer
@@ -175,14 +204,16 @@
*
* @param groupName the identifier to use for this group -- should be
unique!
* @param viewer the name of the viewer to manage this group
+ * @param network the network that this group is in
* @return the newly created group
*/
- public static CyGroup createGroup(String groupName, String viewer) {
+ public static CyGroup createGroup(String groupName, String viewer,
CyNetwork network) {
// Do we already have a group by this name?
if (findGroup(groupName) != null) return null;
// Create the group
CyGroup group = new CyGroupImpl(groupName);
groupMap.put(group.getGroupNode(), group);
+ setGroupNetwork(group, network);
notifyListeners(group,
CyGroupChangeListener.ChangeType.GROUP_CREATED);
setGroupViewer(group, viewer, null, true);
return group;
@@ -197,13 +228,15 @@
* @param groupName the identifier to use for this group -- should be
unique!
* @param nodeList the initial set of nodes for this group
* @param viewer the name of the viewer to manage this group
+ * @param network the network that this group is in
*/
- public static CyGroup createGroup(String groupName, List<CyNode>
nodeList, String viewer) {
+ public static CyGroup createGroup(String groupName, List<CyNode>
nodeList, String viewer, CyNetwork network) {
// Do we already have a group by this name?
if (findGroup(groupName) != null) return null;
// Create the group
CyGroup group = new CyGroupImpl(groupName, nodeList);
groupMap.put(group.getGroupNode(), group);
+ setGroupNetwork(group, network);
notifyListeners(group,
CyGroupChangeListener.ChangeType.GROUP_CREATED);
setGroupViewer(group, viewer, null, false);
return group;
@@ -219,8 +252,9 @@
* @param groupNode the groupNode to use for this group
* @param nodeList the initial set of nodes for this group
* @param viewer the name of the viewer to manage this group
+ * @param network the network that this group is in
*/
- public static CyGroup createGroup(CyNode groupNode, List<CyNode>
nodeList, String viewer) {
+ public static CyGroup createGroup(CyNode groupNode, List<CyNode>
nodeList, String viewer, CyNetwork network) {
// Do we already have a group by this name?
if (findGroup(groupNode.getIdentifier()) != null) return null;
// Create the group
@@ -239,6 +273,8 @@
group.setState(state);
} catch (Exception e) {}
+ setGroupNetwork(group, network);
+
notifyListeners(group,
CyGroupChangeListener.ChangeType.GROUP_CREATED);
if (viewer != null)
@@ -247,6 +283,52 @@
}
/**
+ * Create a new, empty group. Use this to get a new group. In
particular,
+ * this form should be used by internal routines (as opposed to view
+ * implementations) as this form will cause the viewer to be notified of
+ * the group creation. Viewers should use createGroup(String, List,
String)
+ * as defined below.
+ *
+ * @param groupName the identifier to use for this group -- should be
unique!
+ * @param viewer the name of the viewer to manage this group
+ * @return the newly created group
+ */
+ public static CyGroup createGroup(String groupName, String viewer) {
+ return createGroup(groupName, viewer, null);
+ }
+
+ /**
+ * Create a new, empty group. Use this to get a new group. In
particular,
+ * this form should be used by internal routines (as opposed to view
+ * implementations) as this form will cause the viewer to be notified of
+ * the group creation. Viewers should use createGroup(String, List,
String)
+ * as defined below.
+ *
+ * @param groupName the identifier to use for this group -- should be
unique!
+ * @param nodeList the initial set of nodes for this group
+ * @param viewer the name of the viewer to manage this group
+ * @return the newly created group
+ */
+ public static CyGroup createGroup(String groupName,
List<CyNode>nodeList, String viewer) {
+ return createGroup(groupName, nodeList, viewer, null);
+ }
+
+ /**
+ * Create a new group with a list of nodes as initial members, and a
precreated
+ * group node. This is usually used by the XGMML reader since the
group node
+ * may need to alread be created with its associated "extra" edges.
Note that
+ * the node will be created, but *not* added to the network. That is
the
+ * responsibility of the appropriate viewer.
+ *
+ * @param groupNode the groupNode to use for this group
+ * @param nodeList the initial set of nodes for this group
+ * @param viewer the name of the viewer to manage this group
+ */
+ public static CyGroup createGroup(CyNode groupNode, List<CyNode>
nodeList, String viewer) {
+ return createGroup(groupNode, nodeList, viewer, null);
+ }
+
+ /**
* Remove (delete) a group
*
* @param group the group to remove
@@ -267,6 +349,7 @@
// Remove this from the viewer's list
CyGroup group = groupMap.get(groupNode);
String viewer = group.getViewer();
+ CyNetwork network = group.getNetwork();
if ((viewer != null) && viewerMap.containsKey(viewer)) {
CyGroupViewer groupViewer =
viewerMap.get(viewer);
@@ -274,18 +357,25 @@
gList.remove(group);
}
+ if ((network != null) &&
networkGroupMap.containsKey(network)) {
+ List<CyGroup> gList =
networkGroupMap.get(network);
+ gList.remove(group);
+
+ if (gList.size() == 0)
+ networkGroupMap.remove(network);
+ }
+
// Remove it from the groupMap
groupMap.remove(groupNode);
// Remove this group from all the nodes
List<CyNode> nodeList = group.getNodes();
- Iterator <CyNode> nIter = nodeList.iterator();
- while (nIter.hasNext()) {
- CyNode node = nIter.next();
+ for (CyNode node: nodeList) {
node.removeFromGroup(group);
}
- CyNetwork network = Cytoscape.getCurrentNetwork();
+ if (network == null)
+ network = Cytoscape.getCurrentNetwork();
network.removeNode(groupNode.getRootGraphIndex(),
false);
// Remove the group node form the network
// RootGraph rg = groupNode.getRootGraph();
@@ -334,6 +424,8 @@
* @param notify if 'true' the viewer will be notified of the creation
*/
public static void setGroupViewer(CyGroup group, String viewer,
CyNetworkView myView, boolean notify) {
+ if (group == null) return;
+
// See if we need to remove the current viewer first
if (group.getViewer() != null) {
// get the viewer
@@ -437,9 +529,32 @@
* @param whatChanged the thing that has changed about the group
*/
private static void notifyListeners(CyGroup group,
CyGroupChangeListener.ChangeType whatChanged) {
- Iterator <CyGroupChangeListener> listeners =
changeListeners.iterator();
- while (listeners.hasNext()) {
- (listeners.next()).groupChanged(group, whatChanged);
+ for (CyGroupChangeListener listener: changeListeners) {
+ listener.groupChanged(group, whatChanged);
}
}
+
+
+ /**
+ * Maintain the network group map
+ *
+ * @param group the group we're adding to the map
+ * @param network the network -- if it's null, we're adding it to the
global map
+ */
+ private static void setGroupNetwork(CyGroup group, CyNetwork network) {
+ group.setNetwork(network, false);
+ if (network == null)
+ network = GLOBAL_GROUPS;
+
+ List<CyGroup> groupList = null;
+
+ if (!networkGroupMap.containsKey(network)) {
+ groupList = new ArrayList<CyGroup>();
+ } else {
+ groupList = networkGroupMap.get(network);
+ }
+ groupList.add(group);
+ networkGroupMap.put(network, groupList);
+ }
+
}
Modified:
cytoscape/trunk/application/src/main/java/cytoscape/groups/CyGroupViewer.java
===================================================================
---
cytoscape/trunk/application/src/main/java/cytoscape/groups/CyGroupViewer.java
2010-08-04 17:51:37 UTC (rev 21187)
+++
cytoscape/trunk/application/src/main/java/cytoscape/groups/CyGroupViewer.java
2010-08-04 18:04:14 UTC (rev 21188)
@@ -51,7 +51,7 @@
/**
* The change values
*/
- public static enum ChangeType { NODE_ADDED, NODE_REMOVED, STATE_CHANGED
}
+ public static enum ChangeType { NODE_ADDED, NODE_REMOVED,
STATE_CHANGED, NETWORK_CHANGED }
/**
* Provide the string name of this viewer. This will be used to
reassociate
Added:
cytoscape/trunk/application/src/main/java/cytoscape/groups/GroupPropertyChangeListener.java
===================================================================
---
cytoscape/trunk/application/src/main/java/cytoscape/groups/GroupPropertyChangeListener.java
(rev 0)
+++
cytoscape/trunk/application/src/main/java/cytoscape/groups/GroupPropertyChangeListener.java
2010-08-04 18:04:14 UTC (rev 21188)
@@ -0,0 +1,70 @@
+/* vim :set ts=2: */
+/*
+ File: GroupPropertyChangeListener.java
+
+ Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+ The Cytoscape Consortium is:
+ - Institute for Systems Biology
+ - University of California San Diego
+ - Memorial Sloan-Kettering Cancer Center
+ - Institut Pasteur
+ - Agilent Technologies
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+package cytoscape.groups;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import cytoscape.CyNetwork;
+import cytoscape.Cytoscape;
+
+/**
+ * This inner class listens for network destroyed events and deletes
+ * any groups in that network
+ */
+class GroupPropertyChangeListener implements PropertyChangeListener {
+ public void propertyChange(PropertyChangeEvent e) {
+ if (Cytoscape.NETWORK_DESTROYED.equals(e.getPropertyName())) {
+ String networkId = (String) e.getNewValue();
+ if (networkId == null)
+ return;
+
+ CyNetwork network = Cytoscape.getNetwork(networkId);
+ if (network == null ||
network.equals(Cytoscape.getNullNetwork()))
+ return;
+
+ List<CyGroup> groupList =
CyGroupManager.getGroupList(network);
+ for (CyGroup group: groupList) {
+ CyGroupManager.removeGroup(group);
+ }
+ }
+ }
+}
--
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.