use of org.eclipse.jface.operation.IRunnableWithProgress in project pentaho-kettle by pentaho.
the class SaveProgressDialog method open.
public boolean open() {
boolean retval = true;
IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
rep.save(meta, versionComment, new ProgressMonitorAdapter(monitor));
} catch (KettleException e) {
throw new InvocationTargetException(e, BaseMessages.getString(PKG, "TransSaveProgressDialog.Exception.ErrorSavingTransformation") + e.toString());
}
}
};
try {
ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
pmd.run(true, true, op);
} catch (InvocationTargetException e) {
MessageDialog errorDialog = new MessageDialog(shell, BaseMessages.getString(PKG, "TransSaveProgressDialog.UnableToSave.DialogTitle"), null, BaseMessages.getString(PKG, "TransSaveProgressDialog.UnableToSave.DialogMessage"), MessageDialog.ERROR, new String[] { BaseMessages.getString(PKG, "TransSaveProgressDialog.UnableToSave.Close") }, 0);
errorDialog.open();
retval = false;
} catch (InterruptedException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "TransSaveProgressDialog.ErrorSavingTransformation.DialogTitle"), BaseMessages.getString(PKG, "TransSaveProgressDialog.ErrorSavingTransformation.DialogMessage"), e);
retval = false;
}
return retval;
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project pentaho-kettle by pentaho.
the class TextFileCSVImportProgressDialog method open.
public String open() {
IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
message = doScan(monitor);
} catch (Exception e) {
e.printStackTrace();
throw new InvocationTargetException(e, BaseMessages.getString(PKG, "TextFileCSVImportProgressDialog.Exception.ErrorScanningFile", "" + rownumber, debug, e.toString()));
}
}
};
try {
ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
pmd.run(true, true, op);
} catch (InvocationTargetException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "TextFileCSVImportProgressDialog.ErrorScanningFile.Title"), BaseMessages.getString(PKG, "TextFileCSVImportProgressDialog.ErrorScanningFile.Message"), e);
} catch (InterruptedException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "TextFileCSVImportProgressDialog.ErrorScanningFile.Title"), BaseMessages.getString(PKG, "TextFileCSVImportProgressDialog.ErrorScanningFile.Message"), e);
}
return message;
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project hale by halestudio.
the class CodeListSelectionDialog method setupViewer.
/**
* @see AbstractViewerSelectionDialog#setupViewer(StructuredViewer, Object)
*/
@Override
protected void setupViewer(final TreeViewer viewer, final CodeListRef initialSelection) {
viewer.setLabelProvider(new CodeListLabelProvider());
viewer.setContentProvider(new CodeListContentProvider());
ProgressMonitorDialog dlg = new ProgressMonitorDialog(getShell());
final Display display = Display.getCurrent();
try {
dlg.run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Loading available code lists from INSPIRE registry", IProgressMonitor.UNKNOWN);
final Collection<CodeListRef> codeLists = RegistryCodeLists.loadCodeLists().values();
display.asyncExec(new Runnable() {
@Override
public void run() {
viewer.setInput(codeLists);
if (initialSelection != null) {
viewer.setSelection(new StructuredSelection(initialSelection));
}
}
});
monitor.done();
}
});
} catch (InvocationTargetException | InterruptedException e) {
throw new IllegalStateException("Failed to load code lists", e);
}
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project hale by halestudio.
the class ThreadProgressMonitor method runWithProgressDialog.
/**
* Run the given operation in a forked thread with a progress monitor dialog
* or in the current thread with a sub progress monitor if possible.
*
* @param op the operation to execute
* @param isCancelable if the operation can be canceled
* @throws Exception if any error occurs executing the operation
*/
public static void runWithProgressDialog(final IRunnableWithProgress op, final boolean isCancelable) throws Exception {
IProgressMonitor pm = getCurrent();
if (pm == null) {
// no current progress monitor associated to thread, so
// in display thread, launch a new progress monitor dialog
final Display display = PlatformUI.getWorkbench().getDisplay();
final AtomicReference<Exception> error = new AtomicReference<Exception>();
final IRunnableWithProgress progressOp = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
// create a custom progress monitor to be able to decide
// whether the progress is done
StatesIfDoneProgressMonitor cpm = new StatesIfDoneProgressMonitor(monitor);
// register the progress monitor
register(cpm);
try {
op.run(cpm);
} finally {
// deregister the progress monitor
remove(cpm);
}
}
};
display.syncExec(new Runnable() {
@Override
public void run() {
try {
new ProgressMonitorDialog(display.getActiveShell()).run(true, isCancelable, progressOp);
} catch (Exception e) {
error.set(e);
}
}
});
if (error.get() != null) {
throw error.get();
}
} else {
// progress monitor associated to this thread, so
// run the operation in the same thread
boolean useOriginalMonitor = false;
if (pm instanceof StatesIfDoneProgressMonitor) {
useOriginalMonitor = ((StatesIfDoneProgressMonitor) pm).isDone();
}
if (useOriginalMonitor) {
// use the original monitor
// reset subtask name
pm.subTask("");
op.run(pm);
} else {
// use a sub progress monitor
IProgressMonitor sm = new StatesIfDoneProgressMonitor(new SubProgressMonitor(pm, 0, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
register(sm);
try {
op.run(sm);
} finally {
remove(sm);
}
}
}
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project hale by halestudio.
the class OrientInstanceService method performTransformation.
/**
* Perform the transformation
*
* @return if the transformation was successful
*/
protected boolean performTransformation() {
final TransformationService ts = getTransformationService();
if (ts == null) {
log.userError("No transformation service available");
return false;
}
final AtomicBoolean transformationFinished = new AtomicBoolean(false);
final AtomicBoolean transformationCanceled = new AtomicBoolean(false);
IRunnableWithProgress op = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
Alignment alignment = getAlignmentService().getAlignment();
if (alignment.getActiveTypeCells().isEmpty()) {
// early exit if there are no type relations
return;
}
// determine if there are any active type cells w/o source
boolean transformEmpty = false;
for (Cell cell : alignment.getActiveTypeCells()) {
if (cell.getSource() == null || cell.getSource().isEmpty()) {
transformEmpty = true;
break;
}
}
InstanceCollection sources = getInstances(DataSet.SOURCE);
if (!transformEmpty && sources.isEmpty()) {
return;
}
HaleOrientInstanceSink sink = new HaleOrientInstanceSink(transformed, true);
TransformationReport report;
ATransaction trans = log.begin("Instance transformation");
try {
report = ts.transform(alignment, sources, sink, HaleUI.getServiceProvider(), new ProgressMonitorIndicator(monitor));
// publish report
ReportService rs = PlatformUI.getWorkbench().getService(ReportService.class);
rs.addReport(report);
} finally {
try {
sink.close();
} catch (IOException e) {
// ignore
}
trans.end();
}
} finally {
// remember if canceled
if (monitor.isCanceled()) {
transformationCanceled.set(true);
}
// transformation finished
transformationFinished.set(true);
}
}
};
try {
ThreadProgressMonitor.runWithProgressDialog(op, ts.isCancelable());
} catch (Throwable e) {
log.error("Error starting transformation process", e);
}
// wait for transformation to complete
HaleUI.waitFor(transformationFinished);
return !transformationCanceled.get();
}
Aggregations