Author: scooter
Date: 2012-09-19 18:23:01 -0700 (Wed, 19 Sep 2012)
New Revision: 30386
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/GroupUtil.java
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/write/session/SessionWriterImpl.java
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/write/xgmml/GenericXGMMLWriter.java
Log:
Fix for bug 1449.
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/GroupUtil.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/GroupUtil.java
2012-09-19 23:53:15 UTC (rev 30385)
+++
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/GroupUtil.java
2012-09-20 01:23:01 UTC (rev 30386)
@@ -1,8 +1,11 @@
package org.cytoscape.io.internal.util;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.cytoscape.group.CyGroup;
@@ -41,6 +44,9 @@
private final CyGroupManager groupMgr;
private final CyGroupFactory groupFactory;
+
+ // Remember groups that we had to add
+ private Map<CyNetwork, List<CyNode>> addedNodes = null;
public GroupUtil(final CyGroupManager groupMgr, final CyGroupFactory
groupFactory) {
assert groupMgr != null;
@@ -50,14 +56,16 @@
this.groupFactory = groupFactory;
}
- public void prepareGroupsForSerialization(final Set<CyNetwork>
networks) {
+ public void prepareGroupsForSerialization(final Collection<CyNetwork>
networks) {
if (networks == null)
return;
+
+ addedNodes = new HashMap<CyNetwork, List<CyNode>>();
for (CyNetwork net: networks) {
if (!(net instanceof CySubNetwork))
continue;
-
+
// Get the root network
CyRootNetwork rootNetwork =
((CySubNetwork)net).getRootNetwork();
// Get all of our groups
@@ -72,6 +80,33 @@
}
}
+ public void groupsSerialized(final Collection<CyNetwork> networks,
+ final Collection<CyNetworkView> views) {
+
+ if (networks == null)
+ return;
+
+ Map <CyNetwork, CyNetworkView> viewMap = new HashMap<CyNetwork,
CyNetworkView>();
+ if (views != null)
+ for (CyNetworkView view: views)
+ viewMap.put(view.getModel(), view);
+
+
+ for (CyNetwork net: networks) {
+ if (!(net instanceof CySubNetwork) ||
!addedNodes.containsKey(net))
+ continue;
+
+ List<CyNode> nodeList = addedNodes.get(net);
+ if (nodeList != null && nodeList.size() > 0) {
+ net.removeNodes(nodeList);
+ // Update our view if we have one
+ if (viewMap.containsKey(net))
+ viewMap.get(net).updateView();
+ }
+ }
+
+ }
+
public List<CyNode> getExpandedGroups(final CyNetwork network) {
// Get all of our groups in this network
Set<CyGroup> groupSet = groupMgr.getGroupSet(network);
@@ -321,6 +356,7 @@
private void updateGroupAttribute(final CyNetwork net, final CyGroup
group) {
CyNode node = group.getGroupNode();
+ List<CyNode> nodeList;
// Expanded groups won't show in the network. If it's not
there, we need
// to add it so that it will get serialized
@@ -328,6 +364,14 @@
// Node not in this network. Add it and mark it....
CySubNetwork subNet = (CySubNetwork)net;
subNet.addNode(node); // Temporarily add this to the
network so we can serialize it
+
+ // Remember it...
+ if (addedNodes.containsKey(net))
+ nodeList = addedNodes.get(net);
+ else
+ nodeList = new ArrayList<CyNode>();
+ nodeList.add(node);
+ addedNodes.put(net, nodeList);
}
CyTable hiddenTable = net.getTable(CyNode.class,
CyNetwork.HIDDEN_ATTRS);
@@ -431,4 +475,5 @@
if (table.getColumn(column) == null)
table.createListColumn(column, type, false);
}
+
}
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/write/session/SessionWriterImpl.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/write/session/SessionWriterImpl.java
2012-09-19 23:53:15 UTC (rev 30385)
+++
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/write/session/SessionWriterImpl.java
2012-09-20 01:23:01 UTC (rev 30386)
@@ -238,6 +238,9 @@
} catch (Exception e) {
logger.error("Error closing zip output stream", e);
}
+
+ // Tell the groupUtils that we're done
+ groupUtils.groupsSerialized(session.getNetworks(),
session.getNetworkViews());
}
/**
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/write/xgmml/GenericXGMMLWriter.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/write/xgmml/GenericXGMMLWriter.java
2012-09-19 23:53:15 UTC (rev 30385)
+++
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/write/xgmml/GenericXGMMLWriter.java
2012-09-20 01:23:01 UTC (rev 30386)
@@ -35,6 +35,7 @@
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedHashSet;
@@ -151,55 +152,55 @@
private boolean doFullEncoding;
- public GenericXGMMLWriter(final OutputStream outputStream,
- final
RenderingEngineManager renderingEngineMgr,
- final CyNetworkView
networkView,
- final
UnrecognizedVisualPropertyManager unrecognizedVisualPropertyMgr,
- final
CyNetworkManager networkMgr,
- final
CyRootNetworkManager rootNetworkMgr,
- final
VisualMappingManager vmMgr,
- final GroupUtil
groupUtil) {
- this(outputStream, renderingEngineMgr, networkView.getModel(),
unrecognizedVisualPropertyMgr, networkMgr,
- rootNetworkMgr, groupUtil);
- this.networkView = networkView;
-
- setVisualStyle(vmMgr.getVisualStyle(networkView));
+ public GenericXGMMLWriter(final OutputStream outputStream,
+ final RenderingEngineManager renderingEngineMgr,
+ final CyNetworkView networkView,
+ final UnrecognizedVisualPropertyManager
unrecognizedVisualPropertyMgr,
+ final CyNetworkManager networkMgr,
+ final CyRootNetworkManager rootNetworkMgr,
+ final VisualMappingManager vmMgr,
+ final GroupUtil groupUtil) {
+ this(outputStream, renderingEngineMgr, networkView.getModel(),
unrecognizedVisualPropertyMgr, networkMgr,
+ rootNetworkMgr, groupUtil);
+ this.networkView = networkView;
+
+ setVisualStyle(vmMgr.getVisualStyle(networkView));
}
- public GenericXGMMLWriter(final OutputStream outputStream,
- final
RenderingEngineManager renderingEngineMgr,
- final CyNetwork
network,
- final
UnrecognizedVisualPropertyManager unrecognizedVisualPropertyMgr,
- final
CyNetworkManager networkMgr,
- final
CyRootNetworkManager rootNetworkMgr,
- final GroupUtil
groupUtil) {
- this.outputStream = outputStream;
- this.unrecognizedVisualPropertyMgr =
unrecognizedVisualPropertyMgr;
- this.networkMgr = networkMgr;
- this.rootNetworkMgr = rootNetworkMgr;
- this.visualLexicon =
renderingEngineMgr.getDefaultVisualLexicon();
- this.groupUtil = groupUtil;
-
- if (network instanceof CyRootNetwork) {
- this.network = this.rootNetwork = (CyRootNetwork)
network;
- this.subNetworks =
getSerializableSubNetworks(rootNetwork);
- } else {
- this.network = network;
- this.rootNetwork =
rootNetworkMgr.getRootNetwork(network);
- this.subNetworks = new HashSet<CySubNetwork>();
- }
-
- // Create our indent string (480 blanks);
- for (int i = 0; i < 20; i++)
- indentString += " ";
-
- doFullEncoding =
Boolean.valueOf(System.getProperty(ENCODE_PROPERTY, "true"));
- }
+ public GenericXGMMLWriter(final OutputStream outputStream,
+ final RenderingEngineManager renderingEngineMgr,
+ final CyNetwork network,
+ final UnrecognizedVisualPropertyManager
unrecognizedVisualPropertyMgr,
+ final CyNetworkManager networkMgr,
+ final CyRootNetworkManager rootNetworkMgr,
+ final GroupUtil groupUtil) {
+ this.outputStream = outputStream;
+ this.unrecognizedVisualPropertyMgr = unrecognizedVisualPropertyMgr;
+ this.networkMgr = networkMgr;
+ this.rootNetworkMgr = rootNetworkMgr;
+ this.visualLexicon = renderingEngineMgr.getDefaultVisualLexicon();
+ this.groupUtil = groupUtil;
+
+ if (network instanceof CyRootNetwork) {
+ this.network = this.rootNetwork = (CyRootNetwork) network;
+ this.subNetworks = getSerializableSubNetworks(rootNetwork);
+ } else {
+ this.network = network;
+ this.rootNetwork = rootNetworkMgr.getRootNetwork(network);
+ this.subNetworks = new HashSet<CySubNetwork>();
+ }
+
+ // Create our indent string (480 blanks);
+ for (int i = 0; i < 20; i++)
+ indentString += " ";
+
+ doFullEncoding = Boolean.valueOf(System.getProperty(ENCODE_PROPERTY,
"true"));
+ }
- @Override
+ @Override
public void run(TaskMonitor taskMonitor) throws Exception {
- taskMonitor.setProgress(0.0);
- init(taskMonitor);
+ taskMonitor.setProgress(0.0);
+ init(taskMonitor);
writeRootElement();
taskMonitor.setProgress(0.2);
@@ -223,33 +224,36 @@
writer.flush();
taskMonitor.setProgress(1.0);
+
+ // Clean up the group stuff a little
+ if (groupUtil != null) {
+ groupUtil.groupsSerialized(Collections.singletonList(network),
null);
+ }
}
-
- protected void init(TaskMonitor tm) {
- writer = new OutputStreamWriter(outputStream);
- prepareGroupsForSerialization();
- }
-
- /**
- * Necessary only when exporting to XGMML.
- */
- protected void prepareGroupsForSerialization() {
- // Don't do this when saving the session-type XGMML files
- if (groupUtil != null) {
- Set<CyNetwork> netSet = new HashSet<CyNetwork>();
- netSet.add(network);
- groupUtil.prepareGroupsForSerialization(netSet);
- }
- }
+
+ protected void init(TaskMonitor tm) {
+ writer = new OutputStreamWriter(outputStream);
+ prepareGroupsForSerialization();
+ }
+
+ /**
+ * Necessary only when exporting to XGMML.
+ */
+ protected void prepareGroupsForSerialization() {
+ // Don't do this when saving the session-type XGMML files
+ if (groupUtil != null) {
+
groupUtil.prepareGroupsForSerialization(Collections.singletonList(network));
+ }
+ }
- /**
+ /**
* Output the XML preamble. This includes the XML line as well as the
initial
* <graph> element, along with all of our namespaces.
*
* @throws IOException
*/
protected void writeRootElement() throws IOException {
- writeElement(XML_STRING + "\n");
+ writeElement(XML_STRING + "\n");
writeElement("<graph");
writeRootElementAtributes();
@@ -268,8 +272,8 @@
String label = networkView != null ? getLabel(networkView) :
getLabel(network, network);
writeAttributePair("label", label);
-
- writeAttributePair("directed", getDirectionality());
+
+ writeAttributePair("directed", getDirectionality());
}
/**
@@ -277,14 +281,14 @@
* @throws IOException
*/
protected void writeMetadata() throws IOException {
- writeElement("<att name=\"networkMetadata\">\n");
- depth++;
-
- // Write RDF
- String title = networkView != null ? getLabel(networkView) :
getLabel(network, network);
- Date now = new Date();
+ writeElement("<att name=\"networkMetadata\">\n");
+ depth++;
+
+ // Write RDF
+ String title = networkView != null ? getLabel(networkView) :
getLabel(network, network);
+ Date now = new Date();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-
+
writeElement("<rdf:RDF>\n");
depth++;
writeElement("<rdf:Description
rdf:about=\"http://www.cytoscape.org/\">\n");
@@ -300,8 +304,8 @@
writeElement("</rdf:Description>\n");
depth--;
writeElement("</rdf:RDF>\n");
-
- depth--;
+
+ depth--;
writeElement("</att>\n");
}
@@ -312,140 +316,140 @@
*
* @throws IOException
*/
- protected void writeRootGraphAttributes() throws IOException {
- writeAttributes(network.getRow(network));
- writeAttributes(network.getRow(network,
CyNetwork.HIDDEN_ATTRS));
- writeGraphics(networkView, false);
- }
+ protected void writeRootGraphAttributes() throws IOException {
+ writeAttributes(network.getRow(network));
+ writeAttributes(network.getRow(network, CyNetwork.HIDDEN_ATTRS));
+ writeGraphics(networkView, false);
+ }
- protected void writeSubGraph(final CyNetwork net) throws IOException {
- if (net == null)
- return;
-
- if (writtenNetMap.containsKey(net)) {
- // This sub-network has already been written
- writeSubGraphReference(net);
- } else {
- // Check if this network is from the same root network
as the base network
- final CyRootNetwork otherRoot =
rootNetworkMgr.getRootNetwork(net);
- boolean sameRoot = rootNetwork.equals(otherRoot);
-
- if (sameRoot) {
- // Write it for the first time
- writtenNetMap.put(net, net);
-
- writeElement("<att>\n");
- depth++;
- writeElement("<graph");
- // Always write the network ID
- writeAttributePair("id", net.getSUID());
- // Save the label to make it more human readable
- writeAttributePair("label", getLabel(net, net));
- writeAttributePair("cy:registered",
ObjectTypeMap.toXGMMLBoolean(isRegistered(net)));
- write(">\n");
- depth++;
-
- writeAttributes(net.getRow(net));
- writeAttributes(net.getRow(net,
CyNetwork.HIDDEN_ATTRS));
-
- for (CyNode childNode : net.getNodeList())
- writeNode(net, childNode);
- for (CyEdge childEdge : net.getEdgeList())
- writeEdge(net, childEdge);
-
- depth--;
- writeElement("</graph>\n");
- depth--;
- writeElement("</att>\n");
- }
- }
- }
-
- protected void writeSubGraphReference(CyNetwork net) throws IOException
{
- if (net == null)
- return;
-
- String href = "#" + net.getSUID();
- final CyRootNetwork otherRoot =
rootNetworkMgr.getRootNetwork(net);
- final boolean sameRoot = rootNetwork.equals(otherRoot);
-
- if (!sameRoot) {
- // This network belongs to another XGMML file,
- // so add the other root-network's file name to the
XLink URI
- final String fileName =
SessionUtil.getXGMMLFilename(otherRoot);
- href = fileName + href;
- }
-
- writeElement("<att>\n");
- depth++;
- writeElement("<graph");
- writeAttributePair("xlink:href", href);
- write("/>\n");
- depth--;
- writeElement("</att>\n");
- }
+ protected void writeSubGraph(final CyNetwork net) throws IOException {
+ if (net == null)
+ return;
+
+ if (writtenNetMap.containsKey(net)) {
+ // This sub-network has already been written
+ writeSubGraphReference(net);
+ } else {
+ // Check if this network is from the same root network as the base
network
+ final CyRootNetwork otherRoot = rootNetworkMgr.getRootNetwork(net);
+ boolean sameRoot = rootNetwork.equals(otherRoot);
+
+ if (sameRoot) {
+ // Write it for the first time
+ writtenNetMap.put(net, net);
+
+ writeElement("<att>\n");
+ depth++;
+ writeElement("<graph");
+ // Always write the network ID
+ writeAttributePair("id", net.getSUID());
+ // Save the label to make it more human readable
+ writeAttributePair("label", getLabel(net, net));
+ writeAttributePair("cy:registered",
ObjectTypeMap.toXGMMLBoolean(isRegistered(net)));
+ write(">\n");
+ depth++;
+
+ writeAttributes(net.getRow(net));
+ writeAttributes(net.getRow(net, CyNetwork.HIDDEN_ATTRS));
- /**
- * Output Cytoscape nodes as XGMML
- * @throws IOException
- */
- protected void writeNodes() throws IOException {
- List<CyNode> pointerNodes = new ArrayList<CyNode>();
+ for (CyNode childNode : net.getNodeList())
+ writeNode(net, childNode);
+ for (CyEdge childEdge : net.getEdgeList())
+ writeEdge(net, childEdge);
+
+ depth--;
+ writeElement("</graph>\n");
+ depth--;
+ writeElement("</att>\n");
+ }
+ }
+ }
+
+ protected void writeSubGraphReference(CyNetwork net) throws IOException {
+ if (net == null)
+ return;
+
+ String href = "#" + net.getSUID();
+ final CyRootNetwork otherRoot = rootNetworkMgr.getRootNetwork(net);
+ final boolean sameRoot = rootNetwork.equals(otherRoot);
+
+ if (!sameRoot) {
+ // This network belongs to another XGMML file,
+ // so add the other root-network's file name to the XLink URI
+ final String fileName = SessionUtil.getXGMMLFilename(otherRoot);
+ href = fileName + href;
+ }
+
+ writeElement("<att>\n");
+ depth++;
+ writeElement("<graph");
+ writeAttributePair("xlink:href", href);
+ write("/>\n");
+ depth--;
+ writeElement("</att>\n");
+ }
- for (CyNode node : network.getNodeList()) {
- // Save all of the nodes with network pointers until
last
- // this allows us to have embedded networks...
- if (node.getNetworkPointer() != null) {
- pointerNodes.add(node);
- continue;
- }
+ /**
+ * Output Cytoscape nodes as XGMML
+ * @throws IOException
+ */
+ protected void writeNodes() throws IOException {
+ List<CyNode> pointerNodes = new ArrayList<CyNode>();
- // Only if not already written inside a nested graph
- if (!writtenNodeMap.containsKey(node))
- writeNode(network, node);
- }
+ for (CyNode node : network.getNodeList()) {
+ // Save all of the nodes with network pointers until last
+ // this allows us to have embedded networks...
+ if (node.getNetworkPointer() != null) {
+ pointerNodes.add(node);
+ continue;
+ }
- for (CyNode node : pointerNodes) {
- if (!writtenNodeMap.containsKey(node))
- writeNode(network, node);
- }
+ // Only if not already written inside a nested graph
+ if (!writtenNodeMap.containsKey(node))
+ writeNode(network, node);
+ }
- // Now, output nodes for expanded groups. We'll clean
- // these up on import...
- if (groupUtil != null) {
- for (CyNode node :
groupUtil.getExpandedGroups(network)) {
- if (!writtenNodeMap.containsKey(node))
- writeNode(network, node);
- }
- }
- }
-
- /**
+ for (CyNode node : pointerNodes) {
+ if (!writtenNodeMap.containsKey(node))
+ writeNode(network, node);
+ }
+
+ // Now, output nodes for expanded groups. We'll clean
+ // these up on import...
+ if (groupUtil != null) {
+ for (CyNode node : groupUtil.getExpandedGroups(network)) {
+ if (!writtenNodeMap.containsKey(node))
+ writeNode(network, node);
+ }
+ }
+ }
+
+ /**
* Output Cytoscape edges as XGMML
* @throws IOException
*/
protected void writeEdges() throws IOException {
- for (CyEdge edge : network.getEdgeList()) {
- // Only if not already written inside a nested graph
- if (!writtenEdgeMap.containsKey(edge))
- writeEdge(network, edge);
- }
+ for (CyEdge edge : network.getEdgeList()) {
+ // Only if not already written inside a nested graph
+ if (!writtenEdgeMap.containsKey(edge))
+ writeEdge(network, edge);
+ }
- // Now, output hidden edges groups.
- // For collapsed groups, we need to output external edges,
- // for expanded groups, we need to output edges to the group
node
- if (groupUtil != null) {
- // Handle edges to the group node
- for (CyEdge edge :
groupUtil.getGroupNodeEdges(network)) {
- if (!writtenEdgeMap.containsKey(edge))
- writeEdge(network, edge);
- }
- // Now handle external edges
- for (CyEdge edge : groupUtil.getExternalEdges(network))
{
- if (!writtenEdgeMap.containsKey(edge))
- writeEdge(network, edge);
- }
- }
+ // Now, output hidden edges groups.
+ // For collapsed groups, we need to output external edges,
+ // for expanded groups, we need to output edges to the group node
+ if (groupUtil != null) {
+ // Handle edges to the group node
+ for (CyEdge edge : groupUtil.getGroupNodeEdges(network)) {
+ if (!writtenEdgeMap.containsKey(edge))
+ writeEdge(network, edge);
+ }
+ // Now handle external edges
+ for (CyEdge edge : groupUtil.getExternalEdges(network)) {
+ if (!writtenEdgeMap.containsKey(edge))
+ writeEdge(network, edge);
+ }
+ }
}
/**
@@ -454,96 +458,96 @@
* @param node the node to output
* @throws IOException
*/
- protected void writeNode(final CyNetwork net, final CyNode node) throws
IOException {
- boolean written = writtenNodeMap.containsKey(node);
-
- // Output the node
- writeElement("<node");
-
- if (written) {
- // Write as an XLink only
- writeAttributePair("xlink:href", "#" + node.getSUID());
- write("/>\n");
- } else {
- // Remember that we've wrote this node
- writtenNodeMap.put(node, node);
-
- // Write the actual node with its properties
- writeAttributePair("id", node.getSUID());
- writeAttributePair("label", getLabel(net, node));
- write(">\n");
- depth++;
-
- // Output the node attributes
- writeAttributes(net.getRow(node));
- writeAttributes(net.getRow(node,
CyNetwork.HIDDEN_ATTRS));
-
- // Write node's sub-graph
- final CyNetwork netPointer = node.getNetworkPointer();
-
- if (netPointer != null && isSerializable(netPointer))
- writeSubGraph(netPointer);
-
- // Output the node graphics if we have a view
- if (networkView != null)
- writeGraphics(networkView.getNodeView(node),
false);
-
- depth--;
- writeElement("</node>\n");
- }
- }
-
+ protected void writeNode(final CyNetwork net, final CyNode node) throws
IOException {
+ boolean written = writtenNodeMap.containsKey(node);
+
+ // Output the node
+ writeElement("<node");
+
+ if (written) {
+ // Write as an XLink only
+ writeAttributePair("xlink:href", "#" + node.getSUID());
+ write("/>\n");
+ } else {
+ // Remember that we've wrote this node
+ writtenNodeMap.put(node, node);
+
+ // Write the actual node with its properties
+ writeAttributePair("id", node.getSUID());
+ writeAttributePair("label", getLabel(net, node));
+ write(">\n");
+ depth++;
+
+ // Output the node attributes
+ writeAttributes(net.getRow(node));
+ writeAttributes(net.getRow(node, CyNetwork.HIDDEN_ATTRS));
+
+ // Write node's sub-graph
+ final CyNetwork netPointer = node.getNetworkPointer();
+
+ if (netPointer != null && isSerializable(netPointer))
+ writeSubGraph(netPointer);
+
+ // Output the node graphics if we have a view
+ if (networkView != null && network.containsNode(node))
+ writeGraphics(networkView.getNodeView(node), false);
+
+ depth--;
+ writeElement("</node>\n");
+ }
+ }
+
/**
* Output a Cytoscape edge as XGMML
*
* @param edge the edge to output
* @throws IOException
*/
- protected void writeEdge(final CyNetwork net, final CyEdge edge) throws
IOException {
- writeElement("<edge");
- final boolean written = writtenEdgeMap.containsKey(edge);
-
- if (written) {
- // Write as an XLink only
- writeAttributePair("xlink:href", "#" + edge.getSUID());
- write("/>\n");
- } else {
- // Remember that we've wrote this edge
- writtenEdgeMap.put(edge, edge);
-
- writeAttributePair("id", edge.getSUID());
- writeAttributePair("label", getLabel(net, edge));
- writeAttributePair("source",
edge.getSource().getSUID());
- writeAttributePair("target",
edge.getTarget().getSUID());
- writeAttributePair("cy:directed",
ObjectTypeMap.toXGMMLBoolean(edge.isDirected()));
-
- write(">\n");
- depth++;
+ protected void writeEdge(final CyNetwork net, final CyEdge edge) throws
IOException {
+ writeElement("<edge");
+ final boolean written = writtenEdgeMap.containsKey(edge);
+
+ if (written) {
+ // Write as an XLink only
+ writeAttributePair("xlink:href", "#" + edge.getSUID());
+ write("/>\n");
+ } else {
+ // Remember that we've wrote this edge
+ writtenEdgeMap.put(edge, edge);
+
+ writeAttributePair("id", edge.getSUID());
+ writeAttributePair("label", getLabel(net, edge));
+ writeAttributePair("source", edge.getSource().getSUID());
+ writeAttributePair("target", edge.getTarget().getSUID());
+ writeAttributePair("cy:directed",
ObjectTypeMap.toXGMMLBoolean(edge.isDirected()));
+
+ write(">\n");
+ depth++;
- // Write the edge attributes
- writeAttributes(getRowFromNetOrRoot(net, edge, null));
- writeAttributes(getRowFromNetOrRoot(net, edge,
CyNetwork.HIDDEN_ATTRS));
-
- // Write the edge graphics
- if (networkView != null)
- writeGraphics(networkView.getEdgeView(edge),
false);
+ // Write the edge attributes
+ writeAttributes(getRowFromNetOrRoot(net, edge, null));
+ writeAttributes(getRowFromNetOrRoot(net, edge,
CyNetwork.HIDDEN_ATTRS));
+
+ // Write the edge graphics
+ if (networkView != null)
+ writeGraphics(networkView.getEdgeView(edge), false);
- depth--;
- writeElement("</edge>\n");
- }
- }
-
+ depth--;
+ writeElement("</edge>\n");
+ }
+ }
+
/**
* Writes a graphics tag under graph, node, edge.
* @param view
* @param groupLockedProperties Whether or not locked visual properties
must be grouped under a list-type att tag.
* @throws IOException
*/
- @SuppressWarnings({"unchecked", "rawtypes"})
- protected void writeGraphics(View<? extends CyIdentifiable> view, final
boolean groupLockedProperties)
- throws IOException {
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ protected void writeGraphics(View<? extends CyIdentifiable> view, final
boolean groupLockedProperties)
+ throws IOException {
if (view == null)
- return;
+ return;
writeElement("<graphics");
@@ -551,11 +555,11 @@
final VisualProperty<?> root;
if (element instanceof CyNode)
- root = BasicVisualLexicon.NODE;
+ root = BasicVisualLexicon.NODE;
else if (element instanceof CyEdge)
- root = BasicVisualLexicon.EDGE;
+ root = BasicVisualLexicon.EDGE;
else
- root = BasicVisualLexicon.NETWORK;
+ root = BasicVisualLexicon.NETWORK;
final Collection<VisualProperty<?>> visualProperties =
visualLexicon.getAllDescendants(root);
final List<VisualProperty<?>> attProperties = new
ArrayList<VisualProperty<?>>(); // To be written as att tags
@@ -563,85 +567,85 @@
final Set<String> writtenKeys = new HashSet<String>();
for (VisualProperty vp : visualProperties) {
- // If network, ignore node and edge visual properties,
- // because they are also returned as NETWORK's descendants
- if (root == BasicVisualLexicon.NETWORK &&
vp.getTargetDataType() != CyNetwork.class)
- continue;
-
+ // If network, ignore node and edge visual properties,
+ // because they are also returned as NETWORK's descendants
+ if (root == BasicVisualLexicon.NETWORK && vp.getTargetDataType()
!= CyNetwork.class)
+ continue;
+
// It doesn't have to write the property if the value is null
- Object value = view.getVisualProperty(vp);
+ Object value = view.getVisualProperty(vp);
if (value == null)
- continue;
+ continue;
if (groupLockedProperties && view.isValueLocked(vp)) {
- lockedProperties.add(vp);
- continue;
+ lockedProperties.add(vp);
+ continue;
} else {
- // If not a bypass, write only leaf nodes
- final VisualLexiconNode node =
visualLexicon.getVisualLexiconNode(vp);
+ // If not a bypass, write only leaf nodes
+ final VisualLexiconNode node =
visualLexicon.getVisualLexiconNode(vp);
- if (!node.getChildren().isEmpty())
- continue;
+ if (!node.getChildren().isEmpty())
+ continue;
}
- // Use XGMML graphics attribute names for some visual properties
+ // Use XGMML graphics attribute names for some visual properties
final String[] keys = getGraphicsKey(vp);
if (keys != null && keys.length > 0) {
- // XGMML graphics attributes...
- value = vp.toSerializableString(value);
-
- if (value != null) {
- for (int i = 0; i < keys.length; i++) {
- final String k = keys[i];
-
- if (!writtenKeys.contains(k)) {
- writeAttributePair(k, value);
- writtenKeys.add(k); // to avoid writing
the same key twice, because of dependencies!
- }
- }
- }
+ // XGMML graphics attributes...
+ value = vp.toSerializableString(value);
+
+ if (value != null) {
+ for (int i = 0; i < keys.length; i++) {
+ final String k = keys[i];
+
+ if (!writtenKeys.contains(k)) {
+ writeAttributePair(k, value);
+ writtenKeys.add(k); // to avoid writing the same
key twice, because of dependencies!
+ }
+ }
+ }
} else if (!ignoreGraphicsAttribute(element, vp.getIdString())) {
- // So it can be written as nested att tags
- attProperties.add(vp);
+ // So it can be written as nested att tags
+ attProperties.add(vp);
}
}
- Map<String, String> unrecognizedMap =
unrecognizedVisualPropertyMgr
- .getUnrecognizedVisualProperties(networkView,
view);
+ Map<String, String> unrecognizedMap = unrecognizedVisualPropertyMgr
+ .getUnrecognizedVisualProperties(networkView, view);
- if (attProperties.isEmpty() && lockedProperties.isEmpty() &&
unrecognizedMap.isEmpty()) {
- write("/>\n");
- } else {
- write(">\n");
- depth++;
+ if (attProperties.isEmpty() && lockedProperties.isEmpty() &&
unrecognizedMap.isEmpty()) {
+ write("/>\n");
+ } else {
+ write(">\n");
+ depth++;
- // write Cy3-specific properties
- for (VisualProperty vp : attProperties) {
- writeVisualPropertyAtt(view, vp);
+ // write Cy3-specific properties
+ for (VisualProperty vp : attProperties) {
+ writeVisualPropertyAtt(view, vp);
}
-
- // also save unrecognized visual properties
+
+ // also save unrecognized visual properties
for (Map.Entry<String, String> entry : unrecognizedMap.entrySet())
{
- String k = entry.getKey();
- String v = entry.getValue();
-
- if (v != null)
- writeAttributeXML(k, ObjectType.STRING, v, false, true);
+ String k = entry.getKey();
+ String v = entry.getValue();
+
+ if (v != null)
+ writeAttributeXML(k, ObjectType.STRING, v, false, true);
}
-
+
// serialize locked properties as <att> tags inside <graphics>
if (!lockedProperties.isEmpty()) {
- writeAttributeXML("lockedVisualProperties", ObjectType.LIST,
null, false, false);
- depth++;
-
- for (VisualProperty vp : lockedProperties) {
- writeVisualPropertyAtt(view, vp);
- }
-
- depth--;
- writeElement("</att>\n");
+ writeAttributeXML("lockedVisualProperties", ObjectType.LIST,
null, false, false);
+ depth++;
+
+ for (VisualProperty vp : lockedProperties) {
+ writeVisualPropertyAtt(view, vp);
+ }
+
+ depth--;
+ writeElement("</att>\n");
}
depth--;
@@ -650,16 +654,16 @@
}
@SuppressWarnings({ "unchecked", "rawtypes" })
- private void writeVisualPropertyAtt(View<? extends CyIdentifiable>
view, VisualProperty vp) throws IOException {
- Object value = view.getVisualProperty(vp);
- value = vp.toSerializableString(value);
-
- if (value != null) {
- writeAttributeXML(vp.getIdString(), ObjectType.STRING, value,
false, true);
- }
+ private void writeVisualPropertyAtt(View<? extends CyIdentifiable> view,
VisualProperty vp) throws IOException {
+ Object value = view.getVisualProperty(vp);
+ value = vp.toSerializableString(value);
+
+ if (value != null) {
+ writeAttributeXML(vp.getIdString(), ObjectType.STRING, value,
false, true);
+ }
}
- /**
+ /**
* Check directionality of edges, return directionality string to use in
xml
* file as attribute of graph element.
*
@@ -685,16 +689,16 @@
/**
* Do not use this method with locked visual properties.
- * @param element
- * @param attName
- * @return
- */
+ * @param element
+ * @param attName
+ * @return
+ */
protected boolean ignoreGraphicsAttribute(final CyIdentifiable element,
String attName) {
- return false;
- }
+ return false;
+ }
private String[] getGraphicsKey(VisualProperty<?> vp) {
- //Nodes
+ //Nodes
if (vp.equals(BasicVisualLexicon.NODE_X_LOCATION)) return new
String[]{"x"};
if (vp.equals(BasicVisualLexicon.NODE_Y_LOCATION)) return new
String[]{"y"};
if (vp.equals(BasicVisualLexicon.NODE_Z_LOCATION)) return new
String[]{"z"};
@@ -718,14 +722,14 @@
}
protected void writeAttributes(final CyRow row) throws IOException {
- // If it is a Cy Session XGMML, writing the CyRows would be
redundant,
- // because they are already serialized in .cytable files.
- final CyTable table = row.getTable();
+ // If it is a Cy Session XGMML, writing the CyRows would be redundant,
+ // because they are already serialized in .cytable files.
+ final CyTable table = row.getTable();
- for (final CyColumn column : table.getColumns()) {
- if (!CyIdentifiable.SUID.equals(column.getName()))
- writeAttribute(row, column.getName());
- }
+ for (final CyColumn column : table.getColumns()) {
+ if (!CyIdentifiable.SUID.equals(column.getName()))
+ writeAttribute(row, column.getName());
+ }
}
/**
@@ -737,66 +741,66 @@
* @throws IOException
*/
protected void writeAttribute(final CyRow row, final String attName)
throws IOException {
- // create an attribute and its type:
- final CyTable table = row.getTable();
- final CyColumn column = table.getColumn(attName);
-
- if (column == null)
- return;
-
- final boolean hidden = !table.isPublic();
- final Class<?> attType = column.getType();
+ // create an attribute and its type:
+ final CyTable table = row.getTable();
+ final CyColumn column = table.getColumn(attName);
+
+ if (column == null)
+ return;
+
+ final boolean hidden = !table.isPublic();
+ final Class<?> attType = column.getType();
- if (attType == Double.class) {
- Double dAttr = row.get(attName, Double.class);
- writeAttributeXML(attName, ObjectType.REAL, dAttr,
hidden, true);
- } else if (attType == Integer.class) {
- Integer iAttr = row.get(attName, Integer.class);
- writeAttributeXML(attName, ObjectType.INTEGER, iAttr,
hidden, true);
- } else if (attType == Long.class) {
- Long lAttr = row.get(attName, Long.class);
- writeAttributeXML(attName, ObjectType.REAL, lAttr,
hidden, true);
- } else if (attType == String.class) {
- String sAttr = row.get(attName, String.class);
- // Protect tabs and returns
- if (sAttr != null) {
- sAttr = sAttr.replace("\n", "\\n");
- sAttr = sAttr.replace("\t", "\\t");
- }
+ if (attType == Double.class) {
+ Double dAttr = row.get(attName, Double.class);
+ writeAttributeXML(attName, ObjectType.REAL, dAttr, hidden, true);
+ } else if (attType == Integer.class) {
+ Integer iAttr = row.get(attName, Integer.class);
+ writeAttributeXML(attName, ObjectType.INTEGER, iAttr, hidden,
true);
+ } else if (attType == Long.class) {
+ Long lAttr = row.get(attName, Long.class);
+ writeAttributeXML(attName, ObjectType.REAL, lAttr, hidden, true);
+ } else if (attType == String.class) {
+ String sAttr = row.get(attName, String.class);
+ // Protect tabs and returns
+ if (sAttr != null) {
+ sAttr = sAttr.replace("\n", "\\n");
+ sAttr = sAttr.replace("\t", "\\t");
+ }
- writeAttributeXML(attName, ObjectType.STRING, sAttr,
hidden, true);
- } else if (attType == Boolean.class) {
- Boolean bAttr = row.get(attName, Boolean.class);
- writeAttributeXML(attName, ObjectType.BOOLEAN,
ObjectTypeMap.toXGMMLBoolean(bAttr), hidden, true);
- } else if (attType == List.class) {
- final List<?> listAttr = row.getList(attName,
column.getListElementType());
- writeAttributeXML(attName, ObjectType.LIST, null,
hidden, false);
+ writeAttributeXML(attName, ObjectType.STRING, sAttr, hidden, true);
+ } else if (attType == Boolean.class) {
+ Boolean bAttr = row.get(attName, Boolean.class);
+ writeAttributeXML(attName, ObjectType.BOOLEAN,
ObjectTypeMap.toXGMMLBoolean(bAttr), hidden, true);
+ } else if (attType == List.class) {
+ final List<?> listAttr = row.getList(attName,
column.getListElementType());
+ writeAttributeXML(attName, ObjectType.LIST, null, hidden, false);
- if (listAttr != null) {
- depth++;
- // iterate through the list
- for (Object obj : listAttr) {
- String sAttr = null;
-
- if (obj instanceof Boolean) {
- sAttr =
ObjectTypeMap.toXGMMLBoolean((Boolean) obj);
- } else {
- // Protect tabs and returns (if
necessary)
- sAttr = obj.toString();
- if (sAttr != null) {
- sAttr =
sAttr.replace("\n", "\\n");
- sAttr =
sAttr.replace("\t", "\\t");
- }
- }
- // set child attribute value & label
- writeAttributeXML(attName,
checkType(obj), sAttr, hidden, true);
- }
- depth--;
- }
-
- writeAttributeXML(null, null, null, hidden, true);
- }
- }
+ if (listAttr != null) {
+ depth++;
+ // iterate through the list
+ for (Object obj : listAttr) {
+ String sAttr = null;
+
+ if (obj instanceof Boolean) {
+ sAttr = ObjectTypeMap.toXGMMLBoolean((Boolean) obj);
+ } else {
+ // Protect tabs and returns (if necessary)
+ sAttr = obj.toString();
+ if (sAttr != null) {
+ sAttr = sAttr.replace("\n", "\\n");
+ sAttr = sAttr.replace("\t", "\\t");
+ }
+ }
+ // set child attribute value & label
+ writeAttributeXML(attName, checkType(obj), sAttr, hidden,
true);
+ }
+ depth--;
+ }
+
+ writeAttributeXML(null, null, null, hidden, true);
+ }
+ }
/**
* writeAttributeXML outputs an XGMML attribute
@@ -814,14 +818,14 @@
writeElement("<att");
if (name != null)
- writeAttributePair("name", name);
+ writeAttributePair("name", name);
if (value != null)
- writeAttributePair("value", value);
+ writeAttributePair("value", value);
writeAttributePair("type", type);
if (hidden)
- writeAttributePair("cy:hidden",
ObjectTypeMap.toXGMMLBoolean(hidden));
+ writeAttributePair("cy:hidden",
ObjectTypeMap.toXGMMLBoolean(hidden));
if (end)
write("/>\n");
@@ -870,10 +874,10 @@
* @param obj
* @return Attribute type in string.
*/
- private ObjectType checkType(final Object obj) {
+ private ObjectType checkType(final Object obj) {
final Class<?> type = obj.getClass();
-
- if (type == String.class)
+
+ if (type == String.class)
return ObjectType.STRING;
else if (type == Integer.class)
return ObjectType.INTEGER;
@@ -889,37 +893,37 @@
String label =
encode(getRowFromNetOrRoot(network,entry,null).get(CyNetwork.NAME,
String.class));
if (label == null || label.isEmpty())
- label = Long.toString(entry.getSUID());
+ label = Long.toString(entry.getSUID());
return label;
}
protected String getLabel(CyNetworkView view) {
- String label = view.getVisualProperty(BasicVisualLexicon.NETWORK_TITLE);
+ String label =
view.getVisualProperty(BasicVisualLexicon.NETWORK_TITLE);
- if (label == null || label.isEmpty())
- label = Long.toString(view.getSUID());
+ if (label == null || label.isEmpty())
+ label = Long.toString(view.getSUID());
- return label;
- }
+ return label;
+ }
- protected CyRow getRowFromNetOrRoot(CyNetwork network, CyIdentifiable
entry, String namespace) {
- CyRow row = null;
- try {
- if (namespace == null)
- row = network.getRow(entry);
- else
- row = network.getRow(entry, namespace);
- } catch (IllegalArgumentException e) {
- // Doesn't exist in network. Try to get it from the
root
- CyRootNetwork root =
((CySubNetwork)network).getRootNetwork();
- if (namespace == null)
- row = root.getRow(entry);
- else
- row = root.getRow(entry, namespace);
- }
- return row;
- }
+ protected CyRow getRowFromNetOrRoot(CyNetwork network, CyIdentifiable
entry, String namespace) {
+ CyRow row = null;
+ try {
+ if (namespace == null)
+ row = network.getRow(entry);
+ else
+ row = network.getRow(entry, namespace);
+ } catch (IllegalArgumentException e) {
+ // Doesn't exist in network. Try to get it from the root
+ CyRootNetwork root = ((CySubNetwork)network).getRootNetwork();
+ if (namespace == null)
+ row = root.getRow(entry);
+ else
+ row = root.getRow(entry, namespace);
+ }
+ return row;
+ }
/**
* encode returns a quoted string appropriate for use as an XML attribute
@@ -977,40 +981,40 @@
return '"' + encode(str) + '"';
}
- /**
- * Used when saving the view-type XGMML.
- * @param visualStyleName
- */
- private void setVisualStyle(final VisualStyle visualStyle) {
- this.visualStyle = visualStyle;
- }
+ /**
+ * Used when saving the view-type XGMML.
+ * @param visualStyleName
+ */
+ private void setVisualStyle(final VisualStyle visualStyle) {
+ this.visualStyle = visualStyle;
+ }
/**
* @param rootNet
* @return A set with all the subnetworks that should be serialized.
*/
protected Set<CySubNetwork> getSerializableSubNetworks(final CyRootNetwork
rootNet) {
- final Set<CySubNetwork> serializableSet = new
LinkedHashSet<CySubNetwork>();
- final List<CySubNetwork> subNetList =
rootNet.getSubNetworkList();
- final CySubNetwork baseNetwork = rootNet.getBaseNetwork();
-
- // The base network must be the first one!
- if (isSerializable(baseNetwork))
- serializableSet.add(baseNetwork);
-
- for (final CySubNetwork sn : subNetList) {
- if (isSerializable(sn))
- serializableSet.add(sn);
- }
-
- return serializableSet;
- }
+ final Set<CySubNetwork> serializableSet = new
LinkedHashSet<CySubNetwork>();
+ final List<CySubNetwork> subNetList = rootNet.getSubNetworkList();
+ final CySubNetwork baseNetwork = rootNet.getBaseNetwork();
+
+ // The base network must be the first one!
+ if (isSerializable(baseNetwork))
+ serializableSet.add(baseNetwork);
+
+ for (final CySubNetwork sn : subNetList) {
+ if (isSerializable(sn))
+ serializableSet.add(sn);
+ }
+
+ return serializableSet;
+ }
protected boolean isSerializable(final CyNetwork net) {
- return net.getSavePolicy() != SavePolicy.DO_NOT_SAVE;
+ return net.getSavePolicy() != SavePolicy.DO_NOT_SAVE;
}
protected boolean isRegistered(final CyNetwork net) {
- return networkMgr.networkExists(net.getSUID());
+ return networkMgr.networkExists(net.getSUID());
}
}
--
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.