Author: ruschein
Date: 2011-01-24 13:03:52 -0800 (Mon, 24 Jan 2011)
New Revision: 23572

Added:
   core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/read/attrs/
   
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/read/attrs/MapNetworkAttrTask.java
Modified:
   core3/io-impl/trunk/pom.xml
Log:
New task to map network attributes.

Modified: core3/io-impl/trunk/pom.xml
===================================================================
--- core3/io-impl/trunk/pom.xml 2011-01-24 20:46:03 UTC (rev 23571)
+++ core3/io-impl/trunk/pom.xml 2011-01-24 21:03:52 UTC (rev 23572)
@@ -89,6 +89,16 @@
                        <version>3.0.0-alpha2-SNAPSHOT</version>
                </dependency>
                <dependency>
+                       <groupId>org.cytoscape</groupId>
+                       <artifactId>session-api</artifactId>
+                       <version>3.0.0-alpha2-SNAPSHOT</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.cytoscape</groupId>
+                       <artifactId>work-api</artifactId>
+                       <version>3.0.0-alpha2-SNAPSHOT</version>
+               </dependency>
+               <dependency>
                        <groupId>com.lowagie.text</groupId>
                        
<artifactId>com.springsource.com.lowagie.text</artifactId>
                        <version>2.0.8</version>

Added: 
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/read/attrs/MapNetworkAttrTask.java
===================================================================
--- 
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/read/attrs/MapNetworkAttrTask.java
                              (rev 0)
+++ 
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/read/attrs/MapNetworkAttrTask.java
      2011-01-24 21:03:52 UTC (rev 23572)
@@ -0,0 +1,74 @@
+package org.cytoscape.io.internal.read.attrs;
+
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.cytoscape.model.CyEdge;
+import org.cytoscape.model.CyNode;
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyNetworkManager;
+import org.cytoscape.model.CyTable;
+import org.cytoscape.model.CyTableEntry;
+import org.cytoscape.session.CyApplicationManager;
+import org.cytoscape.work.AbstractTask;
+import org.cytoscape.work.TaskMonitor;
+import org.cytoscape.work.Tunable;
+
+
+public final class MapNetworkAttrTask extends AbstractTask {
+       @Tunable(description="Map to current network only")
+       public boolean currentNetworkOnly = true;
+
+       private final CyTableEntry type; // Must be node or edge!
+       private final CyTable newGlobalTable;
+       private final CyNetworkManager networkManager;
+       final private CyApplicationManager applicationManager;
+
+       public MapNetworkAttrTask(final CyTableEntry type, final CyTable 
newGlobalTable,
+                                 final CyNetworkManager networkManager,
+                                 final CyApplicationManager applicationManager)
+       {
+               this.type               = type;
+               this.newGlobalTable     = newGlobalTable;
+               this.networkManager     = networkManager;
+               this.applicationManager = applicationManager;
+
+               if (!(type instanceof CyNode) && !(type instanceof CyEdge))
+                       throw new IllegalArgumentException("\"type\" must be 
CyNode.class or CyEdge.class!");
+       }
+
+       public void run(final TaskMonitor taskMonitor) throws Exception {
+               taskMonitor.setTitle("Mapping virtual columns");
+
+               final List<CyTable> targetTables = new ArrayList<CyTable>();
+               if (currentNetworkOnly) {
+                       final CyNetwork currentNetwork = 
applicationManager.getCurrentNetwork();
+                       targetTables.add(type instanceof CyNode ? 
currentNetwork.getDefaultNodeTable()
+                                                               : 
currentNetwork.getDefaultEdgeTable());
+               } else {
+                       final Set<CyNetwork> networks = 
networkManager.getNetworkSet();
+                       for (final CyNetwork network : networks)
+                               targetTables.add(type instanceof CyNode ? 
network.getDefaultNodeTable()
+                                                                       : 
network.getDefaultEdgeTable());
+               }
+
+               mapAll(targetTables);
+       }
+
+       private void mapAll(final List<CyTable> targetTables) {
+               if (targetTables.isEmpty())
+                       return;
+
+               if (newGlobalTable.getPrimaryKeyType() != String.class)
+                       throw new IllegalStateException("The new table's 
primary key is not of type String!");
+               final String sourceTableJoinColumn = 
newGlobalTable.getPrimaryKey();
+
+               for (final CyTable targetTable : targetTables) {
+                       if (cancelled)
+                               return;
+                       targetTable.addVirtualColumns(newGlobalTable, 
sourceTableJoinColumn, CyTableEntry.NAME);
+               }
+       }
+}
\ No newline at end of file

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