Search in sources :

Example 1 with RunCommandsTaskFactory

use of org.cytoscape.command.internal.tasks.RunCommandsTaskFactory in project cytoscape-impl by cytoscape.

the class CyActivator method start.

@Override
public void start(BundleContext bc) {
    final CyServiceRegistrar serviceRegistrar = getService(bc, CyServiceRegistrar.class);
    CommandTunableInterceptorImpl interceptor = new CommandTunableInterceptorImpl();
    StringTunableHandlerFactory<FileTunableHandler> fileTHF = new SimpleStringTunableHandlerFactory<>(FileTunableHandler.class, File.class);
    StringTunableHandlerFactory<IntTunableHandler> intTHF = new SimpleStringTunableHandlerFactory<>(IntTunableHandler.class, Integer.class, int.class);
    StringTunableHandlerFactory<DoubleTunableHandler> doubleTHF = new SimpleStringTunableHandlerFactory<>(DoubleTunableHandler.class, Double.class, double.class);
    StringTunableHandlerFactory<FloatTunableHandler> floatTHF = new SimpleStringTunableHandlerFactory<>(FloatTunableHandler.class, Float.class, float.class);
    StringTunableHandlerFactory<LongTunableHandler> longTHF = new SimpleStringTunableHandlerFactory<>(LongTunableHandler.class, Long.class, long.class);
    StringTunableHandlerFactory<BooleanTunableHandler> booleanTHF = new SimpleStringTunableHandlerFactory<>(BooleanTunableHandler.class, Boolean.class, boolean.class);
    StringTunableHandlerFactory<StringTunableHandlerImpl> stringTHF = new SimpleStringTunableHandlerFactory<>(StringTunableHandlerImpl.class, String.class);
    StringTunableHandlerFactory<BoundedIntTunableHandler> boundedIntTHF = new SimpleStringTunableHandlerFactory<>(BoundedIntTunableHandler.class, BoundedInteger.class);
    StringTunableHandlerFactory<BoundedDoubleTunableHandler> boundedDoubleTHF = new SimpleStringTunableHandlerFactory<>(BoundedDoubleTunableHandler.class, BoundedDouble.class);
    StringTunableHandlerFactory<BoundedFloatTunableHandler> boundedFloatTHF = new SimpleStringTunableHandlerFactory<>(BoundedFloatTunableHandler.class, BoundedFloat.class);
    StringTunableHandlerFactory<BoundedLongTunableHandler> boundedLongTHF = new SimpleStringTunableHandlerFactory<>(BoundedLongTunableHandler.class, BoundedLong.class);
    StringTunableHandlerFactory<URLTunableHandler> urlTHF = new SimpleStringTunableHandlerFactory<>(URLTunableHandler.class, URL.class);
    StringTunableHandlerFactory<ListSingleTunableHandler> listSingleTHF = new SimpleStringTunableHandlerFactory<>(ListSingleTunableHandler.class, ListSingleSelection.class);
    StringTunableHandlerFactory<ListMultipleTunableHandler> listMultipleTHF = new SimpleStringTunableHandlerFactory<>(ListMultipleTunableHandler.class, ListMultipleSelection.class);
    registerService(bc, fileTHF, StringTunableHandlerFactory.class, new Properties());
    registerService(bc, intTHF, StringTunableHandlerFactory.class, new Properties());
    registerService(bc, doubleTHF, StringTunableHandlerFactory.class, new Properties());
    registerService(bc, floatTHF, StringTunableHandlerFactory.class, new Properties());
    registerService(bc, longTHF, StringTunableHandlerFactory.class, new Properties());
    registerService(bc, booleanTHF, StringTunableHandlerFactory.class, new Properties());
    registerService(bc, stringTHF, StringTunableHandlerFactory.class, new Properties());
    registerService(bc, boundedIntTHF, StringTunableHandlerFactory.class, new Properties());
    registerService(bc, boundedDoubleTHF, StringTunableHandlerFactory.class, new Properties());
    registerService(bc, boundedFloatTHF, StringTunableHandlerFactory.class, new Properties());
    registerService(bc, boundedLongTHF, StringTunableHandlerFactory.class, new Properties());
    registerService(bc, urlTHF, StringTunableHandlerFactory.class, new Properties());
    registerService(bc, listSingleTHF, StringTunableHandlerFactory.class, new Properties());
    registerService(bc, listMultipleTHF, StringTunableHandlerFactory.class, new Properties());
    StringToModel stm = new StringToModelImpl(serviceRegistrar);
    registerService(bc, stm, StringToModel.class, new Properties());
    CyIdentifiableStringTunableHandlerFactory<CyNetworkTunableHandler> networkTHF = new CyIdentifiableStringTunableHandlerFactory<>(stm, CyNetworkTunableHandler.class, CyNetwork.class);
    registerService(bc, networkTHF, StringTunableHandlerFactory.class, new Properties());
    CyIdentifiableStringTunableHandlerFactory<CyNetworkViewTunableHandler> networkViewTHF = new CyIdentifiableStringTunableHandlerFactory<>(stm, CyNetworkViewTunableHandler.class, CyNetworkView.class);
    registerService(bc, networkViewTHF, StringTunableHandlerFactory.class, new Properties());
    CyIdentifiableStringTunableHandlerFactory<CyTableTunableHandler> tableTHF = new CyIdentifiableStringTunableHandlerFactory<>(stm, CyTableTunableHandler.class, CyTable.class);
    registerService(bc, tableTHF, StringTunableHandlerFactory.class, new Properties());
    CyIdentifiableStringTunableHandlerFactory<NodeListTunableHandler> nodeListTHF = new CyIdentifiableStringTunableHandlerFactory<>(stm, NodeListTunableHandler.class, NodeList.class);
    registerService(bc, nodeListTHF, StringTunableHandlerFactory.class, new Properties());
    CyIdentifiableStringTunableHandlerFactory<EdgeListTunableHandler> edgeListTHF = new CyIdentifiableStringTunableHandlerFactory<>(stm, EdgeListTunableHandler.class, EdgeList.class);
    registerService(bc, edgeListTHF, StringTunableHandlerFactory.class, new Properties());
    CyIdentifiableStringTunableHandlerFactory<RowListTunableHandler> rowListTHF = new CyIdentifiableStringTunableHandlerFactory<>(stm, RowListTunableHandler.class, RowList.class);
    registerService(bc, rowListTHF, StringTunableHandlerFactory.class, new Properties());
    BasicArgHandlerFactory argHandlerFactory = new BasicArgHandlerFactory();
    registerService(bc, argHandlerFactory, ArgHandlerFactory.class, new Properties());
    ArgRecorder argRec = new ArgRecorder();
    registerServiceListener(bc, argRec::addTunableHandlerFactory, argRec::removeTunableHandlerFactory, ArgHandlerFactory.class);
    AvailableCommandsImpl availableCommandsImpl = new AvailableCommandsImpl(argRec, serviceRegistrar);
    registerService(bc, availableCommandsImpl, AvailableCommands.class, new Properties());
    registerServiceListener(bc, availableCommandsImpl::addTaskFactory, availableCommandsImpl::removeTaskFactory, TaskFactory.class);
    registerServiceListener(bc, availableCommandsImpl::addNetworkTaskFactory, availableCommandsImpl::removeNetworkTaskFactory, NetworkTaskFactory.class);
    registerServiceListener(bc, availableCommandsImpl::addNetworkViewTaskFactory, availableCommandsImpl::removeNetworkViewTaskFactory, NetworkViewTaskFactory.class);
    registerServiceListener(bc, availableCommandsImpl::addNetworkViewCollectionTaskFactory, availableCommandsImpl::removeNetworkViewCollectionTaskFactory, NetworkViewCollectionTaskFactory.class);
    registerServiceListener(bc, availableCommandsImpl::addTableTaskFactory, availableCommandsImpl::removeTableTaskFactory, TableTaskFactory.class);
    CommandExecutorImpl commandExecutor = new CommandExecutorImpl(interceptor, availableCommandsImpl, serviceRegistrar);
    CommandExecutorTaskFactoryImpl commandExecutorTaskFactory = new CommandExecutorTaskFactoryImpl(commandExecutor, serviceRegistrar);
    Properties commandExecutorTaskFactoryProps = new Properties();
    commandExecutorTaskFactoryProps.setProperty(ID, "commandExecutorTaskFactory");
    registerService(bc, commandExecutorTaskFactory, TaskFactory.class, commandExecutorTaskFactoryProps);
    registerService(bc, commandExecutorTaskFactory, CommandExecutorTaskFactory.class, commandExecutorTaskFactoryProps);
    registerServiceListener(bc, commandExecutor::addTaskFactory, commandExecutor::removeTaskFactory, TaskFactory.class);
    registerServiceListener(bc, commandExecutor::addNetworkTaskFactory, commandExecutor::removeNetworkTaskFactory, NetworkTaskFactory.class);
    registerServiceListener(bc, commandExecutor::addNetworkViewTaskFactory, commandExecutor::removeNetworkViewTaskFactory, NetworkViewTaskFactory.class);
    registerServiceListener(bc, commandExecutor::addNetworkViewCollectionTaskFactory, commandExecutor::removeNetworkViewCollectionTaskFactory, NetworkViewCollectionTaskFactory.class);
    registerServiceListener(bc, commandExecutor::addTableTaskFactory, commandExecutor::removeTableTaskFactory, TableTaskFactory.class);
    registerServiceListener(bc, interceptor::addTunableHandlerFactory, interceptor::removeTunableHandlerFactory, StringTunableHandlerFactory.class);
    {
        Properties props = new Properties();
        props.setProperty(COMMAND, "sleep");
        props.setProperty(COMMAND_NAMESPACE, "command");
        props.setProperty(COMMAND_DESCRIPTION, "Stop command processing for a specified time");
        props.setProperty(COMMAND_LONG_DESCRIPTION, "The **sleep** command will pause processing for a period of time as specified by *duration* seconds.");
        registerService(bc, new SleepCommandTaskFactory(), TaskFactory.class, props);
    }
    {
        Properties props = new Properties();
        props.setProperty(COMMAND, "echo");
        props.setProperty(COMMAND_NAMESPACE, "command");
        props.setProperty(COMMAND_DESCRIPTION, "Returns the value of the 'message' argument.");
        props.setProperty(COMMAND_LONG_DESCRIPTION, "Returns the value of the **message** argument.");
        props.setProperty(COMMAND_SUPPORTS_JSON, "true");
        props.setProperty(COMMAND_EXAMPLE_JSON, "");
        registerService(bc, new EchoCommandTaskFactory(), TaskFactory.class, props);
    }
    {
        Properties props = new Properties();
        props.setProperty(COMMAND, "quit");
        props.setProperty(COMMAND_NAMESPACE, "command");
        props.setProperty(COMMAND_DESCRIPTION, "Exit Cytoscape");
        props.setProperty(COMMAND_LONG_DESCRIPTION, "This command causes Cytoscape to exit. It is typically used at the end of a script file");
        registerService(bc, new QuitTaskFactory(serviceRegistrar), TaskFactory.class, props);
    }
    {
        Properties props = new Properties();
        props.setProperty(PREFERRED_MENU, "Tools");
        props.setProperty(TITLE, "Execute Command File...");
        props.setProperty(COMMAND, "run");
        props.setProperty(COMMAND_NAMESPACE, "command");
        props.setProperty(COMMAND_DESCRIPTION, "Run a series of commands from a file");
        props.setProperty(IN_MENU_BAR, "true");
        props.setProperty(COMMAND_LONG_DESCRIPTION, "The **run** command will execute a command script from the " + "file pointed to by the ``file`` argument, which " + "should contain Cytoscape commands, one per line. " + "Arguments to the " + "script are provided by the *args* argument");
        registerService(bc, new RunCommandsTaskFactory(commandExecutorTaskFactory), TaskFactory.class, props);
    }
    // Get any command line arguments.  The "-S" and "-R" are ours
    AppsFinishedStartingListener scriptRunner = new AppsFinishedStartingListener() {

        public void handleEvent(AppsFinishedStartingEvent event) {
            @SuppressWarnings("unchecked") CyProperty<Properties> commandLineProps = getService(bc, CyProperty.class, "(cyPropertyName=commandline.props)");
            String scriptFile = commandLineProps.getProperties().getProperty("scriptFile");
            if (scriptFile != null) {
                TaskIterator tasks = commandExecutorTaskFactory.createTaskIterator(new File(scriptFile), null);
                SynchronousTaskManager<?> taskManager = serviceRegistrar.getService(SynchronousTaskManager.class);
                taskManager.execute(tasks);
            }
        }
    };
    registerService(bc, scriptRunner, AppsFinishedStartingListener.class, new Properties());
}
Also used : ListSingleTunableHandler(org.cytoscape.command.internal.tunables.ListSingleTunableHandler) BoundedIntTunableHandler(org.cytoscape.command.internal.tunables.BoundedIntTunableHandler) NodeListTunableHandler(org.cytoscape.command.internal.tunables.NodeListTunableHandler) CyTableTunableHandler(org.cytoscape.command.internal.tunables.CyTableTunableHandler) BasicArgHandlerFactory(org.cytoscape.command.internal.available.BasicArgHandlerFactory) BoundedLongTunableHandler(org.cytoscape.command.internal.tunables.BoundedLongTunableHandler) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) ArgRecorder(org.cytoscape.command.internal.available.ArgRecorder) BoundedDoubleTunableHandler(org.cytoscape.command.internal.tunables.BoundedDoubleTunableHandler) DoubleTunableHandler(org.cytoscape.command.internal.tunables.DoubleTunableHandler) CommandTunableInterceptorImpl(org.cytoscape.command.internal.tunables.CommandTunableInterceptorImpl) SimpleStringTunableHandlerFactory(org.cytoscape.command.internal.tunables.SimpleStringTunableHandlerFactory) IntTunableHandler(org.cytoscape.command.internal.tunables.IntTunableHandler) BoundedIntTunableHandler(org.cytoscape.command.internal.tunables.BoundedIntTunableHandler) BooleanTunableHandler(org.cytoscape.command.internal.tunables.BooleanTunableHandler) SleepCommandTaskFactory(org.cytoscape.command.internal.tasks.SleepCommandTaskFactory) StringToModel(org.cytoscape.command.StringToModel) ListMultipleTunableHandler(org.cytoscape.command.internal.tunables.ListMultipleTunableHandler) URLTunableHandler(org.cytoscape.command.internal.tunables.URLTunableHandler) QuitTaskFactory(org.cytoscape.command.internal.tasks.QuitTaskFactory) FileTunableHandler(org.cytoscape.command.internal.tunables.FileTunableHandler) RowListTunableHandler(org.cytoscape.command.internal.tunables.RowListTunableHandler) CyIdentifiableStringTunableHandlerFactory(org.cytoscape.command.internal.tunables.CyIdentifiableStringTunableHandlerFactory) File(java.io.File) BoundedFloatTunableHandler(org.cytoscape.command.internal.tunables.BoundedFloatTunableHandler) FloatTunableHandler(org.cytoscape.command.internal.tunables.FloatTunableHandler) ServiceProperties(org.cytoscape.work.ServiceProperties) Properties(java.util.Properties) CyNetworkTunableHandler(org.cytoscape.command.internal.tunables.CyNetworkTunableHandler) AppsFinishedStartingEvent(org.cytoscape.app.event.AppsFinishedStartingEvent) TaskIterator(org.cytoscape.work.TaskIterator) EdgeListTunableHandler(org.cytoscape.command.internal.tunables.EdgeListTunableHandler) BoundedDoubleTunableHandler(org.cytoscape.command.internal.tunables.BoundedDoubleTunableHandler) EchoCommandTaskFactory(org.cytoscape.command.internal.tasks.EchoCommandTaskFactory) BoundedFloatTunableHandler(org.cytoscape.command.internal.tunables.BoundedFloatTunableHandler) AppsFinishedStartingListener(org.cytoscape.app.event.AppsFinishedStartingListener) RunCommandsTaskFactory(org.cytoscape.command.internal.tasks.RunCommandsTaskFactory) StringTunableHandlerImpl(org.cytoscape.command.internal.tunables.StringTunableHandlerImpl) CyNetworkViewTunableHandler(org.cytoscape.command.internal.tunables.CyNetworkViewTunableHandler) BoundedLongTunableHandler(org.cytoscape.command.internal.tunables.BoundedLongTunableHandler) LongTunableHandler(org.cytoscape.command.internal.tunables.LongTunableHandler) NetworkViewCollectionTaskFactory(org.cytoscape.task.NetworkViewCollectionTaskFactory) EchoCommandTaskFactory(org.cytoscape.command.internal.tasks.EchoCommandTaskFactory) RunCommandsTaskFactory(org.cytoscape.command.internal.tasks.RunCommandsTaskFactory) SleepCommandTaskFactory(org.cytoscape.command.internal.tasks.SleepCommandTaskFactory) NetworkViewTaskFactory(org.cytoscape.task.NetworkViewTaskFactory) TaskFactory(org.cytoscape.work.TaskFactory) NetworkTaskFactory(org.cytoscape.task.NetworkTaskFactory) TableTaskFactory(org.cytoscape.task.TableTaskFactory) CommandExecutorTaskFactory(org.cytoscape.command.CommandExecutorTaskFactory) QuitTaskFactory(org.cytoscape.command.internal.tasks.QuitTaskFactory) AvailableCommandsImpl(org.cytoscape.command.internal.available.AvailableCommandsImpl)

