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