Author: pwang
Date: 2012-01-13 16:22:06 -0800 (Fri, 13 Jan 2012)
New Revision: 28018

Added:
   
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/export/table/SelectExportTableTask.java
Log:
Original creation

Added: 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/export/table/SelectExportTableTask.java
===================================================================
--- 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/export/table/SelectExportTableTask.java
                           (rev 0)
+++ 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/export/table/SelectExportTableTask.java
   2012-01-14 00:22:06 UTC (rev 28018)
@@ -0,0 +1,88 @@
+package org.cytoscape.task.internal.export.table;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.cytoscape.work.AbstractTask;
+import org.cytoscape.work.TaskMonitor;
+import org.cytoscape.work.Tunable;
+import org.cytoscape.work.util.ListSingleSelection;
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyNetworkManager;
+import org.cytoscape.model.CyTable;
+import org.cytoscape.model.CyTableManager;
+import org.cytoscape.io.write.CyTableWriterManager;
+
+import java.util.Iterator;
+import java.util.HashMap;
+import java.util.Collections;
+
+
+public class SelectExportTableTask extends AbstractTask {
+
+       @Tunable(description = "Select a table to export:")
+       public  ListSingleSelection<String> selectTable;
+       
+       private final CyTableWriterManager writerManager;
+       private final CyTableManager cyTableManagerServiceRef;
+       private final CyNetworkManager cyNetworkManagerServiceRef;
+
+       private HashMap<CyTable, CyNetwork> tableNetworkMap = new 
HashMap<CyTable, CyNetwork>();
+       private HashMap<String, CyTable> titleTableMap = new HashMap<String, 
CyTable>();
+       
+       public SelectExportTableTask (CyTableWriterManager 
writerManager,CyTableManager cyTableManagerServiceRef, CyNetworkManager 
cyNetworkManagerServiceRef){
+               this.cyTableManagerServiceRef = cyTableManagerServiceRef;
+               this.writerManager = writerManager;
+               this.cyNetworkManagerServiceRef = cyNetworkManagerServiceRef;
+
+               populateTableNetowrkMap();
+               
+               final List<String> options = new ArrayList<String>();
+               Set<CyTable> tableSet = 
this.cyTableManagerServiceRef.getAllTables(false);
+               
+               Iterator<CyTable> it = tableSet.iterator();
+               while (it.hasNext()){
+                       CyTable tbl = it.next();
+
+                       CyNetwork net = this.tableNetworkMap.get(tbl);
+                       
+                       String title = tbl.getTitle();
+                       if (net != null){
+                               title = net.getRow(net).get("name", 
String.class)+" -- "+title;
+                       }
+                       
+                       options.add(title);                     
+                       this.titleTableMap.put(title, tbl);
+               }
+               
+               Collections.sort(options);
+               selectTable =  new ListSingleSelection<String>(options);
+       }
+       
+       
+       private void populateTableNetowrkMap() {
+               
+               Iterator<CyNetwork> it = 
this.cyNetworkManagerServiceRef.getNetworkSet().iterator();
+               
+               while (it.hasNext()){
+                       CyNetwork net = it.next();
+                       this.tableNetworkMap.put(net.getDefaultNetworkTable(), 
net);
+                       this.tableNetworkMap.put(net.getDefaultNodeTable(), 
net);
+                       this.tableNetworkMap.put(net.getDefaultEdgeTable(), 
net);
+               }
+       }
+       
+
+       @Override
+       public void run(TaskMonitor tm) throws IOException {
+
+               //Get the selected table
+               final String selectedTitle = selectTable.getSelectedValue();    
        
+               CyTable tbl = this.titleTableMap.get(selectedTitle);
+
+               // Export the selected table
+               this.insertTasksAfterCurrentTask(new 
CyTableWriter(writerManager, tbl));                
+       }
+}


Property changes on: 
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/export/table/SelectExportTableTask.java
___________________________________________________________________
Added: svn:executable
   + *

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