Search in sources :

Example 66 with IRunnableWithProgress

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();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 67 with IRunnableWithProgress

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;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) Database(org.pentaho.di.core.database.Database) ProgressMonitorAdapter(org.pentaho.di.core.ProgressMonitorAdapter) InvocationTargetException(java.lang.reflect.InvocationTargetException) KettleException(org.pentaho.di.core.exception.KettleException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 68 with IRunnableWithProgress

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;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) Database(org.pentaho.di.core.database.Database) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 69 with IRunnableWithProgress

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;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 70 with IRunnableWithProgress

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;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Spoon(org.pentaho.di.ui.spoon.Spoon) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ProgressMonitorAdapter(org.pentaho.di.core.ProgressMonitorAdapter) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) MissingEntryDialog(org.pentaho.di.ui.job.entries.missing.MissingEntryDialog) KettleRepositoryLostException(org.pentaho.di.repository.KettleRepositoryLostException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Aggregations

IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)417 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)397 InvocationTargetException (java.lang.reflect.InvocationTargetException)386 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)194 CoreException (org.eclipse.core.runtime.CoreException)123 ArrayList (java.util.ArrayList)86 IStatus (org.eclipse.core.runtime.IStatus)67 IOException (java.io.IOException)65 List (java.util.List)54 Status (org.eclipse.core.runtime.Status)53 IFile (org.eclipse.core.resources.IFile)51 File (java.io.File)47 Shell (org.eclipse.swt.widgets.Shell)44 IProject (org.eclipse.core.resources.IProject)40 PartInitException (org.eclipse.ui.PartInitException)32 IPath (org.eclipse.core.runtime.IPath)26 Display (org.eclipse.swt.widgets.Display)26 IResource (org.eclipse.core.resources.IResource)25 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)24 Path (org.eclipse.core.runtime.Path)23