Search in sources :

Example 11 with ObservableTask

use of org.cytoscape.work.ObservableTask in project EnrichmentMapApp by BaderLab.

the class AddRanksDialog method loadRanksAndClose.

private void loadRanksAndClose() {
    String rankFileName = ranksFileText.getText();
    String ranksName = getRanksName();
    EMDataSet dataset = getDataSet();
    RanksFileReaderTask task = new RanksFileReaderTask(rankFileName, dataset, ranksName, true);
    dialogTaskManager.execute(new TaskIterator(task), new TaskObserver() {

        @Override
        public void taskFinished(ObservableTask task) {
        }

        @Override
        public void allFinished(FinishStatus finishStatus) {
            resultRanksName = ranksName;
            dispose();
        }
    });
}
Also used : TaskObserver(org.cytoscape.work.TaskObserver) ObservableTask(org.cytoscape.work.ObservableTask) TaskIterator(org.cytoscape.work.TaskIterator) RanksFileReaderTask(org.baderlab.csplugins.enrichmentmap.parsers.RanksFileReaderTask) FinishStatus(org.cytoscape.work.FinishStatus) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet)

Example 12 with ObservableTask

use of org.cytoscape.work.ObservableTask in project EnrichmentMapApp by BaderLab.

the class ClusterRankingOption method computeRanking.

@Override
public CompletableFuture<Optional<Map<Integer, RankValue>>> computeRanking(Collection<Integer> genes) {
    if (genes.size() < 2) {
        // The HierarchicalClusterTask requires at least 2 genes
        return CompletableFuture.completedFuture(Optional.of(Collections.emptyMap()));
    }
    HierarchicalClusterTask task = new HierarchicalClusterTask(map, genes, distance.getMetric());
    CompletableFuture<Optional<Map<Integer, RankValue>>> future = new CompletableFuture<>();
    taskManager.execute(new TaskIterator(task), new TaskObserver() {

        @Override
        public void taskFinished(ObservableTask task) {
            if (task instanceof HierarchicalClusterTask) {
                HierarchicalClusterTask clusterTask = (HierarchicalClusterTask) task;
                Optional<Map<Integer, RankValue>> ranking = clusterTask.getActualResults();
                future.complete(ranking);
            }
        }

        @Override
        public void allFinished(FinishStatus finishStatus) {
            // Don't see why this would ever happen
            if (!future.isDone()) {
                future.completeExceptionally(new RuntimeException("Failed"));
            }
        }
    });
    return future;
}
Also used : TaskObserver(org.cytoscape.work.TaskObserver) ObservableTask(org.cytoscape.work.ObservableTask) CompletableFuture(java.util.concurrent.CompletableFuture) TaskIterator(org.cytoscape.work.TaskIterator) Optional(java.util.Optional) FinishStatus(org.cytoscape.work.FinishStatus) RankValue(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.RankValue) HierarchicalClusterTask(org.baderlab.csplugins.enrichmentmap.task.cluster.HierarchicalClusterTask)

Example 13 with ObservableTask

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

the class CommandTaskRunner method runTasks.

private void runTasks(String command, MessageHandler messageHandler) {
    CommandExecutorTaskFactory commandFactory = serviceRegistrar.getService(CommandExecutorTaskFactory.class);
    TaskIterator taskIterator = commandFactory.createTaskIterator(Arrays.asList(command), new TaskObserver() {

        @Override
        public void taskFinished(ObservableTask task) {
            Object result = task.getResults(String.class);
            if (result != null) {
                messageHandler.appendResult(result.toString());
            }
        }

        @Override
        public void allFinished(FinishStatus status) {
            messageHandler.appendCommand(status.getType().toString());
        }
    });
    while (taskIterator.hasNext()) {
        Task task = taskIterator.next();
        try {
            task.run(new TaskMonitor() {

                @Override
                public void showMessage(Level level, String message) {
                    switch(level) {
                        default:
                        case ERROR:
                            messageHandler.appendError(message);
                            break;
                        case INFO:
                            messageHandler.appendMessage(message);
                            break;
                        case WARN:
                            messageHandler.appendWarning(message);
                            break;
                    }
                }

                @Override
                public void setTitle(String title) {
                }

                @Override
                public void setStatusMessage(String statusMessage) {
                }

                @Override
                public void setProgress(double progress) {
                }
            });
        } catch (Exception e) {
            messageHandler.appendError("Error handling command \"" + e.getMessage());
        }
    }
}
Also used : Task(org.cytoscape.work.Task) ObservableTask(org.cytoscape.work.ObservableTask) CommandExecutorTaskFactory(org.cytoscape.command.CommandExecutorTaskFactory) FinishStatus(org.cytoscape.work.FinishStatus) TaskObserver(org.cytoscape.work.TaskObserver) ObservableTask(org.cytoscape.work.ObservableTask) TaskIterator(org.cytoscape.work.TaskIterator) TaskMonitor(org.cytoscape.work.TaskMonitor)

Example 14 with ObservableTask

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

the class DelegateTask method run.

public void run(TaskMonitor tm) throws Exception {
    // this ensures that we get a coherent task monitor
    DelegatingTaskMonitor dtm = new DelegatingTaskMonitor(tm, ti.getNumTasks());
    // this gives the tunable mutator what it needs to set
    // the tunables as the tasks get executed
    stm.setConfigurationContext(tunableValues);
    while (ti.hasNext()) {
        final Task task = ti.next();
        dtm.setTask(task);
        if (!setTunables(task))
            return;
        currentTask = task;
        task.run(dtm);
        if (currentTask instanceof ObservableTask && observer != null) {
            observer.taskFinished((ObservableTask) currentTask);
        }
        currentTask = null;
    }
// We don't call allfinished() since we're delegating...
}
Also used : ObservableTask(org.cytoscape.work.ObservableTask) Task(org.cytoscape.work.Task) AbstractTask(org.cytoscape.work.AbstractTask) ObservableTask(org.cytoscape.work.ObservableTask)

Example 15 with ObservableTask

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

the class ImportDefaultVisualStylesCommand method execute.

@Override
public void execute(final INotification notification) {
    final TaskIterator iterator = new TaskIterator(new ImportDefaultVizmapTask(servicesUtil));
    final DialogTaskManager taskManager = servicesUtil.get(DialogTaskManager.class);
    final VizMapperProxy proxy = (VizMapperProxy) getFacade().retrieveProxy(VizMapperProxy.NAME);
    proxy.setIgnoreStyleEvents(true);
    taskManager.execute(iterator, new TaskObserver() {

        @Override
        public void taskFinished(ObservableTask task) {
        }

        @Override
        public void allFinished(FinishStatus finishStatus) {
            proxy.setIgnoreStyleEvents(false);
            proxy.loadVisualStyles();
            proxy.setCurrentVisualStyle(servicesUtil.get(VisualMappingManager.class).getDefaultVisualStyle());
        }
    });
}
Also used : TaskObserver(org.cytoscape.work.TaskObserver) ObservableTask(org.cytoscape.work.ObservableTask) VizMapperProxy(org.cytoscape.view.vizmap.gui.internal.model.VizMapperProxy) TaskIterator(org.cytoscape.work.TaskIterator) FinishStatus(org.cytoscape.work.FinishStatus) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) DialogTaskManager(org.cytoscape.work.swing.DialogTaskManager) ImportDefaultVizmapTask(org.cytoscape.view.vizmap.gui.internal.task.ImportDefaultVizmapTask)

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