Author: mes
Date: 2011-03-11 16:59:58 -0800 (Fri, 11 Mar 2011)
New Revision: 24420
Added:
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/tunables/
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/tunables/CommandTunableHandlerFactory.java
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/tunables/CommandTunableInterceptorImpl.java
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/tunables/DummyTunableHandler.java
Modified:
core3/command-executor-impl/trunk/pom.xml
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/CommandExecutorImpl.java
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/NTFExecutor.java
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/TFExecutor.java
core3/command-executor-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
core3/command-executor-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
Log:
added proper execution
Modified: core3/command-executor-impl/trunk/pom.xml
===================================================================
--- core3/command-executor-impl/trunk/pom.xml 2011-03-12 00:13:16 UTC (rev
24419)
+++ core3/command-executor-impl/trunk/pom.xml 2011-03-12 00:59:58 UTC (rev
24420)
@@ -83,6 +83,11 @@
<artifactId>core-task-api</artifactId>
<version>3.0.0-alpha2</version>
</dependency>
+ <dependency>
+ <groupId>org.cytoscape</groupId>
+ <artifactId>work-spring-hack</artifactId>
+ <version>3.0.0-alpha1</version>
+ </dependency>
</dependencies>
</project>
Modified:
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/CommandExecutorImpl.java
===================================================================
---
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/CommandExecutorImpl.java
2011-03-12 00:13:16 UTC (rev 24419)
+++
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/CommandExecutorImpl.java
2011-03-12 00:59:58 UTC (rev 24420)
@@ -10,7 +10,11 @@
import org.slf4j.LoggerFactory;
import org.cytoscape.work.TaskFactory;
+import org.cytoscape.work.TunableInterceptor;
import org.cytoscape.task.NetworkTaskFactory;
+import org.cytoscape.command.internal.tunables.CommandTunableInterceptorImpl;
+import org.cytoscape.command.internal.tunables.CommandTunableHandlerFactory;
+import org.cytoscape.session.CyApplicationManager;
public class CommandExecutorImpl {
@@ -19,8 +23,15 @@
private final Map<String, Map<String,Executor>> commandExecutorMap =
new
HashMap<String,Map<String,Executor>>();
+ private final TunableInterceptor interceptor = new
CommandTunableInterceptorImpl(new CommandTunableHandlerFactory());
+ private final CyApplicationManager appMgr;
+
+ public CommandExecutorImpl(CyApplicationManager appMgr) {
+ this.appMgr = appMgr;
+ }
+
public void addTaskFactory(TaskFactory tf, Map props) {
- addTF(new TFExecutor(tf), props);
+ addTF(new TFExecutor(tf,interceptor), props);
}
public void removeTaskFactory(TaskFactory tf, Map props) {
@@ -28,7 +39,7 @@
}
public void addNetworkTaskFactory(NetworkTaskFactory tf, Map props) {
- addTF(new NTFExecutor(tf), props);
+ addTF(new NTFExecutor(tf,interceptor,appMgr), props);
}
public void removeNetworkTaskFactory(NetworkTaskFactory tf, Map props) {
Modified:
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/NTFExecutor.java
===================================================================
---
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/NTFExecutor.java
2011-03-12 00:13:16 UTC (rev 24419)
+++
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/NTFExecutor.java
2011-03-12 00:59:58 UTC (rev 24420)
@@ -3,17 +3,22 @@
package org.cytoscape.command.internal;
import org.cytoscape.task.NetworkTaskFactory;
+import org.cytoscape.work.TunableInterceptor;
+import org.cytoscape.session.CyApplicationManager;
class NTFExecutor extends TFExecutor {
private final NetworkTaskFactory ntf;
+ private final CyApplicationManager appMgr;
- public NTFExecutor(NetworkTaskFactory ntf) {
- super(ntf);
+ public NTFExecutor(NetworkTaskFactory ntf, TunableInterceptor
interceptor, CyApplicationManager appMgr) {
+ super(ntf,interceptor);
this.ntf = ntf;
+ this.appMgr = appMgr;
}
public void execute(String args) {
System.out.println("set current network!");
+ ntf.setNetwork( appMgr.getCurrentNetwork() );
super.execute(args);
}
}
Modified:
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/TFExecutor.java
===================================================================
---
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/TFExecutor.java
2011-03-12 00:13:16 UTC (rev 24419)
+++
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/TFExecutor.java
2011-03-12 00:59:58 UTC (rev 24420)
@@ -2,15 +2,47 @@
package org.cytoscape.command.internal;
import org.cytoscape.work.TaskFactory;
+import org.cytoscape.work.TaskMonitor;
+import org.cytoscape.work.TaskIterator;
+import org.cytoscape.work.Task;
+import org.cytoscape.work.TunableInterceptor;
class TFExecutor implements Executor {
private final TaskFactory tf;
+ private final TunableInterceptor interceptor;
+ private final TaskMonitor tm = new OutTaskMonitor();
- public TFExecutor(TaskFactory tf) {
+ public TFExecutor(TaskFactory tf, TunableInterceptor interceptor) {
this.tf = tf;
+ this.interceptor = interceptor;
}
public void execute(String args) {
+ try {
System.out.println("executing: " + tf + " with args: '" +
args + "'");
+ TaskIterator ti = tf.getTaskIterator();
+ while (ti.hasNext()) {
+ Task t = ti.next();
+ interceptor.loadTunables(t);
+ interceptor.execUI(t);
+ t.run(tm);
+ }
+ } catch (Exception e) {
+ System.out.println("task failed!");
+ e.printStackTrace();
+ }
}
+
+ private class OutTaskMonitor implements TaskMonitor {
+ public void setTitle(String title) {
+ System.out.println("set title: " + title);
+ }
+ public void setProgress(double progress) {
+ System.out.println("set progress: " + progress);
+ }
+ public void setStatusMessage(String statusMessage) {
+ System.out.println("set statusMessage: " +
statusMessage);
+ }
+
+ }
}
Added:
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/tunables/CommandTunableHandlerFactory.java
===================================================================
---
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/tunables/CommandTunableHandlerFactory.java
(rev 0)
+++
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/tunables/CommandTunableHandlerFactory.java
2011-03-12 00:59:58 UTC (rev 24420)
@@ -0,0 +1,97 @@
+package org.cytoscape.command.internal.tunables;
+
+
+import java.io.File;
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.net.URL;
+
+import org.cytoscape.work.Tunable;
+import org.cytoscape.work.TunableHandlerFactory;
+import org.cytoscape.work.TunableHandler;
+import org.cytoscape.work.util.BoundedDouble;
+import org.cytoscape.work.util.BoundedFloat;
+import org.cytoscape.work.util.BoundedInteger;
+import org.cytoscape.work.util.BoundedLong;
+import org.cytoscape.work.util.ListMultipleSelection;
+import org.cytoscape.work.util.ListSingleSelection;
+
+
+public class CommandTunableHandlerFactory implements
TunableHandlerFactory<TunableHandler> {
+
+
+ public TunableHandler getHandler(final Method getter, final Method
setter, final Object instance, final Tunable tunable) {
+ final Class<?> type = getter.getReturnType();
+
+ if (type == Boolean.class || type == boolean.class)
+ return new DummyTunableHandler(getter, setter,
instance, tunable);
+ if (type == String.class)
+ return new DummyTunableHandler(getter, setter,
instance, tunable);
+ if (type == Integer.class || type == int.class)
+ return new DummyTunableHandler(getter, setter,
instance, tunable);
+ if (type == Double.class || type == double.class)
+ return new DummyTunableHandler(getter, setter,
instance, tunable);
+ if (type == Float.class || type == float.class)
+ return new DummyTunableHandler(getter, setter,
instance, tunable);
+ if (type == Long.class || type == long.class)
+ return new DummyTunableHandler(getter, setter,
instance, tunable);
+ if (type == BoundedInteger.class)
+ return new DummyTunableHandler(getter, setter,
instance, tunable);
+ if (type == BoundedLong.class)
+ return new DummyTunableHandler(getter, setter,
instance, tunable);
+ if (type == BoundedFloat.class)
+ return new DummyTunableHandler(getter, setter,
instance, tunable);
+ if (type == BoundedDouble.class)
+ return new DummyTunableHandler(getter, setter,
instance, tunable);
+ if (type == ListSingleSelection.class)
+ return new DummyTunableHandler(getter, setter,
instance, tunable);
+ if (type == ListMultipleSelection.class)
+ return new DummyTunableHandler(getter, setter,
instance, tunable);
+ if (type == File.class)
+ return new DummyTunableHandler(getter, setter,
instance, tunable);
+ if (type == URL.class)
+ return new DummyTunableHandler(getter, setter,
instance, tunable);
+ if (type == InputStream.class)
+ return new DummyTunableHandler(getter, setter,
instance, tunable);
+
+ return null;
+ }
+
+ public TunableHandler getHandler(final Field field, final Object
instance, final Tunable tunable) {
+ final Class<?> type = field.getType();
+
+ if (type == Boolean.class || type == boolean.class)
+ return new DummyTunableHandler(field, instance,
tunable);
+ if (type == String.class)
+ return new DummyTunableHandler(field, instance,
tunable);
+ if (type == Integer.class || type == int.class)
+ return new DummyTunableHandler(field, instance,
tunable);
+ if (type == Double.class || type == double.class)
+ return new DummyTunableHandler(field, instance,
tunable);
+ if (type == Float.class || type == float.class)
+ return new DummyTunableHandler(field, instance,
tunable);
+ if (type == Long.class || type == long.class)
+ return new DummyTunableHandler(field, instance,
tunable);
+ if (type == BoundedInteger.class)
+ return new DummyTunableHandler(field, instance,
tunable);
+ if (type == BoundedLong.class)
+ return new DummyTunableHandler(field, instance,
tunable);
+ if (type == BoundedFloat.class)
+ return new DummyTunableHandler(field, instance,
tunable);
+ if (type == BoundedDouble.class)
+ return new DummyTunableHandler(field, instance,
tunable);
+ if (type == ListSingleSelection.class)
+ return new DummyTunableHandler(field, instance,
tunable);
+ if (type == ListMultipleSelection.class)
+ return new DummyTunableHandler(field, instance,
tunable);
+ if (type == File.class)
+ return new DummyTunableHandler(field, instance,
tunable);
+ if (type == URL.class)
+ return new DummyTunableHandler(field, instance,
tunable);
+ if (type == InputStream.class)
+ return new DummyTunableHandler(field, instance,
tunable);
+
+ return null;
+ }
+}
Added:
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/tunables/CommandTunableInterceptorImpl.java
===================================================================
---
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/tunables/CommandTunableInterceptorImpl.java
(rev 0)
+++
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/tunables/CommandTunableInterceptorImpl.java
2011-03-12 00:59:58 UTC (rev 24420)
@@ -0,0 +1,40 @@
+package org.cytoscape.command.internal.tunables;
+
+
+import java.awt.Color;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.cytoscape.work.TaskFactory;
+import org.cytoscape.work.TunableHandlerFactory;
+import org.cytoscape.work.TunableHandler;
+import org.cytoscape.work.TunableValidator;
+import org.cytoscape.work.spring.SpringTunableInterceptor;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class CommandTunableInterceptorImpl extends
SpringTunableInterceptor<TunableHandler> {
+ private boolean newValuesSet;
+
+ public CommandTunableInterceptorImpl(final
TunableHandlerFactory<TunableHandler> factory) {
+ super(factory);
+ }
+
+ public boolean execUI(Object... objs) {
+ return validateAndWriteBackTunables(objs);
+ }
+
+ public boolean validateAndWriteBackTunables(Object... objs) {
+ for ( Object o : objs ) {
+ Map<String,TunableHandler> handlers = getHandlers(o);
+ for ( String s : handlers.keySet() ) {
+ System.out.println("got handler for tunable
param: " + s);
+ }
+ }
+ return true;
+ }
+}
Added:
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/tunables/DummyTunableHandler.java
===================================================================
---
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/tunables/DummyTunableHandler.java
(rev 0)
+++
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/tunables/DummyTunableHandler.java
2011-03-12 00:59:58 UTC (rev 24420)
@@ -0,0 +1,25 @@
+
+package org.cytoscape.command.internal.tunables;
+
+
+
+import org.cytoscape.work.TunableHandler;
+import org.cytoscape.work.Tunable;
+import org.cytoscape.work.AbstractTunableHandler;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+
+public class DummyTunableHandler extends AbstractTunableHandler {
+
+ public DummyTunableHandler(Field f, Object o, Tunable t) {
+ super(f,o,t);
+ }
+ public DummyTunableHandler(Method get, Method set, Object o, Tunable t)
{
+ super(get,set,o,t);
+ }
+ public void handle() {
+ System.out.println("handling! " + getName());
+ }
+}
Modified:
core3/command-executor-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
===================================================================
---
core3/command-executor-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
2011-03-12 00:13:16 UTC (rev 24419)
+++
core3/command-executor-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
2011-03-12 00:59:58 UTC (rev 24420)
@@ -5,6 +5,8 @@
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi-1.0.xsd"
default-lazy-init="false">
+ <osgi:reference id="cyApplicationManagerServiceRef"
+ interface="org.cytoscape.session.CyApplicationManager" />
<osgi:service id="commandExecutorTaskFactoryService"
ref="commandExecutorTaskFactory"
interface="org.cytoscape.work.TaskFactory">
Modified:
core3/command-executor-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
===================================================================
---
core3/command-executor-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
2011-03-12 00:13:16 UTC (rev 24419)
+++
core3/command-executor-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
2011-03-12 00:59:58 UTC (rev 24420)
@@ -27,6 +27,7 @@
<context:annotation-config />
<bean id="commandExecutorImpl"
class="org.cytoscape.command.internal.CommandExecutorImpl">
+ <constructor-arg ref="cyApplicationManagerServiceRef" />
</bean>
<bean id="commandExecutorTaskFactory"
--
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.