use of net.sf.mzmine.taskcontrol.AllTasksFinishedListener in project mzmine2 by mzmine.
the class GnpsGcExportAndSubmitTask method run.
@Override
public void run() {
final AbstractTask thistask = this;
setStatus(TaskStatus.PROCESSING);
List<AbstractTask> list = new ArrayList<>(3);
// add mgf export task
list.add(addAdapMgfTask(parameters));
// add csv quant table
list.add(addQuantTableTask(parameters, null));
// finish listener to submit
final File fileName = file;
final File folder = file.getParentFile();
new AllTasksFinishedListener(list, true, // succeed
l -> {
try {
LOG.info("succeed" + thistask.getStatus().toString());
if (submit) {
GnpsGcSubmitParameters param = parameters.getParameter(GnpsGcExportAndSubmitParameters.SUBMIT).getEmbeddedParameters();
submit(fileName, param);
}
// open folder
try {
if (openFolder && Desktop.isDesktopSupported()) {
Desktop.getDesktop().open(folder);
}
} catch (Exception ex) {
}
} finally {
// finish task
if (thistask.getStatus() == TaskStatus.PROCESSING)
thistask.setStatus(TaskStatus.FINISHED);
}
}, lerror -> {
setErrorMessage("GNPS-GC submit was not started due too errors while file export");
thistask.setStatus(TaskStatus.ERROR);
throw new MSDKRuntimeException("GNPS-GC submit was not started due too errors while file export");
}, // cancel if one was cancelled
listCancelled -> cancel()) {
@Override
public void taskStatusChanged(Task task, TaskStatus newStatus, TaskStatus oldStatus) {
super.taskStatusChanged(task, newStatus, oldStatus);
// show progress
progress.getAndSet(getProgress());
}
};
MZmineCore.getTaskController().addTasks(list.toArray(new AbstractTask[list.size()]));
// wait till finish
while (!(isCanceled() || isFinished())) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
LOG.log(Level.SEVERE, "Error in GNPS-GC export/submit task", e);
}
}
}
use of net.sf.mzmine.taskcontrol.AllTasksFinishedListener in project mzmine2 by mzmine.
the class GnpsFbmnExportAndSubmitTask method run.
@Override
public void run() {
final AbstractTask thistask = this;
setStatus(TaskStatus.PROCESSING);
boolean openFolder = parameters.getParameter(GnpsFbmnExportAndSubmitParameters.OPEN_FOLDER).getValue();
boolean submit = parameters.getParameter(GnpsFbmnExportAndSubmitParameters.SUBMIT).getValue();
File file = parameters.getParameter(GnpsFbmnExportAndSubmitParameters.FILENAME).getValue();
file = FileAndPathUtil.eraseFormat(file);
parameters.getParameter(GnpsFbmnExportAndSubmitParameters.FILENAME).setValue(file);
List<AbstractTask> list = new ArrayList<>(3);
GnpsFbmnMgfExportTask task = new GnpsFbmnMgfExportTask(parameters);
list.add(task);
// add csv quant table
list.add(addQuantTableTask(parameters, null));
// finish listener to submit
final File fileName = file;
final File folder = file.getParentFile();
new AllTasksFinishedListener(list, true, // succeed
l -> {
try {
LOG.info("succeed" + thistask.getStatus().toString());
if (submit) {
GnpsFbmnSubmitParameters param = parameters.getParameter(GnpsFbmnExportAndSubmitParameters.SUBMIT).getEmbeddedParameters();
submit(fileName, param);
}
// open folder
try {
if (openFolder && Desktop.isDesktopSupported()) {
Desktop.getDesktop().open(folder);
}
} catch (Exception ex) {
}
} finally {
// finish task
if (thistask.getStatus() == TaskStatus.PROCESSING)
thistask.setStatus(TaskStatus.FINISHED);
}
}, lerror -> {
setErrorMessage("GNPS submit was not started due too errors while file export");
thistask.setStatus(TaskStatus.ERROR);
throw new MSDKRuntimeException("GNPS submit was not started due too errors while file export");
}, // cancel if one was cancelled
listCancelled -> cancel()) {
@Override
public void taskStatusChanged(Task task, TaskStatus newStatus, TaskStatus oldStatus) {
super.taskStatusChanged(task, newStatus, oldStatus);
// show progress
progress.getAndSet(getProgress());
}
};
MZmineCore.getTaskController().addTasks(list.toArray(new AbstractTask[list.size()]));
// wait till finish
while (!(isCanceled() || isFinished())) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
LOG.log(Level.SEVERE, "Error in GNPS export/submit task", e);
}
}
}
Aggregations