Author: scooter
Date: 2010-11-02 11:38:23 -0700 (Tue, 02 Nov 2010)
New Revision: 22682

Modified:
   csplugins/trunk/ucsf/scooter/bioCycPlugin/src/bioCycPlugin/BioCycPlugin.java
   
csplugins/trunk/ucsf/scooter/bioCycPlugin/src/bioCycPlugin/commands/QueryHandler.java
   
csplugins/trunk/ucsf/scooter/bioCycPlugin/src/bioCycPlugin/model/Database.java
   
csplugins/trunk/ucsf/scooter/bioCycPlugin/src/bioCycPlugin/webservices/BioCycClient.java
   
csplugins/trunk/ucsf/scooter/bioCycPlugin/src/bioCycPlugin/webservices/BioCycClientGui.java
   
csplugins/trunk/ucsf/scooter/bioCycPlugin/src/bioCycPlugin/webservices/BioCycRESTClient.java
Log:
Fix URL reader and support database defaults.


Modified: 
csplugins/trunk/ucsf/scooter/bioCycPlugin/src/bioCycPlugin/BioCycPlugin.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/bioCycPlugin/src/bioCycPlugin/BioCycPlugin.java    
    2010-11-02 02:06:30 UTC (rev 22681)
+++ 
csplugins/trunk/ucsf/scooter/bioCycPlugin/src/bioCycPlugin/BioCycPlugin.java    
    2010-11-02 18:38:23 UTC (rev 22682)
@@ -39,14 +39,21 @@
 import cytoscape.plugin.CytoscapePlugin;
 import cytoscape.logger.CyLogger;
 
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
 import java.util.Properties;
 
 import bioCycPlugin.commands.BioCycCommandHandler;
 import bioCycPlugin.webservices.BioCycClient;
 
-public class BioCycPlugin extends CytoscapePlugin {
+public class BioCycPlugin extends CytoscapePlugin implements 
PropertyChangeListener {
        private CyLogger logger = null;
        private BioCycClient wpclient;
+       private static Properties defaultProps = null;
 
        protected static final String WEBSERVICE_URL = "biocyc.webservice.uri";
        // protected static final String DEFAULT_URL = 
"http://brg-preview.ai.sri.com/";;
@@ -65,18 +72,59 @@
                        logger.error(e.getMessage());
                }
 
+               // Listen for exits
+               
Cytoscape.getPropertyChangeSupport().addPropertyChangeListener(Cytoscape.CYTOSCAPE_EXIT,
 this);
+
                // Setup any global properties
                Properties p = CytoscapeInit.getProperties();
                if (p.get(WEBSERVICE_URL) == null) {
                        p.put(WEBSERVICE_URL, DEFAULT_URL);
                }
+
+               // Initialize our properties file
+               initBioCycProps();
+
                // Register ourselves with the web services infrastructure
                wpclient = new BioCycClient(logger);
                WebServiceClientManager.registerClient(wpclient);
+       }
 
+       public static void initBioCycProps() {
+               if (defaultProps == null) {
+                       defaultProps = new Properties();
+                       File propsFile = new 
File(CytoscapeInit.getConfigVersionDirectory(), "bioCycPlugin.props");
+                       if (propsFile != null) {
+                               try {
+                                       FileInputStream inputStream = new 
FileInputStream(propsFile);
+                                       defaultProps.load(inputStream);
+                               } catch (IOException e) {}
+                       }
+               }
        }
 
+       public static String getProp(String prop) {
+               if (defaultProps != null)
+                       return defaultProps.getProperty(prop);
+               return null;
+       }
+
+       public static void setProp(String propName, String propValue) {
+               defaultProps.setProperty(propName, propValue);
+       }
+
        public static String getBaseUrl() {
                return 
CytoscapeInit.getProperties().getProperty(WEBSERVICE_URL);
        }
+
+       public void propertyChange(PropertyChangeEvent evt) {
+               if (evt.getPropertyName().equals(Cytoscape.CYTOSCAPE_EXIT)) {
+                       File propsFile = new 
File(CytoscapeInit.getConfigVersionDirectory(), "bioCycPlugin.props");
+                       if (propsFile != null) {
+                               try {
+                                       defaultProps.store(new 
FileOutputStream(propsFile), "");
+                               } catch (IOException e) {}
+                       }
+               }
+       }
+
 }

Modified: 
csplugins/trunk/ucsf/scooter/bioCycPlugin/src/bioCycPlugin/commands/QueryHandler.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/bioCycPlugin/src/bioCycPlugin/commands/QueryHandler.java
       2010-11-02 02:06:30 UTC (rev 22681)