Aggregations

File (java.io.File)1 Properties (java.util.Properties)1 AppsFinishedStartingEvent (org.cytoscape.app.event.AppsFinishedStartingEvent)1 AppsFinishedStartingListener (org.cytoscape.app.event.AppsFinishedStartingListener)1 CommandExecutorTaskFactory (org.cytoscape.command.CommandExecutorTaskFactory)1 StringToModel (org.cytoscape.command.StringToModel)1 ArgRecorder (org.cytoscape.command.internal.available.ArgRecorder)1 AvailableCommandsImpl (org.cytoscape.command.internal.available.AvailableCommandsImpl)1 BasicArgHandlerFactory (org.cytoscape.command.internal.available.BasicArgHandlerFactory)1 EchoCommandTaskFactory (org.cytoscape.command.internal.tasks.EchoCommandTaskFactory)1 QuitTaskFactory (org.cytoscape.command.internal.tasks.QuitTaskFactory)1 RunCommandsTaskFactory (org.cytoscape.command.internal.tasks.RunCommandsTaskFactory)1 SleepCommandTaskFactory (org.cytoscape.command.internal.tasks.SleepCommandTaskFactory)1 BooleanTunableHandler (org.cytoscape.command.internal.tunables.BooleanTunableHandler)1 BoundedDoubleTunableHandler (org.cytoscape.command.internal.tunables.BoundedDoubleTunableHandler)1 BoundedFloatTunableHandler (org.cytoscape.command.internal.tunables.BoundedFloatTunableHandler)1 BoundedIntTunableHandler (org.cytoscape.command.internal.tunables.BoundedIntTunableHandler)1 BoundedLongTunableHandler (org.cytoscape.command.internal.tunables.BoundedLongTunableHandler)1 CommandTunableInterceptorImpl (org.cytoscape.command.internal.tunables.CommandTunableInterceptorImpl)1 CyIdentifiableStringTunableHandlerFactory (org.cytoscape.command.internal.tunables.CyIdentifiableStringTunableHandlerFactory)1