Author: kono
Date: 2011-01-25 16:45:16 -0800 (Tue, 25 Jan 2011)
New Revision: 23621

Modified:
   
core3/webservice-biomart-client/trunk/src/main/java/org/cytoscape/io/webservice/biomart/BiomartClient.java
   
core3/webservice-biomart-client/trunk/src/main/java/org/cytoscape/io/webservice/biomart/task/ImportTableTask.java
   
core3/webservice-biomart-client/trunk/src/main/java/org/cytoscape/io/webservice/biomart/task/ShowBiomartDialogTask.java
   
core3/webservice-biomart-client/trunk/src/main/java/org/cytoscape/io/webservice/biomart/task/ShowBiomartGUIAction.java
   
core3/webservice-biomart-client/trunk/src/main/java/org/cytoscape/io/webservice/biomart/ui/AttributeImportPanel.java
   
core3/webservice-biomart-client/trunk/src/main/java/org/cytoscape/io/webservice/biomart/ui/BiomartAttrMappingPanel.java
   
core3/webservice-biomart-client/trunk/src/main/resources/META-INF/spring/bundle-context.xml
Log:
Result message added.  Some minor bugs are fixed.

Modified: 
core3/webservice-biomart-client/trunk/src/main/java/org/cytoscape/io/webservice/biomart/BiomartClient.java
===================================================================
--- 
core3/webservice-biomart-client/trunk/src/main/java/org/cytoscape/io/webservice/biomart/BiomartClient.java
  2011-01-26 00:01:44 UTC (rev 23620)
+++ 
core3/webservice-biomart-client/trunk/src/main/java/org/cytoscape/io/webservice/biomart/BiomartClient.java
  2011-01-26 00:45:16 UTC (rev 23621)
@@ -39,6 +39,7 @@
 
 import javax.naming.ConfigurationException;
 
+import org.cytoscape.application.swing.CySwingApplication;
 import org.cytoscape.io.webservice.TableImportWebServiceClient;
 import org.cytoscape.io.webservice.biomart.rest.BiomartRestClient;
 import org.cytoscape.io.webservice.biomart.task.ImportTableTask;
@@ -67,6 +68,8 @@
 
        private final CyNetworkManager networkManager;
        private final CyApplicationManager applicationManager;
