Author: scooter
Date: 2009-11-24 15:17:49 -0800 (Tue, 24 Nov 2009)
New Revision: 18572

Added:
   
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/NodeListUtils.java
Removed:
   
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/AbstractCommand.java
Modified:
   
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/AttributeUtils.java
   
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/EdgeNamespace.java
   
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/LayoutNamespace.java
   
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/NetworkNamespace.java
   
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/NetworkViewNamespace.java
   
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/NodeNamespace.java
   
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/PropertyNamespace.java
   
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/QuitNamespace.java
   
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/SessionNamespace.java
   
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/VizMapNamespace.java
   
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/network/CreateNetwork.java
   
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/network/ExportNetwork.java
   
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/network/ImportNetwork.java
   
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/networkView/ExportNetworkView.java
Log:
Moved AbstractCommand into the core


Deleted: 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/AbstractCommand.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/AbstractCommand.java
  2009-11-24 23:10:36 UTC (rev 18571)
+++ 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/AbstractCommand.java
  2009-11-24 23:17:49 UTC (rev 18572)
@@ -1,218 +0,0 @@
-/* vim: set ts=2: */
-/**
- * Copyright (c) 2007 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *   1. Redistributions of source code must retain the above copyright
- *      notice, this list of conditions, and the following disclaimer.
- *   2. Redistributions in binary form must reproduce the above
- *      copyright notice, this list of conditions, and the following
- *      disclaimer in the documentation and/or other materials provided
- *      with the distribution.
- *   3. Redistributions must acknowledge that this software was
- *      originally developed by the UCSF Computer Graphics Laboratory
- *      under support by the NIH National Center for Research Resources,
- *      grant P41-RR01081.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
- * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-package coreCommands.namespaces;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import cytoscape.CyNetwork;
-import cytoscape.CyNode;
-import cytoscape.Cytoscape;
-import cytoscape.command.CyCommandException;
-import cytoscape.command.CyCommandHandler;
-import cytoscape.command.CyCommandManager;
-import cytoscape.command.CyCommandNamespace;
-import cytoscape.command.CyCommandResult;
-import cytoscape.data.CyAttributes;
-import cytoscape.layout.Tunable;
-
-/**
- * The layout command handles all requests to layout the current network.
- * For efficiency reasons, this should be done assuming we're in headless
- * mode.
- */
-public abstract class AbstractCommand implements CyCommandHandler {
-       protected Map<String, List<Tunable>> settingsMap = null;
-       protected CyCommandNamespace namespace = null;
-
-       /**
-        * Override if this handler supports subcommands
-        */
-       public List<String> getCommands() { return new 
ArrayList(settingsMap.keySet()); }
-
-       /**
-        * Override to return the arguments supported for a specific command
-        */
-       public List<String> getArguments(String command) { 
-               if (!settingsMap.containsKey(command)) {
-                       return null;
-               }
-
-               List<String> argList = new ArrayList();
-               for (Tunable t: settingsMap.get(command)) {
-                       argList.add(t.getName());
-               }
-               return argList;
-       }
-
-       /**
-        * Override to return the current values for a specific command
-        */
-       public Map<String, Object> getSettings(String command) { 
-               Map<String, Object> kvSettings = createKVSettings(command);
-               if (kvSettings != null)
-                       return kvSettings;
-               return null;
-       }
-
-       /**
-        * Override to return the Tunables supported for a specific command
-        */
-       public Map<String, Tunable> getTunables(String command) { 
-               if (settingsMap.containsKey(command)) {
-                       Map<String, Tunable> tunableMap = new HashMap();
-                       for (Tunable t: settingsMap.get(command)) {
-                               tunableMap.put(t.getName(), t);
-                       }
-                       return tunableMap;
-               }
-               return null;
-       }
-
-       /**
-        * Override if the commands support Tunables directly (recommended)
-        */
-       public CyCommandResult execute(String command, Collection<Tunable>args) 
throws CyCommandException { 
-               return execute(command, createKVMap(args));
-       }
-
-       protected void addSetting(String command) {
-               if (settingsMap == null)
-                       settingsMap = new HashMap();
-               if (!settingsMap.containsKey(command)) {
-                       settingsMap.put(command, new ArrayList());
-                       CyCommandManager.register(namespace, command, 
(CyCommandHandler)this);
-               } 
-       }
-
-       protected void addSetting(String command, String vKey) {
-               addSetting(command, vKey, null);
-       }
-
-       protected void addSetting(String command, String vKey, String value) {
-               Tunable t = new Tunable(vKey, vKey, Tunable.STRING, value);
-               addSetting(command, t);
-       }
-
-       protected void addSetting(String command, Tunable t) {
-               if (settingsMap == null)
-                       settingsMap = new HashMap();
-               
-               if (!settingsMap.containsKey(command)) {
-                       settingsMap.put(command, new ArrayList());
-                       CyCommandManager.register(namespace, command, this);
-               }
-
-               List<Tunable> tList = settingsMap.get(command);
-               tList.add(t);
-       }
-
-       /**
-        * This method is useful for converting from Tunable lists to key-value 
settings
-        */
-       protected       Map<String, Object> createKVSettings(String command) {
-               if (!settingsMap.containsKey(command)) return null;
-               return createKVMap(settingsMap.get(command));
-       }
-
-       protected Map<String, Object> createKVMap(Collection<Tunable> tList) {
-               Map<String, Object> kvSettings = new HashMap();
-               for (Tunable t: tList) {
-                       Object v = t.getValue();
-                       if (v != null)
-                               kvSettings.put(t.getName(), v.toString());
-                       else
-                               kvSettings.put(t.getName(), null);
-               }
-               return kvSettings;
-       }
-
-       /**
-        * Some additional utility routines
-        */
-
-       protected String getArg(String command, String key, 
Map<String,Object>args) {
-               // Do we have the key in our settings map?
-               String value = null;
-
-               if (settingsMap.containsKey(command)) {
-                       List<Tunable> tL = settingsMap.get(command);
-                       for (Tunable t: tL) {
-                               if (t.getName().equals(key)) {
-                                       Object v = t.getValue();
-                                       if (v != null)
-                                               value = v.toString();
-                                       break;
-                               }
-                       }
-               }
-
-               if (args == null || args.size() == 0 || !args.containsKey(key))
-                       return value;
-
-               return args.get(key).toString();
-       }
-
-       protected static List<CyNode> getNodeList(CyNetwork net, 
CyCommandResult result, 
-                                                 Map<String, Object> args) {
-               if (args == null || args.size() == 0)
-                       return null;
-
-               List<CyNode> retList = new ArrayList();
-               if (args.containsKey("nodelist")) {
-                       String[] nodes = 
args.get("nodelist").toString().split(",");
-                       for (int nodeIndex = 0; nodeIndex < nodes.length; 
nodeIndex++) {
-                               addNode(net, nodes[nodeIndex], retList, result);
-                       }
-               } else if (args.containsKey("node")) {
-                       String nodeName = args.get("node").toString();
-                       addNode(net, nodeName, retList, result);
-               } else {
-                       return null;
-               }
-               return retList;
-       }
-
-       protected static void addNode(CyNetwork net, String nodeName, 
List<CyNode> list, CyCommandResult result) {
-               CyNode node = Cytoscape.getCyNode(nodeName, false);
-               if (node == null) 
-                       result.addError("node: can't find node "+nodeName);
-               else
-                       list.add(node);
-               return;
-       }
-
-}

