Author: mes
Date: 2012-03-14 17:33:09 -0700 (Wed, 14 Mar 2012)
New Revision: 28543

Added:
   
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/NVTFExcutor.java
   
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/TTFExecutor.java
Modified:
   
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/CommandExecutorImpl.java
   
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/CommandExecutorTask.java
   
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/CyActivator.java
   
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/Executor.java
   
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/NTFExecutor.java
   
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/TFExecutor.java
Log:
updated executor to function with more task factory types and to propagate 
exceptions

Modified: 
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/CommandExecutorImpl.java
===================================================================
--- 
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/CommandExecutorImpl.java
        2012-03-14 23:57:32 UTC (rev 28542)
+++ 
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/CommandExecutorImpl.java
        2012-03-15 00:33:09 UTC (rev 28543)
@@ -11,8 +11,11 @@
 
 import org.cytoscape.work.TaskFactory;
 import org.cytoscape.task.NetworkTaskFactory;
+import org.cytoscape.task.NetworkViewTaskFactory;
+import org.cytoscape.task.TableTaskFactory;
 import org.cytoscape.application.CyApplicationManager;
 import org.cytoscape.command.internal.tunables.CommandTunableInterceptorImpl;
+import org.cytoscape.work.TaskMonitor;
 
 public class CommandExecutorImpl {
 
@@ -45,6 +48,22 @@
                removeTF(props);
        }
 
+       public void addNetworkViewTaskFactory(NetworkViewTaskFactory tf, Map 
props) {
+               addTF(new NVTFExecutor(tf,interceptor,appMgr), props);
+       }
+
+       public void removeNetworkViewTaskFactory(NetworkViewTaskFactory tf, Map 
props) {
+               removeTF(props);
+       }
+
+       public void addTableTaskFactory(TableTaskFactory tf, Map props) {
+               addTF(new TTFExecutor(tf,interceptor,appMgr), props);
+       }
+
+       public void removeTableTaskFactory(TableTaskFactory tf, Map props) {
+               removeTF(props);
+       }
+
        private void addTF(Executor ex, Map props) {
                String namespace = (String)props.get("commandNamespace");
                String command = (String)props.get("command");
@@ -88,37 +107,40 @@
                }
        }
 