+       
+       private final CySwingApplication app;
 
        /**
         * Creates a new Biomart Client object.
@@ -78,7 +81,7 @@
                        final BiomartRestClient restClient,
                        final CyTableFactory tableFactory,
                        final CyNetworkManager networkManager,
-                       final CyApplicationManager applicationManager) {
+                       final CyApplicationManager applicationManager, final 
CySwingApplication app) {
                super(restClient.getBaseURL(), displayName, description);
 
                this.tableFactory = tableFactory;
@@ -86,6 +89,7 @@
 
                this.networkManager = networkManager;
                this.applicationManager = applicationManager;
+               this.app = app;
 
                // TODO: set optional parameters (Tunables?)
        }
@@ -115,9 +119,8 @@
 
                final BiomartQuery query = this.gui.getTableImportQuery();
 
-               importTask = new ImportTableTask(restClient, query, 
tableFactory, networkManager, applicationManager);
+               importTask = new ImportTableTask(restClient, query, 
tableFactory, networkManager, applicationManager, app.getJFrame());
 
-               
                return new TaskIterator(importTask);
        }
 }

Modified: 
core3/webservice-biomart-client/trunk/src/main/java/org/cytoscape/io/webservice/biomart/task/ImportTableTask.java
===================================================================
--- 
core3/webservice-biomart-client/trunk/src/main/java/org/cytoscape/io/webservice/biomart/task/ImportTableTask.java
   2011-01-26 00:01:44 UTC (rev 23620)
+++ 
core3/webservice-biomart-client/trunk/src/main/java/org/cytoscape/io/webservice/biomart/task/ImportTableTask.java
   2011-01-26 00:45:16 UTC (rev 23621)
@@ -1,13 +1,15 @@
 package org.cytoscape.io.webservice.biomart.task;
 
+import java.awt.Window;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 
+import javax.swing.JOptionPane;
+
 import org.cytoscape.io.webservice.biomart.BiomartQuery;
 import org.cytoscape.io.webservice.biomart.rest.BiomartRestClient;
 import org.cytoscape.model.CyNetworkManager;
@@ -22,34 +24,35 @@
 
 /**
  * Task to import actual data tables from BioMart service.
- *
+ * 
  */
 public class ImportTableTask extends AbstractTask {
 
        private final BiomartRestClient client;
        private final BiomartQuery query;
-       
+
        private final CyTableFactory tableFactory;
 
        private Set<CyTable> tables;
-       
+
        private final CyNetworkManager networkManager;
        private final CyApplicationManager applicationManager;
 
-       
-       
+       private final Window parent;
+
        public ImportTableTask(final BiomartRestClient client,
-                       final BiomartQuery query, final CyTableFactory 
tableFactory, 
+                       final BiomartQuery query, final CyTableFactory 
tableFactory,
                        final CyNetworkManager networkManager,
-                       final CyApplicationManager applicationManager) {
-               
+                       final CyApplicationManager applicationManager, final 
Window parent) {
+
                this.client = client;
                this.query = query;
                this.tableFactory = tableFactory;
-               
+               this.parent = parent;
+
                this.networkManager = networkManager;
                this.applicationManager = applicationManager;
-               
+
                this.tables = new HashSet<CyTable>();
        }
 
@@ -58,39 +61,42 @@
                if (query == null)
                        throw new NullPointerException("Query is null");
 
+               taskMonitor.setProgress(0.0);
+               taskMonitor.setTitle("Loading data table from BioMart...");
+               taskMonitor.setStatusMessage("Loading data...");
+
                final BufferedReader result = 
client.sendQuery(query.getQueryString());
 
                if (result.ready() == false)
                        throw new IOException("Could not get result.");
 
-               final CyTable newTable = mapping(result, 
query.getKeyColumnName());
                
+               taskMonitor.setStatusMessage("Creating global table...");
+               final CyTable newTable = createGlobalTable(result,
+                               query.getKeyColumnName());
+
                tables.add(newTable);
-               
+
                final MapNetworkAttrTask localMappingTask = new 
MapNetworkAttrTask(
-                               CyNode.class, newTable,
-                               networkManager, applicationManager);
-               
-               this.insertTasksAfterCurrentTask(localMappingTask);
+                               CyNode.class, newTable, networkManager, 
applicationManager);
+               final ShowResultTask messageTask = new ShowResultTask();
+               this.insertTasksAfterCurrentTask(localMappingTask, messageTask);
        }
 
