Author: kono
Date: 2012-07-05 15:18:01 -0700 (Thu, 05 Jul 2012)
New Revision: 29775

Removed:
   
core3/impl/trunk/webservice-biomart-client-impl/src/main/java/org/cytoscape/io/webservice/biomart/task/ShowBiomartGUIAction.java
Modified:
   
core3/impl/trunk/webservice-biomart-client-impl/src/main/java/org/cytoscape/io/webservice/biomart/task/LoadRepositoryTask.java
   
core3/impl/trunk/webservice-biomart-client-impl/src/main/java/org/cytoscape/io/webservice/biomart/task/ShowBiomartDialogTask.java
   
core3/impl/trunk/webservice-biomart-client-impl/src/main/java/org/cytoscape/io/webservice/biomart/ui/AttributeImportPanel.java
   
core3/impl/trunk/webservice-biomart-client-impl/src/main/java/org/cytoscape/io/webservice/biomart/ui/BiomartAttrMappingPanel.java
Log:
fixed #967 Datasource can be selected before initialization to avoid very long 
initialization time.

Modified: 
core3/impl/trunk/webservice-biomart-client-impl/src/main/java/org/cytoscape/io/webservice/biomart/task/LoadRepositoryTask.java
===================================================================
--- 
core3/impl/trunk/webservice-biomart-client-impl/src/main/java/org/cytoscape/io/webservice/biomart/task/LoadRepositoryTask.java
      2012-07-05 20:53:55 UTC (rev 29774)
+++ 
core3/impl/trunk/webservice-biomart-client-impl/src/main/java/org/cytoscape/io/webservice/biomart/task/LoadRepositoryTask.java
      2012-07-05 22:18:01 UTC (rev 29775)
@@ -6,12 +6,15 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.TreeSet;
 
 import javax.xml.parsers.ParserConfigurationException;
 
 import org.cytoscape.io.webservice.biomart.rest.BiomartRestClient;
 import org.cytoscape.work.AbstractTask;
 import org.cytoscape.work.TaskMonitor;
+import org.cytoscape.work.Tunable;
+import org.cytoscape.work.util.ListMultipleSelection;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.xml.sax.SAXException;
@@ -24,7 +27,7 @@
        private final BiomartRestClient client;
 
        private Map<String, Map<String, String>> reg;
-       
+       private final Map<String, String> name2DatasourceMap;
 
        private LoadRepositoryResult result;
 
@@ -41,15 +44,42 @@
 
        private Map<String, String> datasourceMap;
        private List<String> dsList;