-       public void executeList(List<String> commandLines) {
-               try {
+       public void executeList(List<String> commandLines, TaskMonitor tm) 
throws Exception {
 
-                       // begin iterating over the lines
-                       for ( String line : commandLines ) { 
-                               boolean finished = false;
-                               
-                               // match the namespace
-                               for ( String namespace : 
commandExecutorMap.keySet() ) {
-                                       if ( finished ) return;
+               double size = (double)commandLines.size();
+               double count = 1.0;
 
-                                       String commLine = peel( line, namespace 
);
-                                       if ( commLine != null ) {
-                                               Map<String,Executor> commandMap 
= commandExecutorMap.get(namespace);
-                                               if ( commandMap != null ) {
+               // begin iterating over the lines
+               for ( String line : commandLines ) { 
+                       boolean finished = false;
+                       
+                       tm.setStatusMessage("Executing command: '" + line + 
"'");
+                       logger.info("Executing command: '" + line + "'");
+                       // match the namespace
+                       for ( String namespace : commandExecutorMap.keySet() ) {
+                               if ( finished ) return;
 
-                                                       // now match and 
execute the command
-                                                       for ( String command : 
commandMap.keySet() ) {
-                                                               String args = 
peel( commLine, command );
-                                                               if ( args != 
null ) {
-                                                                       
commandMap.get(command).execute(args);
-                                                                       
finished = true;
-                                                                       break;
-                                                               }
+                               String commLine = peel( line, namespace + " " );
+                               if ( commLine != null ) {
+                                       Map<String,Executor> commandMap = 
commandExecutorMap.get(namespace);
+                                       if ( commandMap != null ) {
+
+                                               // now match and execute the 
command
+                                               for ( String command : 
commandMap.keySet() ) {
+                                                       String args = peel( 
commLine, command );
+                                                       if ( args != null ) {
+                                                               
commandMap.get(command).execute(args);
+                                                               finished = true;
+                                                               break;
                                                        }
                                                }
                                        }
                                }
                        }
-               } catch (Exception e) {
-                       logger.error("Command parsing error: ", e);
+                       tm.setProgress(count/size);
+                       count += 1.0;
                }
        }
 }

Modified: 
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/CommandExecutorTask.java
===================================================================
--- 
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/CommandExecutorTask.java
        2012-03-14 23:57:32 UTC (rev 28542)
+++ 
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/CommandExecutorTask.java
        2012-03-15 00:33:09 UTC (rev 28543)
@@ -61,7 +61,7 @@
                this.cei = cei;
        }
 
-       public void run(TaskMonitor e) throws Exception {
+       public void run(TaskMonitor tm) throws Exception {
         if (file == null)
             throw new NullPointerException("You must specify a non-null 
command file to load!");
 
@@ -70,15 +70,15 @@
 
                try {
 
-               fin = new FileReader(file);
-               bin = new BufferedReader(fin);
-               List<String> lines = new ArrayList<String>();
-               String s;
+                       fin = new FileReader(file);
+                       bin = new BufferedReader(fin);
+                       List<String> lines = new ArrayList<String>();
+                       String s;
 
-               while ((s = bin.readLine()) != null) 
-                       lines.add( s.trim() );
+                       while ((s = bin.readLine()) != null) 
+                               lines.add( s.trim() );
 
-               cei.executeList(lines);
+                       cei.executeList(lines,tm);
 
                } finally {
                        if ( bin != null )

Modified: 
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/CyActivator.java
===================================================================
--- 
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/CyActivator.java
        2012-03-14 23:57:32 UTC (rev 28542)
+++ 
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/CyActivator.java
        2012-03-15 00:33:09 UTC (rev 28543)
@@ -9,6 +9,8 @@
 import org.cytoscape.work.TaskFactory;
 
 import org.cytoscape.task.NetworkTaskFactory;
+import org.cytoscape.task.NetworkViewTaskFactory;
+import org.cytoscape.task.TableTaskFactory;
 import org.cytoscape.work.TaskFactory;
 import org.cytoscape.work.util.*;
 
@@ -44,6 +46,8 @@
 
                
registerServiceListener(bc,commandExecutorImpl,"addTaskFactory","removeTaskFactory",TaskFactory.class);
                
registerServiceListener(bc,commandExecutorImpl,"addNetworkTaskFactory","removeNetworkTaskFactory",NetworkTaskFactory.class);
+               
registerServiceListener(bc,commandExecutorImpl,"addNetworkViewTaskFactory","removeNetworkViewTaskFactory",NetworkViewTaskFactory.class);
+               
registerServiceListener(bc,commandExecutorImpl,"addTableTaskFactory","removeTableTaskFactory",TableTaskFactory.class);
 
                
registerServiceListener(bc,interceptor,"addTunableHandlerFactory","removeTunableHandlerFactory",StringTunableHandlerFactory.class);
 

Modified: 
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/Executor.java
===================================================================
--- 
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/Executor.java
   2012-03-14 23:57:32 UTC (rev 28542)
+++ 
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/Executor.java
   2012-03-15 00:33:09 UTC (rev 28543)
@@ -4,5 +4,5 @@
 
 
 interface Executor {
-       void execute(String args);
+       void execute(String args) throws Exception;
 }

Modified: 
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/NTFExecutor.java
===================================================================
--- 
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/NTFExecutor.java
        2012-03-14 23:57:32 UTC (rev 28542)
+++ 
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/NTFExecutor.java
        2012-03-15 00:33:09 UTC (rev 28543)
@@ -17,7 +17,7 @@
                this.appMgr = appMgr;
        }
 
-       public void execute(String args) {
+       public void execute(String args) throws Exception {
                ntf.setNetwork( appMgr.getCurrentNetwork() );
                super.execute(args);
        }

Added: 
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/NVTFExcutor.java
===================================================================
--- 
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/NVTFExcutor.java
                                (rev 0)
+++ 
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/NVTFExcutor.java
        2012-03-15 00:33:09 UTC (rev 28543)
@@ -0,0 +1,24 @@
+
+
+package org.cytoscape.command.internal;
+
+import org.cytoscape.task.NetworkViewTaskFactory;
+import org.cytoscape.application.CyApplicationManager;
+import org.cytoscape.command.internal.tunables.CommandTunableInterceptorImpl;
+
+class NVTFExecutor extends TFExecutor {
+       private final NetworkViewTaskFactory nvtf;
+       private final CyApplicationManager appMgr;
+
+       public NVTFExecutor(NetworkViewTaskFactory nvtf, 
CommandTunableInterceptorImpl interceptor, 
+                          CyApplicationManager appMgr) {
+               super(nvtf,interceptor);
+               this.nvtf = nvtf;
+               this.appMgr = appMgr;
+       }
+
+       public void execute(String args) throws Exception {
+               nvtf.setNetworkView( appMgr.getCurrentNetworkView() );
+               super.execute(args);
+       }
+}

Modified: 
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/TFExecutor.java
===================================================================
--- 
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/TFExecutor.java
 2012-03-14 23:57:32 UTC (rev 28542)
+++ 
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/TFExecutor.java
 2012-03-15 00:33:09 UTC (rev 28543)
@@ -21,32 +21,28 @@
                this.interceptor = interceptor;
        }
 
-       public void execute(String args) {
-               try {
-                       // TODO
-                       // At some point in the future, this code should be 
reorganized into
-                       // a proper TaskManager - that's really what's 
happening here.
-                       TaskIterator ti = tf.createTaskIterator();
-                       while (ti.hasNext()) {
-                               Task t = ti.next();
-                               interceptor.setConfigurationContext(args);
-                               interceptor.validateAndWriteBackTunables(t);
-                               t.run(tm);
-                       }
-               } catch (Exception e) {
-                       logger.warn("Task failed to execute",e);
+       public void execute(String args) throws Exception {
+               // TODO
+               // At some point in the future, this code should be reorganized 
into
+               // a proper TaskManager - that's really what's happening here.
+               TaskIterator ti = tf.createTaskIterator();
+               while (ti.hasNext()) {
+                       Task t = ti.next();
+                       interceptor.setConfigurationContext(args);
+                       interceptor.validateAndWriteBackTunables(t);
+                       t.run(tm);
                }
        }
 
        private class OutTaskMonitor implements TaskMonitor {
                public void setTitle(String title) {
-                       System.out.println("set title: " + title);
+                       //System.out.println("set title: " + title);
                }
                public void setProgress(double progress) {
-                       System.out.println("set progress: " + progress);
+                       //System.out.println("set progress: " + progress);
                }
                public void setStatusMessage(String statusMessage) {
-                       System.out.println("set statusMessage: " + 
statusMessage);
+                       //System.out.println("set statusMessage: " + 
statusMessage);
                }
 
        }

Added: 
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/TTFExecutor.java
===================================================================
--- 
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/TTFExecutor.java
                                (rev 0)
+++ 
core3/impl/trunk/command-executor-impl/src/main/java/org/cytoscape/command/internal/TTFExecutor.java
        2012-03-15 00:33:09 UTC (rev 28543)
@@ -0,0 +1,24 @@
+
+
+package org.cytoscape.command.internal;
+
+import org.cytoscape.task.TableTaskFactory;
+import org.cytoscape.application.CyApplicationManager;
+import org.cytoscape.command.internal.tunables.CommandTunableInterceptorImpl;
+
+class TTFExecutor extends TFExecutor {
+       private final TableTaskFactory ttf;
+       private final CyApplicationManager appMgr;
+
+       public TTFExecutor(TableTaskFactory ttf, CommandTunableInterceptorImpl 
interceptor, 
+                          CyApplicationManager appMgr) {
+               super(ttf,interceptor);
+               this.ttf = ttf;
+               this.appMgr = appMgr;
+       }
+
+       public void execute(String args) throws Exception {
+               ttf.setTable( appMgr.getCurrentTable() );
+               super.execute(args);
+       }
+}

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