-       private CyTable mapping(BufferedReader reader, String key)
+       private CyTable createGlobalTable(BufferedReader reader, String key)
                        throws IOException {
 
-               
-               System.out.println("Key name = " + key);
-               final CyTable globalTable = 
tableFactory.createTable(query.getTableName(), key,
-                               String.class, true);
-               
-
                // Read result from reader
                String line = reader.readLine();
                System.out.println("Table Header: " + line);
                final String[] columnNames = line.split("\\t");
 
                if (columnNames[0].contains("Query ERROR"))
-                       throw new IOException("Biomart service returns Querry 
ERROR.  ");
+                       throw new IOException("BioMart service returns error: 
\n" + line);
 
+               final CyTable globalTable = tableFactory.createTable(
+                               query.getTableName(), key, String.class, true);
+
                // For status report
                int recordCount = 0;
                List<String> report = new ArrayList<String>();
@@ -106,7 +112,6 @@
                        if (columnNames[i].equals(key))
                                keyIdx = i;
                }
-       
 
                String[] row;
                String val;
@@ -140,77 +145,96 @@
 
                                if ((val != null) && (val.length() != 0)) {
 
-                                       if(j == keyIdx) {
+                                       if (j == keyIdx) {
                                                cyRow.set(key, val);
                                        }
                                        cyRow.set(columnNames[j], val);
-//                                     if (keyAttrName.equals("ID")) {
-//                                             testList = attr
-//                                                             
.getListAttribute(keyVal, columnNames[j]);
-//
-//                                             if (testList != null)
-//                                                     
listOfValList.add(testList);
-//                                     } else {
-//                                             ids = 
getIdFromAttrValue(attrDataType, keyAttrName,
-//                                                             keyVal, 
nodeIdList, attr);
-//
-//                                             if (ids.size() == 0)
-//                                                     continue;
-//
-//                                             for (String id : ids)
-//                                                     
listOfValList.add(attr.getListAttribute(id,
-//                                                                     
columnNames[j]));
-//                                     }
-//
-//                                     if (listOfValList.size() == 0) {
-//                                             List<Object> valList = new 
ArrayList<Object>();
-//                                             listOfValList.add(valList);
-//                                     }
-//
-//                                     int index = 0;
-//                                     for (List<Object> valList : 
listOfValList) {
-//                                             if (valList == null)
-//                                                     valList = new 
ArrayList<Object>();
-//
-//                                             if (valList.contains(row[j]) == 
false)
-//                                                     valList.add(row[j]);
-//
-//                                             if (keyAttrName.equals("ID")) {
-//                                                     
attr.setListAttribute(keyVal, columnNames[j],
-//                                                                     
valList);
-//                                                     
attr.setAttribute(keyVal, columnNames[j] + "-TOP",
-//                                                                     
valList.get(0).toString());
-//                                             } else {
-//                                                     
attr.setListAttribute(ids.get(index),
-//                                                                     
columnNames[j], valList);
-//                                                     
attr.setAttribute(ids.get(index), columnNames[j]
-//                                                                     + 
"-TOP", valList.get(0).toString());
-//
-//                                             }
-//                                             hitCount++;
-//                                             index++;
-//                                     }
+                                       // if (keyAttrName.equals("ID")) {
+                                       // testList = attr
+                                       // .getListAttribute(keyVal, 
columnNames[j]);
+                                       //
+                                       // if (testList != null)
+                                       // listOfValList.add(testList);
+                                       // } else {
+                                       // ids = 
getIdFromAttrValue(attrDataType, keyAttrName,
+                                       // keyVal, nodeIdList, attr);
+                                       //
+                                       // if (ids.size() == 0)
+                                       // continue;
+                                       //
+                                       // for (String id : ids)
+                                       // 
listOfValList.add(attr.getListAttribute(id,
+                                       // columnNames[j]));
+                                       // }
+                                       //
+                                       // if (listOfValList.size() == 0) {
+                                       // List<Object> valList = new 
ArrayList<Object>();
+                                       // listOfValList.add(valList);
+                                       // }
+                                       //
+                                       // int index = 0;
+                                       // for (List<Object> valList : 
listOfValList) {
+                                       // if (valList == null)
+                                       // valList = new ArrayList<Object>();
+                                       //
+                                       // if (valList.contains(row[j]) == 
false)
+                                       // valList.add(row[j]);
+                                       //
+                                       // if (keyAttrName.equals("ID")) {
+                                       // attr.setListAttribute(keyVal, 
columnNames[j],
+                                       // valList);
+                                       // attr.setAttribute(keyVal, 
columnNames[j] + "-TOP",
+                                       // valList.get(0).toString());
+                                       // } else {
+                                       // attr.setListAttribute(ids.get(index),
+                                       // columnNames[j], valList);
+                                       // attr.setAttribute(ids.get(index), 
columnNames[j]
+                                       // + "-TOP", valList.get(0).toString());
+                                       //
+                                       // }
+                                       // hitCount++;
+                                       // index++;
+                                       // }
                                }
                        }
                }
 
                reader.close();
                reader = null;
-               
+
                // Dump table
-//             final List<CyRow> rows = globalTable.getAllRows();
-//             for(CyRow r: rows) {
-//                     Map<String, Object> rowVals = r.getAllValues();
-//                     for(String k :rowVals.keySet()) {
-//                             System.out.print(k + ":" + rowVals.get(k) + " 
");
-//                     }
-//                     System.out.println();
-//             }
-               
+               // final List<CyRow> rows = globalTable.getAllRows();
+               // for(CyRow r: rows) {
+               // Map<String, Object> rowVals = r.getAllValues();
+               // for(String k :rowVals.keySet()) {
+               // System.out.print(k + ":" + rowVals.get(k) + " ");
+               // }
+               // System.out.println();
+               // }
+
                return globalTable;
        }
 
        public Set<CyTable> getCyTables() {
                return tables;
        }