Modified: 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/AttributeUtils.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/AttributeUtils.java
   2009-11-24 23:10:36 UTC (rev 18571)
+++ 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/AttributeUtils.java
   2009-11-24 23:17:49 UTC (rev 18572)
@@ -37,6 +37,7 @@
 import cytoscape.data.CyAttributes;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;

Modified: 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/EdgeNamespace.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/EdgeNamespace.java
    2009-11-24 23:10:36 UTC (rev 18571)
+++ 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/EdgeNamespace.java
    2009-11-24 23:17:49 UTC (rev 18572)
@@ -35,6 +35,7 @@
 import cytoscape.CyEdge;
 import cytoscape.CyNetwork;
 import cytoscape.Cytoscape;
+import cytoscape.command.AbstractCommand;
 import cytoscape.command.CyCommandException;
 import cytoscape.command.CyCommandHandler;
 import cytoscape.command.CyCommandManager;
@@ -76,26 +77,25 @@
        private static String VALUE = "value";
 
        protected EdgeNamespace(CyCommandNamespace ns) {
-               this.namespace = ns;
+               super(ns);
 
                // Define our subcommands
-               settingsMap = new HashMap();
-               addSetting(DESELECT, EDGE);
-               addSetting(DESELECT, EDGELIST);
-               // addSetting("export attributes", "file");
-               // addSetting("export attributes", "attribute");
-               // addSetting("find", "expression");
-               addSetting(GETATTR, EDGE);
-               addSetting(GETATTR, EDGELIST);
-               addSetting(GETATTR, NAME);
-               addSetting(GETSEL, NETWORK, "current");
-               addSetting(IMPORTATTR, FILE);
-               addSetting(SELECT, EDGE);
-               addSetting(SELECT, EDGELIST);
-               addSetting(SETATTR, EDGE);
-               addSetting(SETATTR, EDGELIST);
-               addSetting(SETATTR, NAME);
-               addSetting(SETATTR, VALUE);
+               addArgument(DESELECT, EDGE);
+               addArgument(DESELECT, EDGELIST);
+               // addArgument("export attributes", "file");
+               // addArgument("export attributes", "attribute");
+               // addArgument("find", "expression");
+               addArgument(GETATTR, EDGE);
+               addArgument(GETATTR, EDGELIST);
+               addArgument(GETATTR, NAME);
+               addArgument(GETSEL, NETWORK, "current");
+               addArgument(IMPORTATTR, FILE);
+               addArgument(SELECT, EDGE);
+               addArgument(SELECT, EDGELIST);
+               addArgument(SETATTR, EDGE);
+               addArgument(SETATTR, EDGELIST);
+               addArgument(SETATTR, NAME);
+               addArgument(SETATTR, VALUE);
 
                // Handle table import????
        }
