Author: kono
Date: 2012-06-04 12:25:06 -0700 (Mon, 04 Jun 2012)
New Revision: 29441
Added:
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/mapper/MergedNetworkBuilder.java
Removed:
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/mapper/ClusteredNetworkBuilder.java
Modified:
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/CyActivator.java
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/PSICQUICRestClient.java
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/RegistryManager.java
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/mapper/Mitab25Mapper.java
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/task/ImportNetworkFromPSICQUICTask.java
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/task/SearchRecoredsTask.java
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/ui/PSICQUICSearchUI.java
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/ui/SourceStatusPanel.java
core3/impl/trunk/webservice-psicquic-client-impl/src/test/java/org/cytoscape/webservice/psicquic/PSICQUICClientTest.java
core3/impl/trunk/webservice-psicquic-client-impl/src/test/java/org/cytoscape/webservice/psicquic/RegistryClientTest.java
core3/impl/trunk/webservice-psicquic-client-impl/src/test/java/org/cytoscape/webservice/psicquic/RestClientTest.java
Log:
Merge result function implemented.
Modified:
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/CyActivator.java
===================================================================
---
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/CyActivator.java
2012-06-04 19:03:10 UTC (rev 29440)
+++
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/CyActivator.java
2012-06-04 19:25:06 UTC (rev 29441)
@@ -5,7 +5,6 @@
import org.cytoscape.model.CyNetworkFactory;
import org.cytoscape.model.CyNetworkManager;
import org.cytoscape.service.util.AbstractCyActivator;
-import org.cytoscape.task.NetworkTaskFactory;
import org.cytoscape.task.create.CreateNetworkViewTaskFactory;
import org.cytoscape.util.swing.OpenBrowser;
import org.cytoscape.work.swing.DialogTaskManager;
Modified:
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/PSICQUICRestClient.java
===================================================================
---
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/PSICQUICRestClient.java
2012-06-04 19:03:10 UTC (rev 29440)
+++
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/PSICQUICRestClient.java
2012-06-04 19:25:06 UTC (rev 29441)
@@ -23,10 +23,11 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNetworkFactory;
-import org.cytoscape.webservice.psicquic.mapper.ClusteredNetworkBuilder;
+import org.cytoscape.webservice.psicquic.mapper.MergedNetworkBuilder;
import org.cytoscape.webservice.psicquic.mapper.CyNetworkBuilder;
import org.cytoscape.webservice.psicquic.simpleclient.PSICQUICSimpleClient;
import org.cytoscape.work.TaskMonitor;
@@ -41,11 +42,12 @@
* Light-weight REST client based on SimpleClient by EBI team.
*
*/
-public class PSICQUICRestClient {
+public final class PSICQUICRestClient {
+
private static final Logger logger =
LoggerFactory.getLogger(PSICQUICRestClient.class);
- // Static list of ID.
- private static final String allMappingNames =
"flybase,mgd/mgi,sgd,entrez
gene/locuslink,uniprotkb,intact,ddbj/embl/genbank,chebi,irefindex,hgnc,ensembl";
+ // Static list of ID. The oreder is important!
+ private static final String MAPPING_NAMES =
"uniprotkb,chebi,ddbj/embl/genbank,ensembl,irefindex";
public enum SearchMode {
MIQL("Search by Query (MIQL)"), INTERACTOR("Search by
gene/protein ID list");
@@ -62,10 +64,12 @@
}
}
- private static final Long ERROR_CODE = -1l;
+ public static final Long ERROR_SEARCH_FAILED = -1l;
+ public static final Long ERROR_TIMEOUT = -2l;
+ public static final Long ERROR_CANCEL = -3l;
// Timeout for search
- private static final long SEARCH_TIMEOUT = 20000;
+ private static final long SEARCH_TIMEOUT = 5000;
private static final long IMPORT_TIMEOUT = 1000;
private final CyNetworkFactory factory;
@@ -260,10 +264,10 @@
InteractionCluster iC = new InteractionCluster();
iC.setBinaryInteractionIterator(binaryInteractions.iterator());
- iC.setMappingIdDbNames(allMappingNames);
+ iC.setMappingIdDbNames(MAPPING_NAMES);
iC.runService();
- ClusteredNetworkBuilder builder = new
ClusteredNetworkBuilder(factory);
+ MergedNetworkBuilder builder = new
MergedNetworkBuilder(factory);
return builder.buildNetwork(iC);
}
@@ -299,15 +303,20 @@
final SearchTask task = taskItr.next();
final String source = task.getURL();
try {
- resultMap.put(source, future.get());
+ resultMap.put(source,
future.get(SEARCH_TIMEOUT, TimeUnit.MILLISECONDS));
logger.debug(source + " : Got response
= " + resultMap.get(source));
} catch (ExecutionException e) {
logger.warn("Error occured in search: "
+ source, e);
- resultMap.put(source, ERROR_CODE);
+ resultMap.put(source,
ERROR_SEARCH_FAILED);
continue;
} catch (CancellationException ce) {
- logger.warn("Operation timeout for " +
source, ce);
+ resultMap.put(source, ERROR_CANCEL);
+ logger.warn("Operation canceled for " +
source, ce);
continue;
+ } catch (TimeoutException te) {
+ resultMap.put(source, ERROR_TIMEOUT);
+ logger.warn("Operation timeout for " +
source, te);
+ continue;
}
completed += increment;
tm.setProgress(completed);
Modified:
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/RegistryManager.java
===================================================================
---
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/RegistryManager.java
2012-06-04 19:03:10 UTC (rev 29440)
+++
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/RegistryManager.java
2012-06-04 19:25:06 UTC (rev 29441)
@@ -197,7 +197,6 @@
tagList.add(item.getFirstChild().getNodeValue());
tagMap.put(serviceName, tagList);
}
-
walk(n, serviceName);
}
Deleted:
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/mapper/ClusteredNetworkBuilder.java
===================================================================
---
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/mapper/ClusteredNetworkBuilder.java
2012-06-04 19:03:10 UTC (rev 29440)
+++
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/mapper/ClusteredNetworkBuilder.java
2012-06-04 19:25:06 UTC (rev 29441)
@@ -1,80 +0,0 @@
-package org.cytoscape.webservice.psicquic.mapper;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.cytoscape.model.CyNetwork;
-import org.cytoscape.model.CyNetworkFactory;
-import org.cytoscape.model.CyNode;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import uk.ac.ebi.enfin.mi.cluster.EncoreInteraction;
-import uk.ac.ebi.enfin.mi.cluster.InteractionCluster;
-
-
-// TODO Make this smarter
-public class ClusteredNetworkBuilder {
-
- private static final Logger logger =
LoggerFactory.getLogger(ClusteredNetworkBuilder.class);
-
- final String fisrtSeparator = "\t";
- final String secondSeparator = ",";
-
- private final CyNetworkFactory networkFactory;
-
- volatile boolean cancel = false;
-
- private Map<String, CyNode> nodeMap;
-
- public ClusteredNetworkBuilder(final CyNetworkFactory networkFactory) {
- this.networkFactory = networkFactory;
-
- }
-
- public CyNetwork buildNetwork(final InteractionCluster iC) throws
IOException {
- CyNetwork network = networkFactory.createNetwork();
-
- nodeMap = new HashMap<String, CyNode>();
- Map<Integer, EncoreInteraction> interactions =
iC.getInteractionMapping();
- Map<String, List<Integer>> interactorMapping =
iC.getInteractorMapping();
- Map<String, String> interactorSynonyms = iC.getSynonymMapping();
-
- for (Integer interactionKey : interactions.keySet()) {
- if (cancel) {
- logger.warn("Network bulilder interrupted.");
- network = null;
- return null;
- }
-
-
- EncoreInteraction val =
interactions.get(interactionKey);
-
- String source = val.getInteractorA();
- CyNode sourceNode = nodeMap.get(source);
- if (sourceNode == null) {
- sourceNode = network.addNode();
- network.getRow(sourceNode).set(CyNetwork.NAME,
source);
- nodeMap.put(source, sourceNode);
- }
- String target = val.getInteractorB();
- CyNode targetNode = nodeMap.get(target);
- if (targetNode == null) {
- targetNode = network.addNode();
- network.getRow(targetNode).set(CyNetwork.NAME,
target);
- nodeMap.put(target, targetNode);
- }
-
- network.addEdge(sourceNode, targetNode, true);
- }
-
- logger.info("Import Done: " + network.getSUID());
- return network;
- }
-
- public void cancel() {
- this.cancel = true;
- }
-}
Copied:
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/mapper/MergedNetworkBuilder.java
(from rev 29388,
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/mapper/ClusteredNetworkBuilder.java)
===================================================================
---
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/mapper/MergedNetworkBuilder.java
(rev 0)
+++
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/mapper/MergedNetworkBuilder.java
2012-06-04 19:25:06 UTC (rev 29441)
@@ -0,0 +1,165 @@
+package org.cytoscape.webservice.psicquic.mapper;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyNetworkFactory;
+import org.cytoscape.model.CyNode;
+import org.cytoscape.model.CyRow;
+import org.cytoscape.model.CyTable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import psidev.psi.mi.tab.model.CrossReference;
+import uk.ac.ebi.enfin.mi.cluster.EncoreInteraction;
+import uk.ac.ebi.enfin.mi.cluster.InteractionCluster;
+
+// TODO Make this smarter
+public class MergedNetworkBuilder {
+
+ private static final Logger logger =
LoggerFactory.getLogger(MergedNetworkBuilder.class);
+
+ // TODO create utility to provide default set of column names from
+ // identifiers.org
+
+ private static final String TAXNOMY = "taxonomy";
+ private static final String TAXNOMY_NAME = "taxonomy.name";
+ private static final String TAXNOMY_DB = "taxonomy.db";
+
+ final String fisrtSeparator = "\t";
+ final String secondSeparator = ",";
+
+ private final CyNetworkFactory networkFactory;
+
+ volatile boolean cancel = false;
+
+ private Map<String, CyNode> nodeMap;
+
+ public MergedNetworkBuilder(final CyNetworkFactory networkFactory) {
+ this.networkFactory = networkFactory;
+
+ }
+
+ public CyNetwork buildNetwork(final InteractionCluster iC) throws
IOException {
+ CyNetwork network = networkFactory.createNetwork();
+
+ nodeMap = new HashMap<String, CyNode>();
+ Map<Integer, EncoreInteraction> interactions =
iC.getInteractionMapping();
+ Map<String, List<Integer>> interactorMapping =
iC.getInteractorMapping();
+ Map<String, String> interactorSynonyms = iC.getSynonymMapping();
+
+ prepareColumns(network);
+
+ for (final Integer interactionKey : interactions.keySet()) {
+ if (cancel) {
+ logger.warn("Network bulilder interrupted.");
+ network = null;
+ return null;
+ }
+
+ final EncoreInteraction interaction =
interactions.get(interactionKey);
+
+ final String source = interaction.getInteractorA();
+ CyNode sourceNode = nodeMap.get(source);
+ if (sourceNode == null) {
+ sourceNode = network.addNode();
+ network.getRow(sourceNode).set(CyNetwork.NAME,
source);
+ nodeMap.put(source, sourceNode);
+ }
+ final String target = interaction.getInteractorB();
+ CyNode targetNode = nodeMap.get(target);
+ if (targetNode == null) {
+ targetNode = network.addNode();
+ network.getRow(targetNode).set(CyNetwork.NAME,
target);
+ nodeMap.put(target, targetNode);
+ }
+
+ mapNodeAnnotations(interaction, network, sourceNode,
targetNode);
+
+ network.addEdge(sourceNode, targetNode, true);
+ }
+
+ logger.info("Import Done: " + network.getSUID());
+ return network;
+ }
+
+ private final void prepareColumns(CyNetwork network) {
+ final CyTable nodeTable = network.getDefaultNodeTable();
+ final CyTable edgeTable = network.getDefaultEdgeTable();
+ if (nodeTable.getColumn(TAXNOMY) == null)
+ nodeTable.createColumn(TAXNOMY, String.class, false);
+ if (nodeTable.getColumn(TAXNOMY_NAME) == null)
+ nodeTable.createColumn(TAXNOMY_NAME, String.class,
false);
+ if (nodeTable.getColumn(TAXNOMY_DB) == null)
+ nodeTable.createColumn(TAXNOMY_DB, String.class, false);
+ }
+
+ private void mapNodeAnnotations(final EncoreInteraction interaction,
CyNetwork network, CyNode source, CyNode target) {
+ final CyRow sourceRow = network.getRow(source);
+ final CyRow targetRow = network.getRow(target);
+
+ final Map<String, String> accsSource =
interaction.getInteractorAccsA();
+ final Map<String, String> accsTarget =
interaction.getInteractorAccsB();
+ processNames(sourceRow, accsSource);
+ processNames(targetRow, accsTarget);
+
+ final Map<String, List<String>> otherSource =
interaction.getOtherInteractorAccsA();
+ final Map<String, List<String>> otherTarget =
interaction.getOtherInteractorAccsB();
+// processOtherNames(sourceRow, otherSource);
+// processOtherNames(targetRow, otherTarget);
+
+ final Collection<CrossReference> speciesSource =
interaction.getOrganismsA();
+ final Collection<CrossReference> speciesTarget =
interaction.getOrganismsB();
+
+// CrossReference speciesSourceFirst =
speciesSource.iterator().next();
+// CrossReference speciesTargetFirst =
speciesTarget.iterator().next();
+// processSpecies(sourceRow, speciesSourceFirst);
+// processSpecies(targetRow, speciesTargetFirst);
+ }
+
+ private void processNames(CyRow row, final Map<String, String> accs) {
+ for (String dbName : accs.keySet()) {
+ if (row.getTable().getColumn(dbName) == null)
+ row.getTable().createColumn(dbName,
String.class, true);
+ row.set(dbName, accs.get(dbName));
+ }
+
+ }
+
+ private void processOtherNames(CyRow row, final Map<String,
List<String>> accs) {
+ for (String dbName : accs.keySet()) {
+ if (row.getTable().getColumn(dbName) == null)
+ row.getTable().createColumn("other." + dbName,
String.class, true);
+
+ final List<String> names = accs.get(dbName);
+ StringBuilder builder = new StringBuilder();
+ for(String name: names) {
+ builder.append(name + ",");
+ }
+ String longName = builder.toString();
+ longName = longName.substring(0, longName.length()-2);
+ row.set(dbName, longName);
+
+ }
+ }
+
+ private void processSpecies(CyRow row, CrossReference ref) {
+ if (ref != null) {
+ final String name = ref.getText();
+ final String speciesID = ref.getIdentifier();
+ final String db = ref.getDatabase();
+
+ row.set(TAXNOMY, speciesID);
+ row.set(TAXNOMY_NAME, name);
+ row.set(TAXNOMY_DB, db);
+ }
+ }
+
+ public void cancel() {
+ this.cancel = true;
+ }
+}
Property changes on:
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/mapper/MergedNetworkBuilder.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/mapper/Mitab25Mapper.java
===================================================================
---
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/mapper/Mitab25Mapper.java
2012-06-04 19:03:10 UTC (rev 29440)
+++
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/mapper/Mitab25Mapper.java
2012-06-04 19:25:06 UTC (rev 29441)
@@ -9,7 +9,6 @@
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNode;
import org.cytoscape.model.CyRow;
-import org.cytoscape.model.CyIdentifiable;
/**
* Map minimal set of information from MITAB25.
Modified:
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/task/ImportNetworkFromPSICQUICTask.java
===================================================================
---
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/task/ImportNetworkFromPSICQUICTask.java
2012-06-04 19:03:10 UTC (rev 29440)
+++
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/task/ImportNetworkFromPSICQUICTask.java
2012-06-04 19:25:06 UTC (rev 29441)
@@ -92,6 +92,7 @@
if (targetServices == null)
throw new NullPointerException("Target service set is
null");
+ // Switch task type based on the user option.
if(toCluster) {
final CyNetwork network =
client.importClusteredNetwork(query, targetServices, mode, taskMonitor);
result = new HashMap<String, CyNetwork>();
@@ -105,7 +106,6 @@
return;
}
-
final Date date = new Date();
final SimpleDateFormat timestamp = new
SimpleDateFormat("yyyy/MM/dd K:mm:ss a, z");
final String suffix = "(" + timestamp.format(date) + ")";
Modified:
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/task/SearchRecoredsTask.java
===================================================================
---
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/task/SearchRecoredsTask.java
2012-06-04 19:03:10 UTC (rev 29440)
+++
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/task/SearchRecoredsTask.java
2012-06-04 19:25:06 UTC (rev 29441)
@@ -3,8 +3,6 @@
import java.util.Collection;
import java.util.Map;
-import javax.swing.JOptionPane;
-
import org.cytoscape.webservice.psicquic.PSICQUICRestClient;
import org.cytoscape.webservice.psicquic.PSICQUICRestClient.SearchMode;
import org.cytoscape.work.AbstractTask;
Modified:
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/ui/PSICQUICSearchUI.java
===================================================================
---
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/ui/PSICQUICSearchUI.java
2012-06-04 19:03:10 UTC (rev 29440)
+++
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/ui/PSICQUICSearchUI.java
2012-06-04 19:25:06 UTC (rev 29441)
@@ -26,7 +26,6 @@
import javax.swing.event.ChangeListener;
import org.cytoscape.model.CyNetworkManager;
-import org.cytoscape.task.NetworkTaskFactory;
import org.cytoscape.task.create.CreateNetworkViewTaskFactory;
import org.cytoscape.util.swing.OpenBrowser;
import org.cytoscape.webservice.psicquic.PSICQUICRestClient;
@@ -109,6 +108,7 @@
searchPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
searchPanel.setLayout(new BoxLayout(searchPanel,
BoxLayout.X_AXIS));
searchButton = new JButton("Search");
+ searchButton.setFont(new Font("SansSerif", Font.BOLD, 12));
searchButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@@ -186,6 +186,7 @@
queryBuilderPanel.add(helpButton);
final JPanel basePanel = new JPanel();
+ basePanel.setBackground(Color.WHITE);
basePanel.setLayout(new BoxLayout(basePanel, BoxLayout.Y_AXIS));
basePanel.add(queryBuilderPanel);
basePanel.add(searchPanel);
@@ -266,11 +267,14 @@
statesPanel = new
SourceStatusPanel(queryArea.getText(), client, regManager, networkManager,
result,
taskManager, mode,
createViewTaskFactory);
add(statesPanel, BorderLayout.SOUTH);
+
+ statesPanel.sort();
Window parentWindow = ((Window)
getRootPane().getParent());
parentWindow.pack();
repaint();
+
parentWindow.toFront();
}
}
Modified:
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/ui/SourceStatusPanel.java
===================================================================
---
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/ui/SourceStatusPanel.java
2012-06-04 19:03:10 UTC (rev 29440)
+++
core3/impl/trunk/webservice-psicquic-client-impl/src/main/java/org/cytoscape/webservice/psicquic/ui/SourceStatusPanel.java
2012-06-04 19:25:06 UTC (rev 29441)
@@ -2,19 +2,25 @@
import java.awt.Color;
import java.awt.Component;
+import java.awt.Font;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.swing.DefaultRowSorter;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.LayoutStyle;
+import javax.swing.RowSorter;
+import javax.swing.SortOrder;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
@@ -28,6 +34,7 @@
import org.cytoscape.webservice.psicquic.task.ImportNetworkFromPSICQUICTask;
import org.cytoscape.work.TaskIterator;
import org.cytoscape.work.TaskManager;
+import org.junit.runner.manipulation.Sorter;
public class SourceStatusPanel extends JPanel {
@@ -42,14 +49,14 @@
private final String query;
private final CyNetworkManager networkManager;
- private final TaskManager<?,?> taskManager;
+ private final TaskManager<?, ?> taskManager;
private final SearchMode mode;
private final CreateNetworkViewTaskFactory createViewTaskFactory;
-
- private volatile boolean enableItem = true;
+ private int interactionsFound = 0;
+
/**
* Creates new form PSICQUICResultDialog
*
@@ -68,18 +75,25 @@
setTableModel(result);
initComponents();
setCoumnWidth();
+
+ // Set number of items:
+ if (interactionsFound > 0) {
+ this.titleLabel.setText("Binary Interactions Found: " +
interactionsFound);
+ this.titleLabel.setForeground(Color.GREEN);
+ this.titleLabel.setEnabled(true);
+ this.titleLabel.repaint();
+ }
}
-
+
public void enableComponents(final boolean enable) {
this.clearButtonActionPerformed(null);
-
+
this.resultTable.setEnabled(enable);
this.resultScrollPane.setEnabled(enable);
this.selectAllButton.setEnabled(enable);
this.importNetworkButton.setEnabled(enable);
this.clearSelectionButton.setEnabled(enable);
this.setEnabled(enable);
- this.enableItem = enable;
}
public Set<String> getSelected() {
@@ -91,6 +105,8 @@
TableModel model = this.resultTable.getModel();
for (int i = 0; i < model.getRowCount(); i++) {
Boolean selected = (Boolean) model.getValueAt(i, 0);
+ if (selected == null)
+ selected = false;
if (selected)
selectedService.add(model.getValueAt(i,
1).toString());
@@ -104,20 +120,22 @@
resultTable.getTableHeader().setReorderingAllowed(false);
resultTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
// Checkbox
- resultTable.getColumnModel().getColumn(0).setPreferredWidth(70);
+ resultTable.getColumnModel().getColumn(0).setPreferredWidth(60);
// Name
resultTable.getColumnModel().getColumn(1).setPreferredWidth(150);
- // Number of result
-
resultTable.getColumnModel().getColumn(2).setPreferredWidth(100);
- // Status
+ // Tags
+
resultTable.getColumnModel().getColumn(2).setPreferredWidth(250);
+ // Found
resultTable.getColumnModel().getColumn(3).setPreferredWidth(100);
+
resultTable.getColumnModel().getColumn(4).setPreferredWidth(150);
resultTable.setSelectionBackground(SELECTED_ROW);
resultTable.setDefaultRenderer(String.class, new
StringCellRenderer());
-
+ resultTable.setDefaultRenderer(Number.class, new
NumberCellRenderer());
}
private void setTableModel(final Map<String, Long> result) {
+
final StatusTableModel model = new StatusTableModel();
model.addColumn("Import");
model.addColumn("Data Source Name");
@@ -125,7 +143,11 @@
model.addColumn("Records Found");
model.addColumn("Status");
+ // Reset counter
+ this.interactionsFound = 0;
+
for (final String serviceName : manager.getAllServiceNames()) {
+ Integer errorID = null;
final Object[] rowValues = new Object[5];
rowValues[1] = serviceName;
@@ -133,34 +155,56 @@
if (result != null) {
final String targetURL =
manager.getActiveServices().get(serviceName);
if (targetURL != null) {
- Integer count =
result.get(targetURL).intValue();
- if (count < 0)
+ Long targetResult =
result.get(targetURL);
+ if (targetResult == null)
rowValues[3] = 0;
- else
- rowValues[3] = count;
+ else {
+ final Integer count =
targetResult.intValue();
+ if (count > 0)
+ interactionsFound =
interactionsFound + count;
+ else if (count < 0)
+ errorID = count;
+
+ if (count < 0)
+ rowValues[3] = 0;
+ else
+ rowValues[3] = count;
+ }
} else
rowValues[3] = 0;
} else {
rowValues[3] = 0;
}
- if (manager.isActive(serviceName)) {
- rowValues[4] = "Active";
- if (((Integer) rowValues[3]) != 0)
- rowValues[0] = true;
- else
+ if (errorID != null) {
+ if (errorID ==
PSICQUICRestClient.ERROR_CANCEL.intValue())
+ rowValues[4] = "Operation canceled";
+ else if (errorID ==
PSICQUICRestClient.ERROR_TIMEOUT.intValue()) {
+ rowValues[4] = "Timeout. Try again
later.";
+ } else if (errorID ==
PSICQUICRestClient.ERROR_SEARCH_FAILED.intValue()) {
+ rowValues[4] = "Server returns error.
Try again later.";
+ } else {
+ rowValues[4] = "Unknown error. Try
again later.";
+ }
+ } else {
+ if (manager.isActive(serviceName)) {
+ rowValues[4] = "Active";
+ if (((Integer) rowValues[3]) != 0)
+ rowValues[0] = true;
+ else
+ rowValues[0] = false;
+ } else {
rowValues[0] = false;
- } else {
- rowValues[0] = false;
- rowValues[4] = "Inactive";
+ rowValues[4] = "Inactive";
+ }
}
model.addRow(rowValues);
}
this.resultTable = new JTable(model);
+ this.resultTable.setAutoCreateRowSorter(true);
model.fireTableDataChanged();
repaint();
- updateUI();
}
/**
@@ -180,19 +224,20 @@
cancelButton = new javax.swing.JButton();
clearSelectionButton = new JButton();
selectAllButton = new JButton();
- clusterResultCheckBox = new JCheckBox("Mearge Networks (Cluster
Result)");
+ clusterResultCheckBox = new JCheckBox("Merge results into one
network");
titlePanel.setBackground(java.awt.Color.white);
- titleLabel.setFont(new java.awt.Font("SansSerif", 1, 14)); //
NOI18N
- titleLabel.setText("Data Service Status");
+ titleLabel.setFont(new java.awt.Font("SansSerif", Font.BOLD,
14)); // NOI18N
+ titleLabel.setEnabled(false);
+ titleLabel.setText("Binary Interactions Found: -");
GroupLayout titlePanelLayout = new GroupLayout(titlePanel);
titlePanel.setLayout(titlePanelLayout);
titlePanelLayout.setHorizontalGroup(titlePanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(
titlePanelLayout.createSequentialGroup().addContainerGap().addComponent(titleLabel)
-
.addContainerGap(200, Short.MAX_VALUE)));
+
.addContainerGap(40, Short.MAX_VALUE)));
titlePanelLayout.setVerticalGroup(titlePanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
titlePanelLayout.createSequentialGroup().addContainerGap().addComponent(titleLabel)
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
@@ -203,6 +248,7 @@
buttonPanel.setBackground(java.awt.Color.white);
importNetworkButton.setText("Import");
+ importNetworkButton.setFont(new Font("SansSerif", Font.BOLD,
12));
importNetworkButton.setPreferredSize(new java.awt.Dimension(70,
28));
importNetworkButton.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
@@ -230,7 +276,7 @@
selectAllButtonActionPerformed(evt);
}
});
-
+
clusterResultCheckBox.setToolTipText("<html><h3>Cluster to
single network</h3></html>");
GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel);
@@ -240,9 +286,9 @@
GroupLayout.Alignment.TRAILING,
buttonPanelLayout.createSequentialGroup().addComponent(clearSelectionButton)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(selectAllButton)
-
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(clusterResultCheckBox)
-
.addContainerGap(100, Short.MAX_VALUE).addComponent(cancelButton)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
+
.addComponent(clusterResultCheckBox).addContainerGap(100, Short.MAX_VALUE)
+
.addComponent(cancelButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(importNetworkButton).addContainerGap()));
buttonPanelLayout.setVerticalGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(
@@ -297,11 +343,11 @@
networkManager, manager, sourceURLs, mode,
createViewTaskFactory, toBeClustered);
taskManager.execute(new TaskIterator(networkTask));
-
+
Window parentWindow = ((Window) getRootPane().getParent());
parentWindow.pack();
repaint();
-
+
parentWindow.toFront();
}
@@ -314,9 +360,12 @@
resultTable.setValueAt(Boolean.FALSE, i, 0);
}
+ /**
+ * Select all check box
+ */
private void selectAllButtonActionPerformed(ActionEvent evt) {
for (int i = 0; i < resultTable.getRowCount(); i++) {
- if (((Number) resultTable.getValueAt(i, 2)).intValue()
== 0)
+ if (((Number) resultTable.getValueAt(i, 3)).intValue()
== 0)
resultTable.setValueAt(Boolean.FALSE, i, 0);
else
resultTable.setValueAt(Boolean.TRUE, i, 0);
@@ -379,25 +428,87 @@
}
final String serviceName = (String)
table.getValueAt(row, 1);
+ final String statusString = (String)
table.getValueAt(row, 4);
this.setText(value.toString());
- if (!manager.isActive(serviceName))
+ if (!manager.isActive(serviceName) ||
statusString.equals("Active") == false) {
this.setForeground(Color.red);
+ this.setEnabled(false);
+ } else {
+ this.setForeground(table.getForeground());
+ this.setEnabled(true);
+ }
+ if (isSelected)
+
this.setBackground(table.getSelectionBackground());
else
+ this.setBackground(table.getBackground());
+
+ if(column == 4) {
+
this.setHorizontalAlignment(SwingConstants.LEFT);
+ } else {
+
this.setHorizontalAlignment(SwingConstants.CENTER);
+ }
+ return this;
+ }
+ }
+
+ private final class NumberCellRenderer extends DefaultTableCellRenderer
{
+
+ private static final long serialVersionUID =
6889007019721032218L;
+
+ public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected,
+ boolean hasFocus, int row, int column) {
+
+ if (value == null || value instanceof Number == false) {
+ this.setEnabled(false);
+ return this;
+ }
+ this.setEnabled(true);
+
+ Integer count;
+ try {
+ count = Integer.valueOf(value.toString());
+ } catch (Exception e) {
+ count = 0;
+ }
+
+ final String serviceName = (String)
table.getValueAt(row, 1);
+ final String statusString = (String)
table.getValueAt(row, 4);
+
+ this.setText(count.toString());
+
+ if (!manager.isActive(serviceName) ||
statusString.equals("Active") == false) {
+ this.setForeground(Color.red);
+ this.setEnabled(false);
+ } else if (count == 0) {
+ this.setForeground(Color.LIGHT_GRAY);
+ this.setEnabled(false);
+ } else
this.setForeground(table.getForeground());
if (isSelected)
this.setBackground(table.getSelectionBackground());
else
this.setBackground(table.getBackground());
-
- this.setHorizontalAlignment(SwingConstants.CENTER);
- this.setEnabled(enableItem);
-
return this;
}
}
+
+ /**
+ * Force to sort row
+ */
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ void sort() {
+ RowSorter<? extends TableModel> sorter =
this.resultTable.getRowSorter();
+ if (sorter instanceof DefaultRowSorter) {
+ List list = new ArrayList<Object>();
+ list.add(new RowSorter.SortKey(3,
SortOrder.DESCENDING));
+ sorter.setSortKeys(list);
+ ((DefaultRowSorter) sorter).sort();
+ }
+ }
+
}
Modified:
core3/impl/trunk/webservice-psicquic-client-impl/src/test/java/org/cytoscape/webservice/psicquic/PSICQUICClientTest.java
===================================================================
---
core3/impl/trunk/webservice-psicquic-client-impl/src/test/java/org/cytoscape/webservice/psicquic/PSICQUICClientTest.java
2012-06-04 19:03:10 UTC (rev 29440)
+++
core3/impl/trunk/webservice-psicquic-client-impl/src/test/java/org/cytoscape/webservice/psicquic/PSICQUICClientTest.java
2012-06-04 19:25:06 UTC (rev 29441)
@@ -1,12 +1,9 @@
package org.cytoscape.webservice.psicquic;
-import static org.junit.Assert.*;
-
import java.net.URI;
import org.cytoscape.model.CyNetworkFactory;
import org.cytoscape.model.CyNetworkManager;
-import org.cytoscape.task.NetworkTaskFactory;
import org.cytoscape.task.create.CreateNetworkViewTaskFactory;
import org.cytoscape.util.swing.OpenBrowser;
import org.cytoscape.webservice.AbstractWebServiceClientTest;
Modified:
core3/impl/trunk/webservice-psicquic-client-impl/src/test/java/org/cytoscape/webservice/psicquic/RegistryClientTest.java
===================================================================
---
core3/impl/trunk/webservice-psicquic-client-impl/src/test/java/org/cytoscape/webservice/psicquic/RegistryClientTest.java
2012-06-04 19:03:10 UTC (rev 29440)
+++
core3/impl/trunk/webservice-psicquic-client-impl/src/test/java/org/cytoscape/webservice/psicquic/RegistryClientTest.java
2012-06-04 19:25:06 UTC (rev 29441)
@@ -1,9 +1,5 @@
package org.cytoscape.webservice.psicquic;
-import static org.junit.Assert.assertNotNull;
-
-import java.util.Map;
-
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Modified:
core3/impl/trunk/webservice-psicquic-client-impl/src/test/java/org/cytoscape/webservice/psicquic/RestClientTest.java
===================================================================
---
core3/impl/trunk/webservice-psicquic-client-impl/src/test/java/org/cytoscape/webservice/psicquic/RestClientTest.java
2012-06-04 19:03:10 UTC (rev 29440)
+++
core3/impl/trunk/webservice-psicquic-client-impl/src/test/java/org/cytoscape/webservice/psicquic/RestClientTest.java
2012-06-04 19:25:06 UTC (rev 29441)
@@ -1,13 +1,5 @@
package org.cytoscape.webservice.psicquic;
-import static org.junit.Assert.assertNotNull;
-
-import java.util.Collection;
-import java.util.Map;
-
-import org.cytoscape.model.CyNetwork;
-import org.cytoscape.model.CyNetworkFactory;
-import org.cytoscape.model.NetworkTestSupport;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
--
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.