+
+       
+       // Show result.
+       private final class ShowResultTask extends AbstractTask {
+
+               @Override
+               public void run(TaskMonitor taskMonitor) throws Exception {
+                       final CyTable table = tables.iterator().next();
+                       if (table != null) {
+                               JOptionPane.showMessageDialog(parent,
+                                               "New table loaded.\n" + 
table.getTitle() + " contains "
+                                                               + 
table.getRowCount() + " rows.",
+                                               "Table Loaded from BioMart",
+                                               
JOptionPane.INFORMATION_MESSAGE);
+                       }
+               }
+
+       }
+
 }

Modified: 
core3/webservice-biomart-client/trunk/src/main/java/org/cytoscape/io/webservice/biomart/task/ShowBiomartDialogTask.java
===================================================================
--- 
core3/webservice-biomart-client/trunk/src/main/java/org/cytoscape/io/webservice/biomart/task/ShowBiomartDialogTask.java
     2011-01-26 00:01:44 UTC (rev 23620)
+++ 
core3/webservice-biomart-client/trunk/src/main/java/org/cytoscape/io/webservice/biomart/task/ShowBiomartDialogTask.java
     2011-01-26 00:45:16 UTC (rev 23621)
@@ -4,12 +4,8 @@
 import org.cytoscape.io.webservice.biomart.BiomartClient;
 import org.cytoscape.io.webservice.biomart.ui.BiomartAttrMappingPanel;
 import org.cytoscape.io.webservice.biomart.ui.BiomartMainDialog;
-import org.cytoscape.model.CyTableManager;
-import org.cytoscape.session.CyApplicationManager;
 import org.cytoscape.work.AbstractTask;
-import org.cytoscape.work.TaskManager;
 import org.cytoscape.work.TaskMonitor;
-import org.cytoscape.work.swing.GUITaskManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 

Modified: 
core3/webservice-biomart-client/trunk/src/main/java/org/cytoscape/io/webservice/biomart/task/ShowBiomartGUIAction.java
===================================================================
--- 
core3/webservice-biomart-client/trunk/src/main/java/org/cytoscape/io/webservice/biomart/task/ShowBiomartGUIAction.java
      2011-01-26 00:01:44 UTC (rev 23620)
+++ 
core3/webservice-biomart-client/trunk/src/main/java/org/cytoscape/io/webservice/biomart/task/ShowBiomartGUIAction.java
      2011-01-26 00:45:16 UTC (rev 23621)
@@ -2,10 +2,13 @@
 
 import java.awt.event.ActionEvent;
 
+import javax.swing.JOptionPane;
+
 import org.cytoscape.application.swing.AbstractCyAction;
 import org.cytoscape.application.swing.CySwingApplication;
 import org.cytoscape.io.webservice.biomart.BiomartClient;
 import org.cytoscape.io.webservice.biomart.ui.BiomartAttrMappingPanel;