+       
+       @Tunable(description="Please slect services you want to use")
+       public ListMultipleSelection<String> services;
 
        public LoadRepositoryTask(final BiomartRestClient client) {
                this.client = client;
+               this.name2DatasourceMap = new HashMap<String, String>();
+               try {
+                       initServiceList();
+               } catch (Exception e) {
+                       throw new IllegalStateException("Could not obtain 
registry", e);
+               }
        }
+       
+       private final void initServiceList() throws IOException, 
ParserConfigurationException, SAXException {
+               reg = client.getRegistry();
+               
+               for (String databaseName : reg.keySet()) {
 
+                       final Map<String, String> detail = 
reg.get(databaseName);
+                       if (detail.get("visible").equals("1")
+                                       && 
(databaseFilter.contains(databaseName) == false)) {
+                               String dispName = detail.get("displayName");
+                               name2DatasourceMap.put(dispName, databaseName);
+                       }
+               }
+               final TreeSet<String> sortedSet = new 
TreeSet<String>(name2DatasourceMap.keySet());
+               services = new ListMultipleSelection<String>(new 
ArrayList<String>(sortedSet));
+       }
 
+
        @Override
        public void run(TaskMonitor taskMonitor) throws IOException, 
ParserConfigurationException, SAXException {
 
+               final List<String> selected = services.getSelectedValues();
+               
                taskMonitor.setTitle("Loading list of available BioMart 
Services.  Please wait...");
                taskMonitor.setStatusMessage("Loading list of available 
Marts...");
                
@@ -58,9 +88,8 @@
 
                logger.debug("Loading Repository...");
                
-               reg = client.getRegistry();
                taskMonitor.setProgress(0.1);
-               final int registryCount = reg.size();
+               final int registryCount = selected.size();
                float increment = 0.9f / registryCount;
                float percentCompleted = 0.1f;
 
@@ -75,19 +104,22 @@
                        if (detail.get("visible").equals("1")
                                        && 
(databaseFilter.contains(databaseName) == false)) {
                                String dispName = detail.get("displayName");
-                               try {
-                                       datasources = 
client.getAvailableDatasets(databaseName);
-                               } catch (IOException e) {
-                                       // If timeout/connection error is 
found, skip the source.
-                                       percentCompleted += increment;
-                                       continue;
-                               }
+                               if (selected.contains(dispName)) {
+                                       try {
+                                               datasources = 
client.getAvailableDatasets(databaseName);
+                                       } catch (IOException e) {
+                                               // If timeout/connection error 
is found, skip the
+                                               // source.
+                                               percentCompleted += increment;
+                                               continue;
+                                       }
 
-                               for (String key : datasources.keySet()) {
-                                       final String dataSource = dispName + " 
- " + datasources.get(key);
-                                       dsList.add(dataSource);
-                                       datasourceMap.put(dataSource, key);
-                                       taskMonitor.setStatusMessage("Loading 
Data Source: " + dataSource);
+                                       for (String key : datasources.keySet()) 
{
+                                               final String dataSource = 
dispName + " - " + datasources.get(key);
+                                               dsList.add(dataSource);
+                                               datasourceMap.put(dataSource, 
key);
+                                               
taskMonitor.setStatusMessage("Loading Data Source: " + dataSource);
+                                       }
                                }
                        }
 

Modified: 
core3/impl/trunk/webservice-biomart-client-impl/src/main/java/org/cytoscape/io/webservice/biomart/task/ShowBiomartDialogTask.java
===================================================================
--- 
core3/impl/trunk/webservice-biomart-client-impl/src/main/java/org/cytoscape/io/webservice/biomart/task/ShowBiomartDialogTask.java
   2012-07-05 20:53:55 UTC (rev 29774)
+++ 
core3/impl/trunk/webservice-biomart-client-impl/src/main/java/org/cytoscape/io/webservice/biomart/task/ShowBiomartDialogTask.java
   2012-07-05 22:18:01 UTC (rev 29775)
@@ -1,42 +1,30 @@
 package org.cytoscape.io.webservice.biomart.task;
 
-import org.cytoscape.io.webservice.biomart.BiomartClient;
+import javax.swing.JDialog;
+
 import org.cytoscape.io.webservice.biomart.ui.BiomartAttrMappingPanel;
-import org.cytoscape.io.webservice.biomart.ui.BiomartMainDialog;
 import org.cytoscape.work.AbstractTask;
 import org.cytoscape.work.TaskMonitor;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class ShowBiomartDialogTask extends AbstractTask {
-       
+
        private static final Logger logger = 
LoggerFactory.getLogger(ShowBiomartDialogTask.class);
-       
-       private BiomartMainDialog dialog;
-       
-       private final BiomartClient client;
-       
+
        private final BiomartAttrMappingPanel panel;
-       
        private final LoadRepositoryTask loadTask;
-       
-       public ShowBiomartDialogTask(final BiomartAttrMappingPanel panel, final 
BiomartClient client, final LoadRepositoryTask loadTask) {
-               
+
+       public ShowBiomartDialogTask(final BiomartAttrMappingPanel panel, final 
LoadRepositoryTask loadTask) {
                this.panel = panel;
-               this.client = client;
                this.loadTask = loadTask;
        }
 
        @Override
        public void run(TaskMonitor taskMonitor) throws Exception {
-               if(dialog == null) {
-                       final LoadRepositoryResult result = 
loadTask.getResult();
-                       panel.initDataSources(result);
-                       logger.info("BioMart Client initialized.");
-               }
+               final LoadRepositoryResult result = loadTask.getResult();
+               panel.initDataSources(result);
+               logger.info("BioMart Client initialized.");
+               ((JDialog)panel.getRootPane().getParent()).toFront();
        }
-       
-       public BiomartMainDialog getDialog() {
-               return dialog;
-       }
 }

Deleted: 
core3/impl/trunk/webservice-biomart-client-impl/src/main/java/org/cytoscape/io/webservice/biomart/task/ShowBiomartGUIAction.java
===================================================================
--- 
core3/impl/trunk/webservice-biomart-client-impl/src/main/java/org/cytoscape/io/webservice/biomart/task/ShowBiomartGUIAction.java
    2012-07-05 20:53:55 UTC (rev 29774)
+++ 
core3/impl/trunk/webservice-biomart-client-impl/src/main/java/org/cytoscape/io/webservice/biomart/task/ShowBiomartGUIAction.java
    2012-07-05 22:18:01 UTC (rev 29775)
@@ -1,76 +0,0 @@
-package org.cytoscape.io.webservice.biomart.task;
-
-import java.awt.event.ActionEvent;
-
-import javax.swing.JOptionPane;
-
-import org.cytoscape.application.CyApplicationManager;
-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.work.TaskIterator;
-import org.cytoscape.work.TaskManager;
-import org.cytoscape.work.swing.DialogTaskManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * 
- * TODO: Add cancel function
- */
-public class ShowBiomartGUIAction extends AbstractCyAction {
-
-       private static final long serialVersionUID = -1329132199540543764L;
-
-       private static final Logger logger = 
LoggerFactory.getLogger(ShowBiomartGUIAction.class);
-
-       private final DialogTaskManager taskManager;
-       private final CySwingApplication app;
-       
-       private ShowBiomartDialogTask showDialogTask;
-       private final CyApplicationManager appManager;
-       
-       private final LoadRepositoryTask firstTask;
-
-       public ShowBiomartGUIAction(final BiomartAttrMappingPanel panel, final 
BiomartClient client,
-                       final TaskManager taskManager,
-                       final CyApplicationManager appManager,
-                       final CySwingApplication app) {
-               super("Biomart...");
-               setPreferredMenu("File.Import.Table.Public Databases");
-               
-               this.appManager = appManager;
-               this.app = app;
-               this.taskManager = (DialogTaskManager) taskManager;
-               
-               this.firstTask = new LoadRepositoryTask(client.getRestClient());
-               this.showDialogTask = new ShowBiomartDialogTask(panel, client, 
firstTask);
-       }
-
-       @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();
-               } else {
-                       
showDialogTask.getDialog().setLocationRelativeTo(app.getJFrame());
-                       showDialogTask.getDialog().setVisible(true);
-               }
-       }
-       
-       
-       private void initDialog() {
-               taskManager.setExecutionContext(app.getJFrame());
-               taskManager.execute(new TaskIterator(firstTask, 
showDialogTask));
-       }
-}

Modified: 
core3/impl/trunk/webservice-biomart-client-impl/src/main/java/org/cytoscape/io/webservice/biomart/ui/AttributeImportPanel.java
===================================================================
--- 
core3/impl/trunk/webservice-biomart-client-impl/src/main/java/org/cytoscape/io/webservice/biomart/ui/AttributeImportPanel.java
      2012-07-05 20:53:55 UTC (rev 29774)
+++ 
core3/impl/trunk/webservice-biomart-client-impl/src/main/java/org/cytoscape/io/webservice/biomart/ui/AttributeImportPanel.java
      2012-07-05 22:18:01 UTC (rev 29775)
@@ -100,6 +100,7 @@
        protected JButton importButton;
        protected JLabel titleLabel;
        protected JButton resetButton;
+       protected JButton refreshButton;
        protected CheckBoxJList attrCheckboxList;
 
        protected DefaultListModel attrCheckboxListModel;
@@ -148,6 +149,7 @@
                importButton = new JButton();
                cancelButton = new JButton();
                resetButton = new JButton();
+               refreshButton= new JButton();
 
                setBackground(new java.awt.Color(255, 255, 255));
                titleLabel.setBackground(new java.awt.Color(255, 255, 255));
@@ -262,13 +264,21 @@
                });
                cancelButton.setBackground(Color.white);
 
-               resetButton.setText("Reset");
+               resetButton.setText("Clear");
                resetButton.addActionListener(new 
java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent 
evt) {
                                resetButtonActionPerformed(evt);
                        }
                });
                resetButton.setBackground(Color.white);
+               
+               refreshButton.setText("Refresh");
+               refreshButton.addActionListener(new 
java.awt.event.ActionListener() {
+                       public void actionPerformed(java.awt.event.ActionEvent 
evt) {
+                               refreshButtonActionPerformed(evt);
+                       }
+               });
+               refreshButton.setBackground(Color.white);
 
                GroupLayout layout = new GroupLayout(this);
                this.setLayout(layout);
@@ -287,7 +297,7 @@
                                                                                
.addComponent(titleLabel)
                                                                                
.addGroup(
                                                                                
                layout.createSequentialGroup()
-                                                                               
                                .addComponent(resetButton)
+                                                                               
                                
.addComponent(resetButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(refreshButton)
                                                                                
                                
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 343,
                                                                                
                                                
Short.MAX_VALUE).addComponent(cancelButton)
                                                                                
                                
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
@@ -308,10 +318,11 @@
                                                
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(
                                                                
layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(importButton)
-                                                                               
.addComponent(cancelButton).addComponent(resetButton)).addContainerGap()));
+                                                                               
.addComponent(cancelButton).addComponent(resetButton).addComponent(refreshButton)).addContainerGap()));
        } // </editor-fold>
 
        protected abstract void resetButtonActionPerformed(ActionEvent evt);