@@ -109,6 +109,10 @@
         */
        public String getHandlerName() { return EDGE; }
 
+       public CyCommandResult execute(String command, Collection<Tunable>args) 
throws CyCommandException {
+               return execute(command, createKVMap(args));
+       }
+
        public CyCommandResult execute(String command, Map<String, Object>args) 
throws CyCommandException { 
                CyCommandResult result = new CyCommandResult();
 

Modified: 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/LayoutNamespace.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/LayoutNamespace.java
  2009-11-24 23:10:36 UTC (rev 18571)
+++ 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/LayoutNamespace.java
  2009-11-24 23:17:49 UTC (rev 18572)
@@ -33,6 +33,7 @@
 package coreCommands.namespaces;
 
 import cytoscape.Cytoscape;
+import cytoscape.command.AbstractCommand;
 import cytoscape.command.CyCommandException;
 import cytoscape.command.CyCommandHandler;
 import cytoscape.command.CyCommandManager;
@@ -47,6 +48,7 @@
 import cytoscape.view.CyNetworkView;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -61,24 +63,23 @@
        private static String DEFAULT = "default";
 
        protected LayoutNamespace(CyCommandNamespace ns) {
-               this.namespace = ns;
+               super(ns);
 
                // Define our subcommands
-               settingsMap = new HashMap();
-               addSetting(GETCURRENT);
-               addSetting(GETDEFAULT);
-               addSetting(DEFAULT);
+               addArgument(GETCURRENT);
+               addArgument(GETDEFAULT);
+               addArgument(DEFAULT);
 
                // Get the list of layouts from the layout manager
                for (CyLayoutAlgorithm alg: CyLayouts.getAllLayouts()) {
                        String layout = alg.getName();
                        LayoutProperties props = alg.getSettings();
                        if (props == null) {
-                               addSetting(layout);
+                               addArgument(layout);
                                continue;
                        }
                        for (Tunable t: props.getTunables())
-                               addSetting(layout, t);
+                               addArgument(layout, t);
                }
        }
 
@@ -91,6 +92,10 @@
         */
        public String getHandlerName() { return LAYOUT; }
 
+       public CyCommandResult execute(String command, Collection<Tunable>args) 
throws CyCommandException {
+               return execute(command, createKVMap(args));
+       }
+
        public CyCommandResult execute(String command, Map<String, Object>args) 
throws CyCommandException { 
                CyCommandResult result = new CyCommandResult();
 

Modified: 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/NetworkNamespace.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/NetworkNamespace.java
 2009-11-24 23:10:36 UTC (rev 18571)
+++ 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/NetworkNamespace.java
 2009-11-24 23:17:49 UTC (rev 18572)
@@ -35,6 +35,7 @@
 import cytoscape.CyNetwork;
 import cytoscape.Cytoscape;
 
+import cytoscape.command.AbstractCommand;
 import cytoscape.command.CyCommandException;
 import cytoscape.command.CyCommandHandler;
 import cytoscape.command.CyCommandManager;
@@ -50,6 +51,7 @@
 import cytoscape.view.CyNetworkView;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -79,14 +81,13 @@
        static String TYPE = "type";
 
        protected NetworkNamespace(CyCommandNamespace ns) {
-               this.namespace = ns;
+               super(ns);
 
                // Define our subcommands
-               settingsMap = new HashMap();
-               addSetting(DESTROY, NAME);
-               addSetting(GETCURRENT);
-               addSetting(LIST);
-               addSetting(MAKECURRENT, NAME);
+               addArgument(DESTROY, NAME);
+               addArgument(GETCURRENT);
+               addArgument(LIST);
+               addArgument(MAKECURRENT, NAME);
        }
 
 
@@ -98,6 +99,10 @@
         */
        public String getHandlerName() { return NETWORK; }
 
+       public CyCommandResult execute(String command, Collection<Tunable>args) 
throws CyCommandException {
+               return execute(command, createKVMap(args));
+       }
+
        public CyCommandResult execute(String command, Map<String, Object>args) 
throws CyCommandException { 
                CyCommandResult result = new CyCommandResult();
 

Modified: 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/NetworkViewNamespace.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/NetworkViewNamespace.java
     2009-11-24 23:10:36 UTC (rev 18571)
+++ 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/NetworkViewNamespace.java
     2009-11-24 23:17:49 UTC (rev 18572)
@@ -37,6 +37,7 @@
 import cytoscape.CyNode;
 import cytoscape.Cytoscape;
 import cytoscape.CytoscapeInit;
+import cytoscape.command.AbstractCommand;
 import cytoscape.command.CyCommandException;
 import cytoscape.command.CyCommandHandler;
 import cytoscape.command.CyCommandManager;
@@ -49,6 +50,7 @@
 import cytoscape.view.InternalFrameComponent;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -78,27 +80,26 @@
        static String SCALE = "scale";
 
        public NetworkViewNamespace(CyCommandNamespace ns) {
-               this.namespace = ns;
+               super(ns);
 
                // Define our subcommands
-               settingsMap = new HashMap();
-               addSetting(CREATE, NETWORK, CURRENT);
-               addSetting(GETCURRENT);
-               // addSetting("get size", "network", "current");
-               addSetting(FIT, NETWORK, CURRENT);
-               addSetting(FOCUS, NODELIST);
-               addSetting(FOCUS, NETWORK, CURRENT);
-               addSetting(LIST);
-               addSetting(MAKECURRENT, NETWORK);
-               // addSetting("set window", "network", "current");
-               // addSetting("set window", "x");
-               // addSetting("set window", "y");
-               // addSetting("set window", "height");
-               // addSetting("set window", "width");
-               addSetting(UPDATE, NETWORK, CURRENT);
-               addSetting(ZOOM, FACTOR, "2.0");
-               addSetting(ZOOM, SCALE);
-               addSetting(ZOOM, NETWORK, CURRENT);
+               addArgument(CREATE, NETWORK, CURRENT);
+               addArgument(GETCURRENT);
+               // addArgument("get size", "network", "current");
+               addArgument(FIT, NETWORK, CURRENT);
+               addArgument(FOCUS, NODELIST);
+               addArgument(FOCUS, NETWORK, CURRENT);
+               addArgument(LIST);
+               addArgument(MAKECURRENT, NETWORK);
+               // addArgument("set window", "network", "current");
+               // addArgument("set window", "x");
+               // addArgument("set window", "y");
+               // addArgument("set window", "height");
+               // addArgument("set window", "width");
+               addArgument(UPDATE, NETWORK, CURRENT);
+               addArgument(ZOOM, FACTOR, "2.0");
+               addArgument(ZOOM, SCALE);
+               addArgument(ZOOM, NETWORK, CURRENT);
        }
 
 
@@ -110,6 +111,10 @@
         */
        public String getHandlerName() { return NETWORKVIEW; }
 
+       public CyCommandResult execute(String command, Collection<Tunable>args) 
throws CyCommandException {
+               return execute(command, createKVMap(args));
+       }
+
        public CyCommandResult execute(String command, Map<String, Object>args) 
throws CyCommandException { 
                CyCommandResult result = new CyCommandResult();
                Map<String, CyNetworkView> viewMap = 
Cytoscape.getNetworkViewMap();
@@ -169,7 +174,7 @@
                                result.addMessage("networkview: focused 
'"+net.getIdentifier()+"' on selected nodes/edges");
                        } else {
                                // get the list of nodes
-                               List<CyNode> nodeList = getNodeList(net, 
result, args);
+                               List<CyNode> nodeList = 
NodeListUtils.getNodeList(net, result, args);
 
                                // Remember our currently selected nodes and 
edges
                                List<CyNode>selNodes = new 
ArrayList(net.getSelectedNodes());

Added: 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/NodeListUtils.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/NodeListUtils.java
                            (rev 0)
+++ 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/NodeListUtils.java
    2009-11-24 23:17:49 UTC (rev 18572)
@@ -0,0 +1,90 @@
+/* vim: set ts=2: */
+/**
+ * Copyright (c) 2007 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions, and the following disclaimer.
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions, and the following
+ *      disclaimer in the documentation and/or other materials provided
+ *      with the distribution.
+ *   3. Redistributions must acknowledge that this software was
+ *      originally developed by the UCSF Computer Graphics Laboratory
+ *      under support by the NIH National Center for Research Resources,
+ *      grant P41-RR01081.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+package coreCommands.namespaces;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import cytoscape.CyNetwork;
+import cytoscape.CyNode;
+import cytoscape.Cytoscape;
+import cytoscape.command.CyCommandResult;
+
+/**
+ * This is a utility class that contains some methods that help with the 
handling of
+ * node and node list parameters.  A node list is denoted by the key 
<b>nodelist</b>
+ * and the a string value with a simple comma-separated list of node 
identifiers.  A 
+ * node is denoted by the key <b>node</b> and a single node identifier.
+ */
+public class NodeListUtils {
+
+       /**
+        * This method is used to handle both <b>nodelist</b> and <b>node</b> 
parameters.
+        *
+        * @param net the network we are currently dealing with
+        * @param result the CyCommandResult to store our values in
+        * @param args the argument list we're use to look for <b>nodelist</b> 
and
+        * <b>node</b> arguments.
+        * @return the list of CyNode objects we found that matched the 
arguments
+        */
+       public static List<CyNode> getNodeList(CyNetwork net, CyCommandResult 
result, 
+                                                 Map<String, Object> args) {
+               if (args == null || args.size() == 0)
+                       return null;
+
+               List<CyNode> retList = new ArrayList();
+               if (args.containsKey("nodelist")) {
+                       String[] nodes = 
args.get("nodelist").toString().split(",");
+                       for (int nodeIndex = 0; nodeIndex < nodes.length; 
nodeIndex++) {
+                               addNode(net, nodes[nodeIndex], retList, result);
+                       }
+               } else if (args.containsKey("node")) {
+                       String nodeName = args.get("node").toString();
+                       addNode(net, nodeName, retList, result);
+               } else {
+                       return null;
+               }
+               return retList;
+       }
+
+       private static void addNode(CyNetwork net, String nodeName, 
List<CyNode> list, CyCommandResult result) {
+               CyNode node = Cytoscape.getCyNode(nodeName, false);
+               if (node == null) 
+                       result.addError("node: can't find node "+nodeName);
+               else
+                       list.add(node);
+               return;
+       }
+
+}

Modified: 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/NodeNamespace.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/NodeNamespace.java
    2009-11-24 23:10:36 UTC (rev 18571)
+++ 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/NodeNamespace.java
    2009-11-24 23:17:49 UTC (rev 18572)
@@ -35,6 +35,7 @@
 import cytoscape.CyNetwork;
 import cytoscape.CyNode;
 import cytoscape.Cytoscape;
+import cytoscape.command.AbstractCommand;
 import cytoscape.command.CyCommandException;
 import cytoscape.command.CyCommandHandler;
 import cytoscape.command.CyCommandManager;
@@ -76,27 +77,26 @@
        private static String TYPE = "type";
 
        public NodeNamespace(CyCommandNamespace ns) {
-               this.namespace = ns;
+               super(ns);
 
                // Define our subcommands
-               settingsMap = new HashMap();
-               addSetting(DESELECT, NODE);
-               addSetting(DESELECT, NODELIST);
-               // addSetting("export attributes", "file");
-               // addSetting("export attributes", "attribute");
-               // addSetting("find", "expression");
-               addSetting(GETATTR, NODE);
-               addSetting(GETATTR, NODELIST);
-               addSetting(GETATTR, NAME);
-               addSetting(GETSEL, NETWORK, "current");
-               addSetting(IMPORTATTR, FILE);
-               addSetting(SELECT, NODE);
-               addSetting(SELECT, NODELIST);
-               addSetting(SETATTR, NODE);
-               addSetting(SETATTR, NODELIST);
-               addSetting(SETATTR, NAME);
-               addSetting(SETATTR, VALUE);
-               addSetting(SETATTR, TYPE);
+               addArgument(DESELECT, NODE);
+               addArgument(DESELECT, NODELIST);
+               // addArgument("export attributes", "file");
+               // addArgument("export attributes", "attribute");
+               // addArgument("find", "expression");
+               addArgument(GETATTR, NODE);
+               addArgument(GETATTR, NODELIST);
+               addArgument(GETATTR, NAME);
+               addArgument(GETSEL, NETWORK, "current");
+               addArgument(IMPORTATTR, FILE);
+               addArgument(SELECT, NODE);
+               addArgument(SELECT, NODELIST);
+               addArgument(SETATTR, NODE);
+               addArgument(SETATTR, NODELIST);
+               addArgument(SETATTR, NAME);
+               addArgument(SETATTR, VALUE);
+               addArgument(SETATTR, TYPE);
        }
 
 
@@ -108,6 +108,10 @@
         */
        public String getHandlerName() { return NODE; }
 
+       public CyCommandResult execute(String command, Collection<Tunable>args) 
throws CyCommandException {
+               return execute(command, createKVMap(args));
+       }
+
        public CyCommandResult execute(String command, Map<String, Object>args) 
throws CyCommandException { 
                CyCommandResult result = new CyCommandResult();
 
@@ -131,7 +135,7 @@
                // Select some ndoes
                } else if (SELECT.equals(command)) {
                        CyNetwork net = getNetwork(command, args);
-                       List<CyNode> nodeList = getNodeList(net, result, args);
+                       List<CyNode> nodeList = NodeListUtils.getNodeList(net, 
result, args);
                        if (nodeList == null)
                                throw new CyCommandException("node: nothing to 
select");
                        net.setSelectedNodeState(nodeList, true);
@@ -144,7 +148,7 @@
                } else if (DESELECT.equals(command)) {
                        CyNetwork net = getNetwork(command, args);
                        try {
-                               List<CyNode> nodeList = getNodeList(net, 
result, args);
+                               List<CyNode> nodeList = 
NodeListUtils.getNodeList(net, result, args);
                                if (nodeList == null)
                                        throw new CyCommandException("node: 
nothing to deselect");
 
@@ -177,7 +181,7 @@
                        else if (nodeAttributes.getType(attrName) == 
CyAttributes.TYPE_UNDEFINED)
                                throw new CyCommandException("node: attribute 
'name' does not exist");
 
-                       List<CyNode> nodeList = getNodeList(net, result, args);
+                       List<CyNode> nodeList = NodeListUtils.getNodeList(net, 
result, args);
                        if (nodeList == null)
                                nodeList = net.nodesList();
 
@@ -201,7 +205,7 @@
                        if (attrName == null || value == null)
                                throw new CyCommandException("node: attribute 
'name' and 'value' are required");
 
-                       List<CyNode> nodeList = getNodeList(net, result, args);
+                       List<CyNode> nodeList = NodeListUtils.getNodeList(net, 
result, args);
                        if (nodeList == null)
                                nodeList = net.nodesList();
 

Modified: 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/PropertyNamespace.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/PropertyNamespace.java
        2009-11-24 23:10:36 UTC (rev 18571)
+++ 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/PropertyNamespace.java
        2009-11-24 23:17:49 UTC (rev 18572)
@@ -34,6 +34,7 @@
 
 import cytoscape.Cytoscape;
 import cytoscape.CytoscapeInit;
+import cytoscape.command.AbstractCommand;
 import cytoscape.command.CyCommandException;
 import cytoscape.command.CyCommandHandler;
 import cytoscape.command.CyCommandManager;
@@ -44,6 +45,7 @@
 import cytoscape.view.CyNetworkView;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -63,14 +65,13 @@
        static String VALUE = "value";
 
        public PropertyNamespace(CyCommandNamespace ns) {
-               this.namespace = ns;
+               super(ns);
 
                // Define our subcommands
-               settingsMap = new HashMap();
-               addSetting(SET, NAME);
-               addSetting(SET, VALUE);
-               addSetting(GET, NAME);
-               addSetting(CLEAR, NAME);
+               addArgument(SET, NAME);
+               addArgument(SET, VALUE);
+               addArgument(GET, NAME);
+               addArgument(CLEAR, NAME);
        }
 
 
@@ -82,6 +83,10 @@
         */
        public String getHandlerName() { return PROPERTY; }
 
+       public CyCommandResult execute(String command, Collection<Tunable>args) 
throws CyCommandException {
+               return execute(command, createKVMap(args));
+       }
+
        public CyCommandResult execute(String command, Map<String, Object>args) 
throws CyCommandException { 
                CyCommandResult result = new CyCommandResult();
                Properties props = CytoscapeInit.getProperties();

Modified: 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/QuitNamespace.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/QuitNamespace.java
    2009-11-24 23:10:36 UTC (rev 18571)
+++ 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/QuitNamespace.java
    2009-11-24 23:17:49 UTC (rev 18572)
@@ -34,6 +34,7 @@
 
 import cytoscape.Cytoscape;
 import cytoscape.CytoscapeInit;
+import cytoscape.command.AbstractCommand;
 import cytoscape.command.CyCommandException;
 import cytoscape.command.CyCommandHandler;
 import cytoscape.command.CyCommandManager;
@@ -44,6 +45,7 @@
 import cytoscape.view.CyNetworkView;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -55,8 +57,8 @@
 public class QuitNamespace extends AbstractCommand {
 
        public QuitNamespace(CyCommandNamespace ns) {
-               this.namespace = ns;
-               addSetting("");
+               super(ns);
+               addArgument("");
        }
 
 
@@ -68,11 +70,14 @@
         */
        public String getHandlerName() { return namespace.getNamespaceName(); }
 
+       public CyCommandResult execute(String command, Collection<Tunable>args) 
throws CyCommandException {
+               System.exit(0);
+               return null;
+       }
+
        public CyCommandResult execute(String command, Map<String, Object>args) 
throws CyCommandException { 
-               CyCommandResult result = new CyCommandResult();
-
                System.exit(0);
-               return result;
+               return null;
        }
 
        public static CyCommandHandler register(String namespace) throws 
RuntimeException {

Modified: 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/SessionNamespace.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/SessionNamespace.java
 2009-11-24 23:10:36 UTC (rev 18571)
+++ 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/SessionNamespace.java
 2009-11-24 23:17:49 UTC (rev 18572)
@@ -33,6 +33,7 @@
 package coreCommands.namespaces;
 
 import cytoscape.Cytoscape;
+import cytoscape.command.AbstractCommand;
 import cytoscape.command.CyCommandException;
 import cytoscape.command.CyCommandHandler;
 import cytoscape.command.CyCommandManager;
@@ -47,6 +48,7 @@
 import java.io.File;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -64,12 +66,12 @@
        static String FILE = "file";
 
        public SessionNamespace(CyCommandNamespace ns) {
-               this.namespace = ns;
+               super(ns);
+
                // Define our subcommands
-               settingsMap = new HashMap();
-               addSetting(OPEN, FILE);
-               addSetting(NEW);
-               addSetting(SAVE, FILE);
+               addArgument(OPEN, FILE);
+               addArgument(NEW);
+               addArgument(SAVE, FILE);
        }
 
 
@@ -81,6 +83,10 @@
         */
        public String getHandlerName() { return SESSION; }
 
+       public CyCommandResult execute(String command, Collection<Tunable>args) 
throws CyCommandException {
+               return execute(command, createKVMap(args));
+       }
+
        public CyCommandResult execute(String command, Map<String, Object>args) 
throws CyCommandException { 
                CyCommandResult result = new CyCommandResult();
 

Modified: 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/VizMapNamespace.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/VizMapNamespace.java
  2009-11-24 23:10:36 UTC (rev 18571)
+++ 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/VizMapNamespace.java
  2009-11-24 23:17:49 UTC (rev 18572)
@@ -33,6 +33,7 @@
 package coreCommands.namespaces;
 
 import cytoscape.Cytoscape;
+import cytoscape.command.AbstractCommand;
 import cytoscape.command.CyCommandException;
 import cytoscape.command.CyCommandHandler;
 import cytoscape.command.CyCommandManager;
@@ -47,6 +48,7 @@
 
 import java.io.File;
 
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -67,13 +69,12 @@
        static String FILE = "file";
 
        public VizMapNamespace(CyCommandNamespace ns) {
-               this.namespace = ns;
+               super(ns);
 
                // Define our subcommands
-               settingsMap = new HashMap();
-               addSetting(APPLY, STYLE, "default");
+               addArgument(APPLY, STYLE, "default");
 
-               addSetting(IMPORT, FILE, null);
+               addArgument(IMPORT, FILE, null);
        }
 
 
@@ -85,6 +86,10 @@
         */
        public String getHandlerName() { return VIZMAP; }
 
+       public CyCommandResult execute(String command, Collection<Tunable>args) 
throws CyCommandException {
+               return execute(command, createKVMap(args));
+       }
+
        public CyCommandResult execute(String command, Map<String, Object>args) 
throws CyCommandException { 
                CyCommandResult result = new CyCommandResult();
                if (command.equals(STYLE)) {

Modified: 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/network/CreateNetwork.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/network/CreateNetwork.java
    2009-11-24 23:10:36 UTC (rev 18571)
+++ 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/network/CreateNetwork.java
    2009-11-24 23:17:49 UTC (rev 18572)
@@ -35,6 +35,7 @@
 import cytoscape.CyNetwork;
 import cytoscape.Cytoscape;
 
+import cytoscape.command.AbstractCommand;
 import cytoscape.command.CyCommandException;
 import cytoscape.command.CyCommandHandler;
 import cytoscape.command.CyCommandNamespace;
@@ -44,12 +45,11 @@
 import cytoscape.logger.CyLogger;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import coreCommands.namespaces.AbstractCommand;
-
 /**
  * XXX FIXME XXX Description 
  */
@@ -65,13 +65,12 @@
        static String PARENT = "parent";
 
        public CreateNetwork(CyCommandNamespace ns) {
-               this.namespace = ns;
+               super(ns);
 
                // Define our subcommands
-               settingsMap = new HashMap();
-               addSetting(CREATE, NAME, "NewNetwork");
-               addSetting(CREATE, CREATEVIEW, "true");
-               addSetting(CREATE, PARENT);
+               addArgument(CREATE, NAME, "NewNetwork");
+               addArgument(CREATE, CREATEVIEW, "true");
+               addArgument(CREATE, PARENT);
        }
 
 
@@ -83,6 +82,10 @@
         */
        public String getHandlerName() { return CREATE; }
 
+       public CyCommandResult execute(String command, Collection<Tunable>args) 
throws CyCommandException {
+               return execute(command, createKVMap(args));
+       }
+
        public CyCommandResult execute(String command, Map<String, Object>args) 
throws CyCommandException { 
                CyCommandResult result = new CyCommandResult();
 

Modified: 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/network/ExportNetwork.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/network/ExportNetwork.java
    2009-11-24 23:10:36 UTC (rev 18571)
+++ 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/network/ExportNetwork.java
    2009-11-24 23:17:49 UTC (rev 18572)
@@ -35,6 +35,7 @@
 import cytoscape.CyNetwork;
 import cytoscape.Cytoscape;
 
+import cytoscape.command.AbstractCommand;
 import cytoscape.command.CyCommandException;
 import cytoscape.command.CyCommandHandler;
 import cytoscape.command.CyCommandNamespace;
@@ -55,12 +56,11 @@
 import java.io.FileWriter;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import coreCommands.namespaces.AbstractCommand;
-
 /**
  * XXX FIXME XXX Description 
  */
@@ -83,13 +83,12 @@
        static String SIF = "sif";
 
        public ExportNetwork(CyCommandNamespace ns) {
-               this.namespace = ns;
+               super(ns);
 
                // Define our subcommands
-               settingsMap = new HashMap();
-               addSetting(EXPORT, NAME , CURRENT);
-               addSetting(EXPORT, FILE);
-               addSetting(EXPORT, TYPE, XGMML);
+               addArgument(EXPORT, NAME , CURRENT);
+               addArgument(EXPORT, FILE);
+               addArgument(EXPORT, TYPE, XGMML);
        }
 
 
@@ -101,6 +100,10 @@
         */
        public String getHandlerName() { return EXPORT; }
 
+       public CyCommandResult execute(String command, Collection<Tunable>args) 
throws CyCommandException {
+               return execute(command, createKVMap(args));
+       }
+
        public CyCommandResult execute(String command, Map<String, Object>args) 
throws CyCommandException { 
                CyCommandResult result = new CyCommandResult();
 

Modified: 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/network/ImportNetwork.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/network/ImportNetwork.java
    2009-11-24 23:10:36 UTC (rev 18571)
+++ 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/network/ImportNetwork.java
    2009-11-24 23:17:49 UTC (rev 18572)
@@ -35,6 +35,7 @@
 import cytoscape.CyNetwork;
 import cytoscape.Cytoscape;
 
+import cytoscape.command.AbstractCommand;
 import cytoscape.command.CyCommandException;
 import cytoscape.command.CyCommandHandler;
 import cytoscape.command.CyCommandNamespace;
@@ -54,12 +55,11 @@
 import java.net.URI;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import coreCommands.namespaces.AbstractCommand;
-
 /**
  * XXX FIXME XXX Description 
  */
@@ -82,13 +82,12 @@
        static String SIF = "sif";
 
        public ImportNetwork(CyCommandNamespace ns) {
-               this.namespace = ns;
+               super(ns);
 
                // Define our subcommands
-               settingsMap = new HashMap();
-               addSetting(IMPORT, FILE);
-               addSetting(IMPORT, CREATEVIEW, "true");
-               addSetting(IMPORT, PARENT);
+               addArgument(IMPORT, FILE);
+               addArgument(IMPORT, CREATEVIEW, "true");
+               addArgument(IMPORT, PARENT);
        }
 
 
@@ -100,6 +99,10 @@
         */
        public String getHandlerName() { return IMPORT; }
 
+       public CyCommandResult execute(String command, Collection<Tunable>args) 
throws CyCommandException {
+               return execute(command, createKVMap(args));
+       }
+
        public CyCommandResult execute(String command, Map<String, Object>args) 
throws CyCommandException { 
                CyCommandResult result = new CyCommandResult();
 

Modified: 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/networkView/ExportNetworkView.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/networkView/ExportNetworkView.java
    2009-11-24 23:10:36 UTC (rev 18571)
+++ 
csplugins/trunk/ucsf/scooter/coreCommands/src/coreCommands/namespaces/networkView/ExportNetworkView.java
    2009-11-24 23:17:49 UTC (rev 18572)
@@ -37,6 +37,8 @@
 import cytoscape.CyNode;
 import cytoscape.Cytoscape;
 import cytoscape.CytoscapeInit;
+
+import cytoscape.command.AbstractCommand;
 import cytoscape.command.CyCommandException;
 import cytoscape.command.CyCommandHandler;
 import cytoscape.command.CyCommandManager;
@@ -58,14 +60,14 @@
 
 import java.io.File;
 import java.io.FileOutputStream;
+
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import coreCommands.namespaces.AbstractCommand;
-
 /**
  * XXX FIXME XXX Description 
  */
@@ -89,14 +91,13 @@
        private static String BMP = "bmp";
 
        public ExportNetworkView(CyCommandNamespace ns) {
-               this.namespace = ns;
+               super(ns);
 
                // Define our subcommands
-               settingsMap = new HashMap();
-               addSetting(EXPORT, FILE);
-               addSetting(EXPORT, NETWORK, CURRENT);
-               addSetting(EXPORT, TYPE, PNG);
-               addSetting(EXPORT, ZOOM, "1.0");
+               addArgument(EXPORT, FILE);
+               addArgument(EXPORT, NETWORK, CURRENT);
+               addArgument(EXPORT, TYPE, PNG);
+               addArgument(EXPORT, ZOOM, "1.0");
        }
 
 
@@ -108,6 +109,10 @@
         */
        public String getHandlerName() { return EXPORT; }
 
+       public CyCommandResult execute(String command, Collection<Tunable>args) 
throws CyCommandException {
+               return execute(command, createKVMap(args));
+       }
+
        public CyCommandResult execute(String command, Map<String, Object>args) 
throws CyCommandException { 
                CyCommandResult result = new CyCommandResult();
                Map<String, CyNetworkView> viewMap = 
Cytoscape.getNetworkViewMap();

--

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