use of org.eclipse.jface.operation.IRunnableWithProgress in project hale by halestudio.
the class AbstractInstancePainter method update.
/**
* Do a complete update of the way-points. Existing way-points are
* discarded.
*
* @param selection the current selection
*/
public void update(ISelection selection) {
clearWaypoints();
// XXX only mappable type instances for source?!
InstanceCollection instances = instanceService.getInstances(dataSet);
if (selection != null) {
lastSelected = collectReferences(selection);
}
if (instances.isEmpty()) {
return;
}
final AtomicBoolean updateFinished = new AtomicBoolean(false);
IRunnableWithProgress op = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
String taskName;
switch(getDataSet()) {
case SOURCE:
taskName = "Update source data in map";
break;
case TRANSFORMED:
default:
taskName = "Update transformed data in map";
break;
}
monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
// add way-points for instances
InstanceCollection instances = instanceService.getInstances(dataSet);
ResourceIterator<Instance> it = instances.iterator();
try {
while (it.hasNext()) {
Instance instance = it.next();
InstanceWaypoint wp = createWaypoint(instance, instanceService);
if (wp != null) {
if (lastSelected.contains(wp.getValue())) {
// refresh can be
wp.setSelected(true, null);
// ignored because
// it's done for
// addWaypoint
}
// no refresher, as
addWaypoint(wp, null);
// refreshAll is executed
}
}
} finally {
it.close();
monitor.done();
updateFinished.set(true);
}
}
};
try {
ThreadProgressMonitor.runWithProgressDialog(op, false);
} catch (Throwable e) {
log.error("Error running painter update", e);
}
HaleUI.waitFor(updateFinished);
refreshAll();
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project pentaho-kettle by pentaho.
the class GetPreviewTableProgressDialog method open.
public List<Object[]> open() {
IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
db = new Database(Spoon.loggingObject, dbMeta);
try {
db.connect();
if (limit > 0) {
db.setQueryLimit(limit);
}
rows = db.getFirstRows(tableName, limit, new ProgressMonitorAdapter(monitor));
rowMeta = db.getReturnRowMeta();
} catch (KettleException e) {
throw new InvocationTargetException(e, "Couldn't find any rows because of an error :" + e.toString());
} finally {
db.disconnect();
}
}
};
try {
final ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
// Run something in the background to cancel active database queries, forecably if needed!
Runnable run = new Runnable() {
public void run() {
IProgressMonitor monitor = pmd.getProgressMonitor();
while (pmd.getShell() == null || (!pmd.getShell().isDisposed() && !monitor.isCanceled())) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// Ignore
}
}
if (monitor.isCanceled()) {
try {
db.cancelQuery();
} catch (Exception e) {
// Ignore
}
}
}
};
// Start the cancel tracker in the background!
new Thread(run).start();
pmd.run(true, true, op);
} catch (InvocationTargetException e) {
showErrorDialog(e);
return null;
} catch (InterruptedException e) {
showErrorDialog(e);
return null;
}
return rows;
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project pentaho-kettle by pentaho.
the class GetQueryFieldsProgressDialog method open.
public RowMetaInterface open() {
IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
db = new Database(Spoon.loggingObject, dbMeta);
try {
db.connect();
result = db.getQueryFields(sql, false);
if (monitor.isCanceled()) {
throw new InvocationTargetException(new Exception("This operation was cancelled!"));
}
} catch (Exception e) {
throw new InvocationTargetException(e, "Problem encountered determining query fields: " + e.toString());
} finally {
db.disconnect();
}
}
};
try {
final ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
// Run something in the background to cancel active database queries, forecably if needed!
Runnable run = new Runnable() {
public void run() {
IProgressMonitor monitor = pmd.getProgressMonitor();
while (pmd.getShell() == null || (!pmd.getShell().isDisposed() && !monitor.isCanceled())) {
try {
Thread.sleep(250);
} catch (InterruptedException e) {
// Ignore
}
}
if (monitor.isCanceled()) {
try {
db.cancelQuery();
} catch (Exception e) {
// Ignore
}
}
}
};
// Dump the cancel looker in the background!
new Thread(run).start();
pmd.run(true, true, op);
} catch (InvocationTargetException e) {
showErrorDialog(e);
return null;
} catch (InterruptedException e) {
showErrorDialog(e);
return null;
}
return result;
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project pentaho-kettle by pentaho.
the class LoopNodesImportProgressDialog method open.
public String[] open() {
IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
Xpaths = doScan(monitor);
} catch (Exception e) {
e.printStackTrace();
throw new InvocationTargetException(e, BaseMessages.getString(PKG, "GetXMLDateLoopNodesImportProgressDialog.Exception.ErrorScanningFile", filename, e.toString()));
}
}
};
try {
ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
pmd.run(true, true, op);
} catch (InvocationTargetException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "GetXMLDateLoopNodesImportProgressDialog.ErrorScanningFile.Title"), BaseMessages.getString(PKG, "GetXMLDateLoopNodesImportProgressDialog.ErrorScanningFile.Message"), e);
} catch (InterruptedException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "GetXMLDateLoopNodesImportProgressDialog.ErrorScanningFile.Title"), BaseMessages.getString(PKG, "GetXMLDateLoopNodesImportProgressDialog.ErrorScanningFile.Message"), e);
}
return Xpaths;
}
use of org.eclipse.jface.operation.IRunnableWithProgress in project pentaho-kettle by pentaho.
the class JobLoadProgressDialog method open.
public JobMeta open() {
IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
Spoon spoon = Spoon.getInstance();
try {
// Call extension point(s) before the file has been opened
ExtensionPointHandler.callExtensionPoint(spoon.getLog(), KettleExtensionPoint.JobBeforeOpen.id, (objectId == null) ? jobname : objectId.toString());
if (objectId != null) {
jobInfo = rep.loadJob(objectId, versionLabel);
} else {
jobInfo = rep.loadJob(jobname, repdir, new ProgressMonitorAdapter(monitor), versionLabel);
}
// Call extension point(s) now that the file has been opened
ExtensionPointHandler.callExtensionPoint(spoon.getLog(), KettleExtensionPoint.JobAfterOpen.id, jobInfo);
if (jobInfo.hasMissingPlugins()) {
MissingEntryDialog missingDialog = new MissingEntryDialog(shell, jobInfo.getMissingEntries());
if (missingDialog.open() == null) {
jobInfo = null;
}
}
} catch (KettleException e) {
throw new InvocationTargetException(e, "Error loading job");
}
}
};
try {
ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
pmd.run(true, false, op);
} catch (InvocationTargetException e) {
KettleRepositoryLostException krle = KettleRepositoryLostException.lookupStackStrace(e);
if (krle != null) {
throw krle;
}
new ErrorDialog(shell, "Error loading job", "An error occured loading the job!", e);
jobInfo = null;
} catch (InterruptedException e) {
new ErrorDialog(shell, "Error loading job", "An error occured loading the job!", e);
jobInfo = null;
}
return jobInfo;
}
Aggregations