+       protected abstract void refreshButtonActionPerformed(ActionEvent evt);
 
        protected void importButtonActionPerformed(ActionEvent evt) {
                importAttributes();

Modified: 
core3/impl/trunk/webservice-biomart-client-impl/src/main/java/org/cytoscape/io/webservice/biomart/ui/BiomartAttrMappingPanel.java
===================================================================
--- 
core3/impl/trunk/webservice-biomart-client-impl/src/main/java/org/cytoscape/io/webservice/biomart/ui/BiomartAttrMappingPanel.java
   2012-07-05 20:53:55 UTC (rev 29774)
+++ 
core3/impl/trunk/webservice-biomart-client-impl/src/main/java/org/cytoscape/io/webservice/biomart/ui/BiomartAttrMappingPanel.java
   2012-07-05 22:18:01 UTC (rev 29775)
@@ -44,6 +44,7 @@
 import javax.swing.DefaultListModel;
 import javax.swing.Icon;
 import javax.swing.ImageIcon;
+import javax.swing.JComboBox;
 import javax.swing.event.AncestorEvent;
 import javax.swing.event.AncestorListener;
 
@@ -130,7 +131,7 @@
 
        private void initPanel() {
                LoadRepositoryTask firstTask = new 
LoadRepositoryTask(client.getRestClient());
-               ShowBiomartDialogTask showDialogTask = new 
ShowBiomartDialogTask(this, client, firstTask);
+               ShowBiomartDialogTask showDialogTask = new 
ShowBiomartDialogTask(this, firstTask);
 
                taskManager.setExecutionContext(null);
                taskManager.execute(new TaskIterator(firstTask, 
showDialogTask));
@@ -148,16 +149,21 @@
        }
 
        public void setMartServiceList(LoadRepositoryResult res) {
+               databaseComboBox.removeAllItems();
+               
                this.datasourceMap = res.getDatasourceMap();
                final List<String> dsList = res.getSortedDataSourceList();
                for (String ds : dsList)
-                       this.databaseComboBox.addItem(ds);
+                       this.databaseComboBox.addItem(ds);              
        }
 
        public void loadFilter() {
+               Object selected = databaseComboBox.getSelectedItem();
+               if(selected == null)
+                       return;
+               
                attributeTypeComboBox.removeAllItems();
-
-               final String selectedDB = 
databaseComboBox.getSelectedItem().toString();
+               final String selectedDB = selected.toString();
                final String selectedDBName = datasourceMap.get(selectedDB);
 
                fetchData(selectedDBName, SourceType.FILTER);
@@ -172,8 +178,12 @@
                loadFilter();
        }
 
-       private void updateAttributeList() {            
-               final String selectedDB = 
databaseComboBox.getSelectedItem().toString();
+       private void updateAttributeList() {
+               Object selected = databaseComboBox.getSelectedItem();
+               if(selected == null)
+                       return;
+               
+               final String selectedDB = selected.toString();
                final String selectedDBName = datasourceMap.get(selectedDB);
 
                List<String> order = attributeListOrder.get(selectedDBName);
@@ -415,4 +425,9 @@
 
        }
 
+       @Override
+       protected void refreshButtonActionPerformed(ActionEvent evt) {
+               initPanel();
+       }
+
 }

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