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();
}
});
}
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);
}
}
}
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);
}
}
}
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));
}
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));
}
Aggregations