Search in sources :

Example 56 with IRunnableWithProgress

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

Example 57 with IRunnableWithProgress

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

Example 58 with IRunnableWithProgress

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);
    }
}
Also used : ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Collection(java.util.Collection) Display(org.eclipse.swt.widgets.Display)

Example 59 with IRunnableWithProgress

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);
            }
        }
    }
}
Also used : StatesIfDoneProgressMonitor(eu.esdihumboldt.hale.ui.util.io.internal.StatesIfDoneProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) AtomicReference(java.util.concurrent.atomic.AtomicReference) InvocationTargetException(java.lang.reflect.InvocationTargetException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) Display(org.eclipse.swt.widgets.Display) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 60 with IRunnableWithProgress

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();
}
Also used : TransformationReport(eu.esdihumboldt.hale.common.align.transformation.report.TransformationReport) ProgressMonitorIndicator(eu.esdihumboldt.hale.common.core.io.ProgressMonitorIndicator) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) BrowseOrientInstanceCollection(eu.esdihumboldt.hale.common.instance.orient.storage.BrowseOrientInstanceCollection) FilteredInstanceCollection(eu.esdihumboldt.hale.common.instance.model.impl.FilteredInstanceCollection) IOException(java.io.IOException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) ReportService(eu.esdihumboldt.hale.ui.service.report.ReportService) ATransaction(de.fhg.igd.slf4jplus.ATransaction) TransformationService(eu.esdihumboldt.hale.common.align.transformation.service.TransformationService) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

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