Author: ruschein
Date: 2011-06-24 12:34:55 -0700 (Fri, 24 Jun 2011)
New Revision: 25923

Modified:
   core3/search-impl/trunk/pom.xml
   
core3/search-impl/trunk/src/main/java/org/cytoscape/search/internal/EnhancedSearchIndex.java
   
core3/search-impl/trunk/src/main/java/org/cytoscape/search/internal/EnhancedSearchPlugin.java
   
core3/search-impl/trunk/src/main/java/org/cytoscape/search/internal/EnhancedSearchQuery.java
   
core3/search-impl/trunk/src/main/java/org/cytoscape/search/internal/IndexAndSearchTask.java
Log:
Now invalid search expression errors are being displayed to the user and event 
handling has been updated to the modern payload style.  This fixes Redmine Bug 
#134.

Modified: core3/search-impl/trunk/pom.xml
===================================================================
--- core3/search-impl/trunk/pom.xml     2011-06-24 18:58:29 UTC (rev 25922)
+++ core3/search-impl/trunk/pom.xml     2011-06-24 19:34:55 UTC (rev 25923)
@@ -94,22 +94,22 @@
                <dependency>
                        <groupId>org.cytoscape</groupId>
                        <artifactId>model-api</artifactId>
-                       <version>3.0.0-alpha3</version>
+                       <version>3.0.0-alpha5-SNAPSHOT</version>
                </dependency>
                <dependency>
                        <groupId>org.cytoscape</groupId>
                        <artifactId>viewmodel-api</artifactId>
-                       <version>3.0.0-alpha4</version>
+                       <version>3.0.0-alpha5-SNAPSHOT</version>
                </dependency>
                <dependency>
                        <groupId>org.cytoscape</groupId>
                        <artifactId>core-task-api</artifactId>
-                       <version>3.0.0-alpha3</version>
+                       <version>3.0.0-alpha4-SNAPSHOT</version>
                </dependency>
                <dependency>
                        <groupId>org.cytoscape</groupId>
                        <artifactId>session-api</artifactId>
-                       <version>3.0.0-alpha3</version>
+                       <version>3.0.0-alpha6-SNAPSHOT</version>
                </dependency>
                <dependency>
                        <groupId>org.cytoscape.wrappers</groupId>
@@ -120,13 +120,13 @@
                <dependency>
                <groupId>org.cytoscape</groupId>
                <artifactId>swing-application-api</artifactId>
-               <version>3.0.0-alpha2</version>
+               <version>3.0.0-alpha3-SNAPSHOT</version>
                </dependency>
 
                <dependency>
                        <groupId>org.cytoscape</groupId>
                        <artifactId>work-swing-api</artifactId>
-                       <version>3.0.0-alpha2</version>
+                       <version>3.0.0-alpha3-SNAPSHOT</version>
                </dependency>
 
                <!-- dependencies specifically for unit testing -->

Modified: 
core3/search-impl/trunk/src/main/java/org/cytoscape/search/internal/EnhancedSearchIndex.java
===================================================================
--- 
core3/search-impl/trunk/src/main/java/org/cytoscape/search/internal/EnhancedSearchIndex.java
        2011-06-24 18:58:29 UTC (rev 25922)
+++ 
core3/search-impl/trunk/src/main/java/org/cytoscape/search/internal/EnhancedSearchIndex.java
        2011-06-24 19:34:55 UTC (rev 25923)
@@ -1,5 +1,5 @@
 /*
- Copyright (c) 2006, 2007, 2010, The Cytoscape Consortium (www.cytoscape.org)
+ Copyright (c) 2006, 2007, 2010, 2011, The Cytoscape Consortium 
(www.cytoscape.org)
 
  This library is free software; you can redistribute it and/or modify it
  under the terms of the GNU Lesser General Public License as published
@@ -96,7 +96,6 @@
         * attribute fields
         */
        private static Document createDocument(CyTableEntry graphObject, String 
graphObjectType, int index) {
-
                Document doc = new Document();
                String identifier = Integer.toString(index);
                
@@ -146,9 +145,13 @@
                                doc.add(new Field(attrIndexingName, attrValue, 
Field.Store.YES, Field.Index.ANALYZED));
                        } else if (valueType == List.class) {
                                List attrValueList = 
graphObject.getCyRow().get(attrName, List.class);
-                               for (int j = 0; j < attrValueList.size(); j++) {
-                                       String attrValue = 
attrValueList.get(j).toString();
-                                       doc.add(new Field(attrIndexingName, 
attrValue, Field.Store.YES, Field.Index.ANALYZED));
+                               if (attrValueList != null) {
+                                       for (int j = 0; j < 
attrValueList.size(); j++) {
+                                               String attrValue = 
attrValueList.get(j).toString();
+                                               doc.add(new 
Field(attrIndexingName, attrValue,
+                                                                 
Field.Store.YES,
+                                                                 
Field.Index.ANALYZED));
+                                       }
                                }
                        }
                }
