Search in sources :

Example 16 with ObservableTask

use of org.cytoscape.work.ObservableTask in project cytoscape-impl by cytoscape.

the class CheckForUpdatesPanel method installUpdates.

private void installUpdates(final Set<Update> updates) {
    TaskIterator ti = new TaskIterator();
    ti.append(new InstallUpdatesTask(updates, appManager));
    taskManager.execute(ti, new TaskObserver() {

        @Override
        public void taskFinished(ObservableTask task) {
        }

        @Override
        public void allFinished(FinishStatus finishStatus) {
            checkUpdates();
        }
    });
}
Also used : TaskObserver(org.cytoscape.work.TaskObserver) ObservableTask(org.cytoscape.work.ObservableTask) TaskIterator(org.cytoscape.work.TaskIterator) InstallUpdatesTask(org.cytoscape.app.internal.task.InstallUpdatesTask) FinishStatus(org.cytoscape.work.FinishStatus)

Example 17 with ObservableTask

use of org.cytoscape.work.ObservableTask in project cytoscape-impl by cytoscape.

the class TFExecutor method execute.

@Override
public void execute(String args, TaskMonitor taskMonitor, TaskObserver observer) throws Exception {
    // Reset TunableInterceptor
    interceptor.setConfigurationContext((String) null);
    TaskIterator ti = tf.createTaskIterator();
    while (ti.hasNext()) {
        Task t = ti.next();
        interceptor.setConfigurationContext(args);
        interceptor.validateAndWriteBackTunables(t);
        TaskMonitor tm = new LogDelegateTaskMonitor(taskMonitor);
        if (!interceptor.validateTunableInput(t, tm)) {
            if (observer != null)
                observer.allFinished(FinishStatus.newCancelled(t));
            return;
        }
        t.run(tm);
        if (observer != null && t instanceof ObservableTask) {
            observer.taskFinished((ObservableTask) t);
        }
    }
}
Also used : ObservableTask(org.cytoscape.work.ObservableTask) Task(org.cytoscape.work.Task) ObservableTask(org.cytoscape.work.ObservableTask) TaskIterator(org.cytoscape.work.TaskIterator) TaskMonitor(org.cytoscape.work.TaskMonitor)

Example 18 with ObservableTask

use of org.cytoscape.work.ObservableTask in project cytoscape-impl by cytoscape.

the class TFExecutor method execute.

@Override
public void execute(Map<String, Object> args, TaskMonitor taskMonitor, TaskObserver observer) throws Exception {
    // Reset TunableInterceptor
    interceptor.setConfigurationContext((Map<String, Object>) null);
    TaskIterator ti = tf.createTaskIterator();
    while (ti.hasNext()) {
        Task t = ti.next();
        interceptor.setConfigurationContext(args);
        interceptor.validateAndWriteBackTunables(t);
        TaskMonitor tm = new LogDelegateTaskMonitor(taskMonitor);
        if (!interceptor.validateTunableInput(t, tm)) {
            if (observer != null)
                observer.allFinished(FinishStatus.newCancelled(t));
            return;
        }
        t.run(tm);
        if (observer != null && t instanceof ObservableTask) {
            observer.taskFinished((ObservableTask) t);
        }
    }
}
Also used : ObservableTask(org.cytoscape.work.ObservableTask) Task(org.cytoscape.work.Task) ObservableTask(org.cytoscape.work.ObservableTask) TaskIterator(org.cytoscape.work.TaskIterator) TaskMonitor(org.cytoscape.work.TaskMonitor)

Example 19 with ObservableTask

use of org.cytoscape.work.ObservableTask in project cytoscape-impl by cytoscape.

the class NewNetworkSelectedNodesOnlyTaskFactoryTest method testObserver.