+import org.cytoscape.model.CyNetwork;
 import org.cytoscape.session.CyApplicationManager;
 import org.cytoscape.work.TaskManager;
 import org.cytoscape.work.swing.GUITaskManager;
@@ -26,6 +29,7 @@
        private final CySwingApplication app;
        
        private ShowBiomartDialogTask showDialogTask;
+       private final CyApplicationManager appManager;
        
        private final LoadRepositoryTask firstTask;
 
@@ -36,6 +40,7 @@
                super("from Biomart...", appManager);
                setPreferredMenu("File.Import.Table.WebService");
 
+               this.appManager = appManager;
                this.app = app;
                this.taskManager = (GUITaskManager) taskManager;
                
@@ -45,6 +50,14 @@
 
        @Override
        public void actionPerformed(ActionEvent ae) {
+               // State check: BioMart client needs at least a network to 
create query string.
+               final CyNetwork net = appManager.getCurrentNetwork();
+               if(net == null) {
+                       JOptionPane.showMessageDialog(app.getJFrame(), "BioMart 
Client needs at least one network to create query.  Please import a network 
first.",
+                                       "No Network Found", 
JOptionPane.INFORMATION_MESSAGE);
+                       return;
+               }
+               
                // Lazy instantiation. This process depends on network 
connection.
                if (showDialogTask.getDialog() == null) {                       
                        initDialog();

Modified: 
core3/webservice-biomart-client/trunk/src/main/java/org/cytoscape/io/webservice/biomart/ui/AttributeImportPanel.java
===================================================================
--- 
core3/webservice-biomart-client/trunk/src/main/java/org/cytoscape/io/webservice/biomart/ui/AttributeImportPanel.java
        2011-01-26 00:01:44 UTC (rev 23620)
+++ 
core3/webservice-biomart-client/trunk/src/main/java/org/cytoscape/io/webservice/biomart/ui/AttributeImportPanel.java
        2011-01-26 00:45:16 UTC (rev 23621)
@@ -73,7 +73,7 @@
 
        private static final long serialVersionUID = 8665197023334496167L;
        
-       protected static final String TABLE_PREFIX = "BioMart Table ";
+       protected static final String TABLE_PREFIX = "BioMart Global Table ";
 
        /**
         * Will be caught by parent object (usually a dialog.)

Modified: 
core3/webservice-biomart-client/trunk/src/main/java/org/cytoscape/io/webservice/biomart/ui/BiomartAttrMappingPanel.java
===================================================================
--- 
core3/webservice-biomart-client/trunk/src/main/java/org/cytoscape/io/webservice/biomart/ui/BiomartAttrMappingPanel.java
     2011-01-26 00:01:44 UTC (rev 23620)
+++ 
core3/webservice-biomart-client/trunk/src/main/java/org/cytoscape/io/webservice/biomart/ui/BiomartAttrMappingPanel.java
     2011-01-26 00:45:16 UTC (rev 23621)
@@ -321,6 +321,7 @@
 
        @Override
        protected void importAttributes() {
+               taskManager.setParent(parent);
                taskManager.execute(client);
        }
 

Modified: 
core3/webservice-biomart-client/trunk/src/main/resources/META-INF/spring/bundle-context.xml
===================================================================
--- 
core3/webservice-biomart-client/trunk/src/main/resources/META-INF/spring/bundle-context.xml
 2011-01-26 00:01:44 UTC (rev 23620)
+++ 
core3/webservice-biomart-client/trunk/src/main/resources/META-INF/spring/bundle-context.xml
 2011-01-26 00:45:16 UTC (rev 23621)
@@ -33,6 +33,7 @@
                <constructor-arg ref="cyTableFactoryServiceRef" />
                <constructor-arg ref="cyNetworkManagerServiceRef" />
                <constructor-arg ref="cyApplicationManagerServiceRef" />
+               <constructor-arg ref="cySwingApplicationServiceRef" />
        </bean>
 
        <bean id="biomartAttrMappingPanel"

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