@@ -159,5 +162,4 @@
        public RAMDirectory getIndex() {
                return idx;
        }
-
 }

Modified: 
core3/search-impl/trunk/src/main/java/org/cytoscape/search/internal/EnhancedSearchPlugin.java
===================================================================
--- 
core3/search-impl/trunk/src/main/java/org/cytoscape/search/internal/EnhancedSearchPlugin.java
       2011-06-24 18:58:29 UTC (rev 25922)
+++ 
core3/search-impl/trunk/src/main/java/org/cytoscape/search/internal/EnhancedSearchPlugin.java
       2011-06-24 19:34:55 UTC (rev 25923)
@@ -1,14 +1,6 @@
-
 /*
- Copyright (c) 2006, 2007, The Cytoscape Consortium (www.cytoscape.org)
+ Copyright (c) 2006, 2007, 2011, The Cytoscape Consortium (www.cytoscape.org)
 
- The Cytoscape Consortium is:
- - Institute for Systems Biology
- - University of California San Diego
- - Memorial Sloan-Kettering Cancer Center
- - Institut Pasteur
- - Agilent Technologies
-
  This library is free software; you can redistribute it and/or modify it
  under the terms of the GNU Lesser General Public License as published
  by the Free Software Foundation; either version 2.1 of the License, or
@@ -32,15 +24,18 @@
  You should have received a copy of the GNU Lesser General Public License
  along with this library; if not, write to the Free Software Foundation,
  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-
+*/
 package org.cytoscape.search.internal;
 
+
+import java.awt.Component;
+
+import org.cytoscape.application.swing.AbstractToolBarComponent;
+import org.cytoscape.event.CyEventHelper;
+import org.cytoscape.model.CyNetwork;
 import org.cytoscape.model.CyTableManager;
 import org.cytoscape.model.events.NetworkAboutToBeDestroyedEvent;
 import org.cytoscape.model.events.NetworkAboutToBeDestroyedListener;
-import org.cytoscape.model.events.RowsAboutToChangeEvent;
-import org.cytoscape.model.events.RowsFinishedChangingEvent;
 import org.cytoscape.session.CyApplicationManager;
 import org.cytoscape.session.events.SessionLoadedEvent;
 import org.cytoscape.session.events.SessionLoadedListener;
@@ -49,27 +44,28 @@
 import org.cytoscape.application.swing.CySwingApplication;
 import org.cytoscape.search.internal.ui.EnhancedSearchPanel;
 import org.cytoscape.work.swing.GUITaskManager;
-import org.cytoscape.model.CyNetwork;
-import org.cytoscape.application.swing.AbstractToolBarComponent;
-import org.cytoscape.event.CyEventHelper;
 
-import java.awt.Component;
 