+++ 
csplugins/trunk/ucsf/scooter/bioCycPlugin/src/bioCycPlugin/commands/QueryHandler.java
       2010-11-02 18:38:23 UTC (rev 22682)
@@ -125,6 +125,12 @@
 
                ImportHandler inputHandler = Cytoscape.getImportHandler();
                try {
+                       // Add a listener so we can fix up some attributes
+                       Cytoscape.getPropertyChangeSupport()
+                                         .addPropertyChangeListener( 
Cytoscape.NETWORK_LOADED, new ParseCMLAttributes(logger) );
+                       LoadNetworkTask.loadURL(new URL(baseUrl+queryString), 
false);
+
+/*
                        File rawFile = inputHandler.downloadFromURL(new 
URL(baseUrl+queryString), null);
                        File bioPaxFile = new 
File(rawFile.getAbsolutePath()+".xml");
                        rawFile.renameTo(bioPaxFile);
@@ -133,8 +139,11 @@
                                          .addPropertyChangeListener( 
Cytoscape.NETWORK_LOADED, new ParseCMLAttributes(logger) );
 
                        LoadNetworkTask.loadFile(bioPaxFile, false);
+                       logger.info("Loading file into: 
"+bioPaxFile.getAbsolutePath());
                        bioPaxFile.delete();
+*/
                } catch (Exception e) {
+                       logger.error("Error loading network from 
"+baseUrl+queryString+": "+e.getMessage(), e);
                        throw new MalformedURLException("Unable to load network 
from "+baseUrl+queryString+" ("+e.getMessage()+")");
                }
        }

Modified: 
csplugins/trunk/ucsf/scooter/bioCycPlugin/src/bioCycPlugin/model/Database.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/bioCycPlugin/src/bioCycPlugin/model/Database.java  
    2010-11-02 02:06:30 UTC (rev 22681)
+++ 
csplugins/trunk/ucsf/scooter/bioCycPlugin/src/bioCycPlugin/model/Database.java  
    2010-11-02 18:38:23 UTC (rev 22682)
@@ -32,6 +32,8 @@
  */
 package bioCycPlugin.model;
 
+import bioCycPlugin.BioCycPlugin;
+
 import java.util.ArrayList;
 import java.util.List;
 import org.w3c.dom.Document;
@@ -84,4 +86,17 @@
                }
                return databases;
        }
+
+       public static Database getDefaultDatabase(List<Database>databases) {
+               String db = BioCycPlugin.getProp("defaultDatabase");
+               for (Database d: databases) {
+                       if (d.getOrgID().equals(db))
+                               return d;
+               }
+               return null;
+       }
+
+       public static void setDefaultDatabase(Database database) {
+               BioCycPlugin.setProp("defaultDatabase", database.getOrgID());
+       }
 }

Modified: 
csplugins/trunk/ucsf/scooter/bioCycPlugin/src/bioCycPlugin/webservices/BioCycClient.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/bioCycPlugin/src/bioCycPlugin/webservices/BioCycClient.java
    2010-11-02 02:06:30 UTC (rev 22681)
+++ 
csplugins/trunk/ucsf/scooter/bioCycPlugin/src/bioCycPlugin/webservices/BioCycClient.java
    2010-11-02 18:38:23 UTC (rev 22682)
@@ -115,41 +115,6 @@
                }
        }
 