@Test
public void testObserver() throws Exception {
    NetworkViewTestSupport viewSupport = new NetworkViewTestSupport();
    NetworkTestSupport networkSupport = new NetworkTestSupport();
    CyNetworkFactory networkFactory = networkSupport.getNetworkFactory();
    UndoSupport undoSupport = mock(UndoSupport.class);
    CyRootNetworkManager crnf = new CyRootNetworkManagerImpl();
    CyNetworkViewFactory cnvf = viewSupport.getNetworkViewFactory();
    CyNetworkManager netmgr = mock(CyNetworkManager.class);
    CyNetworkViewManager networkViewManager = mock(CyNetworkViewManager.class);
    CyNetworkNaming naming = mock(CyNetworkNaming.class);
    VisualMappingManager vmm = mock(VisualMappingManager.class);
    CyApplicationManager appManager = mock(CyApplicationManager.class);
    CyEventHelper eventHelper = mock(CyEventHelper.class);
    CyGroupManager groupMgr = mock(CyGroupManager.class);
    RenderingEngineManager renderingEngineMgr = mock(RenderingEngineManager.class);
    CyLayoutAlgorithm defLayout = mock(CyLayoutAlgorithm.class);
    CyLayoutAlgorithmManager layoutMgr = mock(CyLayoutAlgorithmManager.class);
    when(layoutMgr.getDefaultLayout()).thenReturn(defLayout);
    CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
    when(serviceRegistrar.getService(CyLayoutAlgorithmManager.class)).thenReturn(layoutMgr);
    NewNetworkSelectedNodesOnlyTaskFactoryImpl factory = new NewNetworkSelectedNodesOnlyTaskFactoryImpl(undoSupport, crnf, cnvf, netmgr, networkViewManager, naming, vmm, appManager, eventHelper, groupMgr, renderingEngineMgr, serviceRegistrar);
    CyNetwork network = networkFactory.createNetwork();
    CyNode node = network.addNode();
    network.getRow(node).set(CyNetwork.SELECTED, true);
    TaskObserver observer = mock(TaskObserver.class);
    TaskMonitor taskMonitor = mock(TaskMonitor.class);
    TaskIterator iterator = factory.createTaskIterator(network);
    while (iterator.hasNext()) {
        Task t = iterator.next();
        t.run(taskMonitor);
        if (t instanceof ObservableTask)
            observer.taskFinished((ObservableTask) t);
    }
    verify(observer, times(1)).taskFinished(any(ObservableTask.class));
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) Task(org.cytoscape.work.Task) ObservableTask(org.cytoscape.work.ObservableTask) CyNetwork(org.cytoscape.model.CyNetwork) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) ObservableTask(org.cytoscape.work.ObservableTask) TaskIterator(org.cytoscape.work.TaskIterator) TaskMonitor(org.cytoscape.work.TaskMonitor) CyLayoutAlgorithm(org.cytoscape.view.layout.CyLayoutAlgorithm) CyNode(org.cytoscape.model.CyNode) CyGroupManager(org.cytoscape.group.CyGroupManager) CyRootNetworkManager(org.cytoscape.model.subnetwork.CyRootNetworkManager) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) CyRootNetworkManagerImpl(org.cytoscape.model.internal.CyRootNetworkManagerImpl) NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) NetworkViewTestSupport(org.cytoscape.ding.NetworkViewTestSupport) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyApplicationManager(org.cytoscape.application.CyApplicationManager) TaskObserver(org.cytoscape.work.TaskObserver) CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyNetworkViewFactory(org.cytoscape.view.model.CyNetworkViewFactory) CyLayoutAlgorithmManager(org.cytoscape.view.layout.CyLayoutAlgorithmManager) CyNetworkNaming(org.cytoscape.session.CyNetworkNaming) CyNetworkFactory(org.cytoscape.model.CyNetworkFactory) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) Test(org.junit.Test)

Example 20 with ObservableTask

use of org.cytoscape.work.ObservableTask in project cytoscape-impl by cytoscape.

the class LoadNetworkFileTaskFactoryTest method testObserver.

@Test
public void testObserver() throws Exception {
    when(netReaderManager.getReader(any(URI.class), anyString())).thenReturn(reader);
    LoadNetworkFileTaskFactoryImpl factory = new LoadNetworkFileTaskFactoryImpl(serviceRegistrar);
    TaskMonitor taskMonitor = mock(TaskMonitor.class);
    TaskObserver observer = mock(TaskObserver.class);
    TaskIterator iterator = factory.createTaskIterator(new File(""), observer);
    while (iterator.hasNext()) {
        Task t = iterator.next();
        t.run(taskMonitor);
        if (t instanceof ObservableTask)
            observer.taskFinished((ObservableTask) t);
    }
    verify(observer, times(1)).taskFinished(any(ObservableTask.class));
}
Also used : TaskObserver(org.cytoscape.work.TaskObserver) ObservableTask(org.cytoscape.work.ObservableTask) Task(org.cytoscape.work.Task) ObservableTask(org.cytoscape.work.ObservableTask) TaskIterator(org.cytoscape.work.TaskIterator) TaskMonitor(org.cytoscape.work.TaskMonitor) LoadNetworkFileTaskFactoryImpl(org.cytoscape.task.internal.export.network.LoadNetworkFileTaskFactoryImpl) URI(java.net.URI) File(java.io.File) Test(org.junit.Test)

Aggregations

ObservableTask (org.cytoscape.work.ObservableTask)22 TaskIterator (org.cytoscape.work.TaskIterator)17 TaskObserver (org.cytoscape.work.TaskObserver)16 Task (org.cytoscape.work.Task)13 FinishStatus (org.cytoscape.work.FinishStatus)12 TaskMonitor (org.cytoscape.work.TaskMonitor)11 Test (org.junit.Test)6 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)5 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)4 File (java.io.File)3 CyApplicationManager (org.cytoscape.application.CyApplicationManager)3 NetworkViewTestSupport (org.cytoscape.ding.NetworkViewTestSupport)3 CyGroupManager (org.cytoscape.group.CyGroupManager)3 CyNetwork (org.cytoscape.model.CyNetwork)3 CyNetworkFactory (org.cytoscape.model.CyNetworkFactory)3 CyNetworkManager (org.cytoscape.model.CyNetworkManager)3 NetworkTestSupport (org.cytoscape.model.NetworkTestSupport)3 CyRootNetworkManagerImpl (org.cytoscape.model.internal.CyRootNetworkManagerImpl)3 CyRootNetworkManager (org.cytoscape.model.subnetwork.CyRootNetworkManager)3 CyNetworkNaming (org.cytoscape.session.CyNetworkNaming)3