-public class EnhancedSearchPlugin extends AbstractToolBarComponent implements 
SetCurrentNetworkViewListener, NetworkAboutToBeDestroyedListener, 
-                                       SessionLoadedListener
+public class EnhancedSearchPlugin extends AbstractToolBarComponent
+       implements SetCurrentNetworkViewListener, 
NetworkAboutToBeDestroyedListener,
+                  SessionLoadedListener
 {
-       private EnhancedSearchManager searchMgr = null;
-       private EnhancedSearchPanel searchPnl = null; 
-       public static CyEventHelper eventHelper;
+       private final EnhancedSearchManager searchMgr;
+       private final EnhancedSearchPanel searchPnl; 
+       static CyEventHelper eventHelper;
        
-       public EnhancedSearchPlugin(CySwingApplication desktopApp, 
CyApplicationManager netmgr, 
-                       CyTableManager tableMgr, GUITaskManager taskMgr, final 
CyEventHelper eventHelper) {
+       public EnhancedSearchPlugin(final CySwingApplication desktopApp,
+                                   final CyApplicationManager netmgr, 
+                                   final CyTableManager tableMgr,
+                                   final GUITaskManager taskMgr,
+                                   final CyEventHelper eventHelper)
+       {
                
                searchMgr = new EnhancedSearchManager();
                // Add a text-field and a search button on tool-bar
                searchPnl = new EnhancedSearchPanel(netmgr, tableMgr, 
searchMgr, taskMgr);
                this.setToolBarGravity(150.0f);
-               EnhancedSearchPlugin.eventHelper    = eventHelper;
+               EnhancedSearchPlugin.eventHelper = eventHelper;
        }
 
        @Override       

Modified: 
core3/search-impl/trunk/src/main/java/org/cytoscape/search/internal/EnhancedSearchQuery.java
===================================================================
--- 
core3/search-impl/trunk/src/main/java/org/cytoscape/search/internal/EnhancedSearchQuery.java
        2011-06-24 18:58:29 UTC (rev 25922)
+++ 
core3/search-impl/trunk/src/main/java/org/cytoscape/search/internal/EnhancedSearchQuery.java
        2011-06-24 19:34:55 UTC (rev 25923)
@@ -1,13 +1,6 @@
 /*
- Copyright (c) 2006, 2007, The Cytoscape Consortium (www.cytoscape.org)
+ Copyright (c) 2006, 2007, 2011, The Cytoscape Consortium (www.cytoscape.org)
 
- The Cytoscape Consortium is:
- - Institute for Systems Biology
- - University of California San Diego
- - Memorial Sloan-Kettering Cancer Center
- - Institut Pasteur
- - Agilent Technologies
-
  This library is free software; you can redistribute it and/or modify it
  under the terms of the GNU Lesser General Public License as published
  by the Free Software Foundation; either version 2.1 of the License, or
@@ -31,39 +24,40 @@
  You should have received a copy of the GNU Lesser General Public License
  along with this library; if not, write to the Free Software Foundation,
  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-
+*/
 package org.cytoscape.search.internal;
 
+
 import java.io.IOException;
 import java.util.ArrayList;
+import javax.swing.JOptionPane;
+
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
-import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.search.Collector;
 import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Query;
+import org.apache.lucene.search.Scorer;
 import org.apache.lucene.search.Searcher;
+import org.apache.lucene.search.Query;
 import org.apache.lucene.store.RAMDirectory;
-import org.apache.lucene.document.Document;
-import org.cytoscape.search.internal.util.EnhancedSearchUtils;
-import org.cytoscape.search.internal.util.CustomMultiFieldQueryParser;
-import org.cytoscape.search.internal.util.AttributeFields;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.util.Version;
+
 import org.cytoscape.model.CyNetwork;
 import org.cytoscape.model.CyTableManager;
-import org.apache.lucene.util.Version;
-import org.apache.lucene.search.Collector;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.search.Scorer;
+import org.cytoscape.search.internal.util.AttributeFields;
+import org.cytoscape.search.internal.util.CustomMultiFieldQueryParser;
+import org.cytoscape.search.internal.util.EnhancedSearchUtils;
 
 
 public class EnhancedSearchQuery {
-
+       private final RAMDirectory idx;
+       private final CyNetwork network;
+       private final CyTableManager tableMgr;
        private IdentifiersCollector hitCollector = null;
+       private Searcher searcher = null;
 
-       private RAMDirectory idx;
-       private CyNetwork network;
-       private Searcher searcher;
-       private  CyTableManager tableMgr;
-
        public EnhancedSearchQuery(CyNetwork network, RAMDirectory index, 
CyTableManager tableMgr) {
                this.network = network;
                this.idx = index;
@@ -72,7 +66,6 @@
 
        public void executeQuery(String queryString) {
                try {
-
                        // Define attribute fields in which the search is to be 
carried on
                        AttributeFields attFields = new 
AttributeFields(network, tableMgr);
 
@@ -94,32 +87,32 @@
         * attributeName), search is carried out on all attribute fields. This
         * functionality is enabled with the use of MultiFieldQueryParser.
         */
-       private void search(String queryString, AttributeFields attFields)
-                       throws IOException {
-               
+       private void search(final String queryString, final AttributeFields 
attFields)
+               throws IOException
+       {
                // Build a Query object.
                // CustomMultiFieldQueryParser is used to support range queries 
on numerical attribute fields.
-               CustomMultiFieldQueryParser queryParser = new 
CustomMultiFieldQueryParser(attFields, new StandardAnalyzer(Version.LUCENE_30));
+               final CustomMultiFieldQueryParser queryParser =
+                       new CustomMultiFieldQueryParser(attFields, new 
StandardAnalyzer(Version.LUCENE_30));
 
                try {
                        // Execute query
                        Query query = queryParser.parse(queryString);
-                       
                        hitCollector = new IdentifiersCollector(searcher);
                        searcher.search(query, hitCollector);               
-               } catch (ParseException pe) {
+               } catch (final ParseException pe) {
                        // Parse exceptions occur when colon appear in the 
query in an
                        // unexpected location, e.g. when attribute or value are
                        // missing in the query. In such case, the hitCollector
                        // variable will be null.
-                       System.out.println("Invalid query '" + queryString + 
"'");
-                       String message = pe.getMessage();
-                       System.out.println(message);
-               } catch (Exception e) {
+                       JOptionPane.showMessageDialog(null, pe.getMessage(),
+                                                     "Invalid query!",
+                                                     
JOptionPane.ERROR_MESSAGE);
+               } catch (final Exception e) {
                        // Other types of exception may occur
-                       System.out.println("Error during execution of query '" 
+ queryString + "'");
-                       String message = e.getMessage();
-                       System.out.println(message);
+                       JOptionPane.showMessageDialog(null, e.getMessage(),
+                                                     "Query execution error!",
+                                                     
JOptionPane.ERROR_MESSAGE);
                }                       
        }
 

Modified: 
core3/search-impl/trunk/src/main/java/org/cytoscape/search/internal/IndexAndSearchTask.java
===================================================================
--- 
core3/search-impl/trunk/src/main/java/org/cytoscape/search/internal/IndexAndSearchTask.java
 2011-06-24 18:58:29 UTC (rev 25922)
+++ 
core3/search-impl/trunk/src/main/java/org/cytoscape/search/internal/IndexAndSearchTask.java
 2011-06-24 19:34:55 UTC (rev 25923)
@@ -1,13 +1,6 @@
 /*
- Copyright (c) 2006, 2007, The Cytoscape Consortium (www.cytoscape.org)
+ Copyright (c) 2006, 2007, 2011, The Cytoscape Consortium (www.cytoscape.org)
 
- The Cytoscape Consortium is:
- - Institute for Systems Biology
- - University of California San Diego
- - Memorial Sloan-Kettering Cancer Center
- - Institut Pasteur
- - Agilent Technologies
-
  This library is free software; you can redistribute it and/or modify it
  under the terms of the GNU Lesser General Public License as published
  by the Free Software Foundation; either version 2.1 of the License, or
@@ -31,41 +24,41 @@
  You should have received a copy of the GNU Lesser General Public License
  along with this library; if not, write to the Free Software Foundation,
  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-
+*/
 package org.cytoscape.search.internal;
 
+
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Iterator;
+
 import org.apache.lucene.store.RAMDirectory;
+
 import org.cytoscape.model.CyNetwork;
 import org.cytoscape.view.model.CyNetworkView;
 import org.cytoscape.model.CyNode;
 import org.cytoscape.model.CyEdge;
 import org.cytoscape.task.AbstractNetworkViewTask;
 import org.cytoscape.work.TaskMonitor;
-//import org.cytoscape.work.Tunable;
 import org.cytoscape.model.CyTableManager;
-import org.cytoscape.model.events.RowsAboutToChangeEvent;
-import org.cytoscape.model.events.RowsFinishedChangingEvent;
 
-public class IndexAndSearchTask extends AbstractNetworkViewTask {
 
+public class IndexAndSearchTask extends AbstractNetworkViewTask {
        private boolean interrupted = false;
        private EnhancedSearch enhancedSearch;
        private CyNetwork network;
        private CyTableManager tableMgr;
 
-       //@Tunable(description="Search for:")
        public String query;
 
        /**
-        * The constructor. Any necessary data that is <i>not</i> provided by 
-        * the user should be provided as arguments to the constructor.  
+        * The constructor. Any necessary data that is <i>not</i> provided by
+        * the user should be provided as arguments to the constructor.
         */
-       public IndexAndSearchTask(final CyNetworkView networkView, 
EnhancedSearch enhancedSearch, 
-                       CyTableManager tableMgr, String query) {
+       public IndexAndSearchTask(final CyNetworkView networkView,
+                                 final EnhancedSearch enhancedSearch,
+                                 final CyTableManager tableMgr, String query)
+       {
                // Will set a CyNetwork field called "net".
                super(networkView);
                network = networkView.getModel();
@@ -76,7 +69,6 @@
 
        @Override
        public void run(final TaskMonitor taskMonitor) {
-
                // Give the task a title.
                taskMonitor.setTitle("Searching the network");
 
@@ -85,49 +77,33 @@
 
                String status = enhancedSearch.getNetworkIndexStatus(network);
 
-               if (status != null && 
status.equalsIgnoreCase(EnhancedSearch.INDEX_SET)) {
-                       idx = enhancedSearch.getNetworkIndex(network);          
        
-               } else {
+               if (status != null && 
status.equalsIgnoreCase(EnhancedSearch.INDEX_SET))
+                       idx = enhancedSearch.getNetworkIndex(network);
+               else {
                        taskMonitor.setStatusMessage("Indexing network");
                        EnhancedSearchIndex indexHandler = new 
EnhancedSearchIndex(network);
                        idx = indexHandler.getIndex();
                        enhancedSearch.setNetworkIndex(network, idx);
                }
 
-               if (interrupted) {
+               if (interrupted)
                        return;
-               }
 
                // Execute query
                taskMonitor.setStatusMessage("Executing query");
                EnhancedSearchQuery queryHandler = new 
EnhancedSearchQuery(network, idx, tableMgr);
                queryHandler.executeQuery(query);
 
-               if (interrupted) {
+               if (interrupted)
                        return;
-               }
-
-               if (network != null && network.getNodeList().size() > 0){
-                       try {
-
-                               
EnhancedSearchPlugin.eventHelper.fireSynchronousEvent(new 
RowsAboutToChangeEvent(this,  network.getDefaultNodeTable()));
-                               
EnhancedSearchPlugin.eventHelper.fireSynchronousEvent(new 
RowsAboutToChangeEvent(this,  network.getDefaultEdgeTable()));
-
-                               showResults(queryHandler, taskMonitor);
-                       }
-                       finally {
-                               
EnhancedSearchPlugin.eventHelper.fireAsynchronousEvent(new 
RowsFinishedChangingEvent(this, network.getDefaultNodeTable()));             
-                               
EnhancedSearchPlugin.eventHelper.fireAsynchronousEvent(new 
RowsFinishedChangingEvent(this, network.getDefaultEdgeTable()));                
                                     
-                       }
-               }
        }
 
-
-       private void showResults(EnhancedSearchQuery queryHandler, final 
TaskMonitor taskMonitor){
-               // Display results
-               if (network == null || network.getNodeList().size() == 0){
+       // Display results
+       private void showResults(final EnhancedSearchQuery queryHandler,
+                                final TaskMonitor taskMonitor)
+       {
+               if (network == null || network.getNodeList().size() == 0)
                        return;
-               }
 
                List<CyNode> nodeList = network.getNodeList();
                for (CyNode n : nodeList) {
@@ -140,9 +116,8 @@
 
                int nodeHitCount = queryHandler.getNodeHitCount();
                int edgeHitCount = queryHandler.getEdgeHitCount();
-               if (nodeHitCount == 0 && edgeHitCount == 0) {
+               if (nodeHitCount == 0 && edgeHitCount == 0)
                        return;
-               }       
 
                taskMonitor.setStatusMessage("Selecting " + nodeHitCount + " 
and " + edgeHitCount + " edges");
 
@@ -154,11 +129,10 @@
                while (nodeIt.hasNext() && !interrupted) {
                        int currESPIndex = 
Integer.parseInt(nodeIt.next().toString());
                        CyNode currNode = network.getNode(currESPIndex);
-                       if (currNode != null) {
+                       if (currNode != null)
                                currNode.getCyRow().set("selected", true);
-                       } else {
+                       else
                                System.out.println("Unknown node identifier " + 
(currESPIndex));
-                       }
 
                        taskMonitor.setProgress(numCompleted++ / nodeHitCount);
                }
@@ -168,22 +142,20 @@
                while (edgeIt.hasNext() && !interrupted) {
                        int currESPIndex = 
Integer.parseInt(edgeIt.next().toString());
                        CyEdge currEdge = network.getEdge(currESPIndex);
-                       if (currEdge != null) {
+                       if (currEdge != null)
                                currEdge.getCyRow().set("selected", true);
-                       } else {
+                       else
                                System.out.println("Unknown edge identifier " + 
(currESPIndex));
-                       }
 
-                       taskMonitor.setProgress(numCompleted++ / edgeHitCount);
+                       taskMonitor.setProgress(++numCompleted / edgeHitCount);
                }
 
                // Refresh view to show selected nodes and edges
                view.updateView();
        }
 
-
        @Override
        public void cancel() {
                this.interrupted = true;
        }
-}
\ 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