-       public List<JMenuItem> getNodeContextMenuItems(NodeView nv) {
-               List<JMenuItem> menuList = new ArrayList<JMenuItem>();
-
-               //Add an item to find interactions
-               // menuList.add(new JMenuItem(new NodeInteractionsAction(this, 
nv)));
-
-               //If the node is a found interaction, add items to open the 
source on WP
-               CyAttributes attr = Cytoscape.getNodeAttributes();
-               String nid = nv.getNode().getIdentifier();
-               // addPathwayMenuItems(attr, nid, menuList);
-               return menuList;
-       }
-
-       public List<JMenuItem> getEdgeContextMenuItems(EdgeView ev) {
-               List<JMenuItem> menuList = new ArrayList<JMenuItem>();
-
-               //If the edge is a found interaction, add items to open the 
source on WP
-               CyAttributes attr = Cytoscape.getEdgeAttributes();
-               String eid = ev.getEdge().getIdentifier();
-               // addPathwayMenuItems(attr, eid, menuList);
-
-               return menuList;
-       }
-
-       /**
-        * Adds menu items to open and import pathways based on the pathway info
-        * stored in the attributes (by the find interactions function).
-        * @param attr The attribute store
-        * @param nid The node or edge id
-        * @param menuList The list to add the menu items to
-        */
-       private void addPathwayMenuItems(CyAttributes attr, String nid, 
List<JMenuItem> menuList) {
-               // TODO
-       }
-
        public void executeService(CyWebServiceEvent e)
        throws CyWebServiceException {
                if(CLIENT_ID.equals(e.getSource())) {
@@ -237,10 +202,6 @@
                }
 
                public void halt() {
-                       //Not 2.6 compatible
-                       //                      
WebServiceClientManager.getCyWebServiceEventSupport().fireCyWebServiceEvent(
-                       //                              new 
CyWebServiceEvent(CLIENT_ID, WSEventType.CANCEL, query)
-                       //                      );
                }
 
                public void setTaskMonitor(TaskMonitor m)
@@ -250,10 +211,6 @@
 
                public void executeService(CyWebServiceEvent event)
                throws CyWebServiceException {
-                       //Not 2.6 compatible
-                       //                      if 
(event.getEventType().equals(WSEventType.CANCEL)) {
-                       //                              throw new 
CyWebServiceException(CyWebServiceException.WSErrorCode.REMOTE_EXEC_FAILED);
-                       //                      }
                }
        }
 

Modified: 
csplugins/trunk/ucsf/scooter/bioCycPlugin/src/bioCycPlugin/webservices/BioCycClientGui.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/bioCycPlugin/src/bioCycPlugin/webservices/BioCycClientGui.java
 2010-11-02 02:06:30 UTC (rev 22681)
+++ 
csplugins/trunk/ucsf/scooter/bioCycPlugin/src/bioCycPlugin/webservices/BioCycClientGui.java
 2010-11-02 18:38:23 UTC (rev 22682)
@@ -16,9 +16,9 @@
 //
 package bioCycPlugin.webservices;
 
-import bioCycPlugin.webservices.ResultProperty;
 import bioCycPlugin.model.Database;
 import bioCycPlugin.model.Pathway;
+import bioCycPlugin.webservices.ResultProperty;
 
 import bioCycPlugin.webservices.BioCycClient.FindPathwaysByTextParameters;
 import bioCycPlugin.webservices.BioCycClient.GetPathwayParameters;
@@ -59,6 +59,7 @@
        final BioCycClient client;
        private CyLogger logger;
 
+       Database defaultDatabase = null;
        JComboBox databaseCombo;
        JTextField searchText;
        JTable resultTable;
@@ -69,6 +70,8 @@
                this.logger = logger;
 
                databaseCombo = new JComboBox();
+               databaseCombo.addActionListener(this);
+               databaseCombo.setActionCommand(ACTION_SET_DATABASE);
                resetDatabases();
 
                searchText = new JTextField();
@@ -116,6 +119,9 @@
                Object dbArray[] = databases.toArray();
                Arrays.sort(dbArray);
                databaseCombo.setModel(new DefaultComboBoxModel(dbArray));
+               defaultDatabase = Database.getDefaultDatabase(databases);
+               if (defaultDatabase != null) 
+                       databaseCombo.setSelectedItem(defaultDatabase);
        }
 
        public void actionPerformed(ActionEvent e) {
@@ -150,6 +156,9 @@
                                }
                                ex.printStackTrace();
                        }
+               } else if (ACTION_SET_DATABASE.equals(action)) {
+                       defaultDatabase = (Database) 
databaseCombo.getSelectedItem();
+                       Database.setDefaultDatabase(defaultDatabase);
                }
        }
 
@@ -215,4 +224,5 @@
        }
 
        private static final String ACTION_SEARCH = "Search";
+       private static final String ACTION_SET_DATABASE = "Set Database";
 }

Modified: 
csplugins/trunk/ucsf/scooter/bioCycPlugin/src/bioCycPlugin/webservices/BioCycRESTClient.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/bioCycPlugin/src/bioCycPlugin/webservices/BioCycRESTClient.java
        2010-11-02 02:06:30 UTC (rev 22681)
+++ 
csplugins/trunk/ucsf/scooter/bioCycPlugin/src/bioCycPlugin/webservices/BioCycRESTClient.java
        2010-11-02 18:38:23 UTC (rev 22682)
@@ -53,6 +53,7 @@
 public class BioCycRESTClient {
        CyLogger logger;
        QueryHandler handler;
+       List<Database> databaseCache = null;
 
        enum Operator {AND, OR};
 
@@ -70,7 +71,9 @@
        }
 
        public List<Database> listDatabases() {
-               return Database.getDatabases(handler.query("dbs"));
+               if (databaseCache == null)
+                       databaseCache = 
Database.getDatabases(handler.query("dbs"));
+               return databaseCache;
        }
 
        public List<Pathway> findPathwaysByText(String query, String db) {

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