Search in sources :

Example 71 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project pentaho-kettle by pentaho.

the class JobSaveProgressDialog method open.

public boolean open() {
    boolean retval = true;
    IRunnableWithProgress op = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                rep.save(jobMeta, versionComment, new ProgressMonitorAdapter(monitor));
            } catch (KettleException e) {
                throw new InvocationTargetException(e, "Error saving job");
            }
        }
    };
    try {
        ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
        pmd.run(true, true, op);
    } catch (InvocationTargetException e) {
        new ErrorDialog(shell, "Error saving job", "An error occured saving the job!", e);
        retval = false;
    } catch (InterruptedException e) {
        new ErrorDialog(shell, "Error saving job", "An error occured saving the job!", 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) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 72 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project pentaho-kettle by pentaho.

the class UpgradeRepositoryProgressDialog method open.

public boolean open() {
    boolean retval = true;
    IRunnableWithProgress op = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            // This is running in a new process: copy some KettleVariables info
            // LocalVariables.getInstance().createKettleVariables(Thread.currentThread(),
            // kettleVariables.getLocalThread(), true);
            // --> don't set variables if not running in different thread --> pmd.run(true,true,
            // op);
            // Ask if you want to do a dry run first?
            // 
            MessageBox box = new MessageBox(shell, SWT.YES | SWT.NO);
            box.setMessage(BaseMessages.getString(PKG, "UpgradeRepositoryDialog.DryRunQuestion.Message"));
            box.setText(BaseMessages.getString(PKG, "UpgradeRepositoryDialog.DryRunQuestion.Title"));
            int answer = box.open();
            try {
                if (answer == SWT.YES) {
                    // First do a dry-run
                    // 
                    dryRun = true;
                    rep.createRepositorySchema(new ProgressMonitorAdapter(monitor), upgrade, generatedStatements, true);
                } else {
                    rep.createRepositorySchema(new ProgressMonitorAdapter(monitor), upgrade, generatedStatements, false);
                }
            } catch (KettleException e) {
                log.logError(toString(), Const.getStackTracker(e));
                throw new InvocationTargetException(e, BaseMessages.getString(PKG, "UpgradeRepositoryDialog.Error.CreateUpdate", e.getMessage()));
            }
        }
    };
    try {
        ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
        pmd.run(false, false, op);
    } catch (InvocationTargetException e) {
        log.logError(UpgradeRepositoryProgressDialog.class.toString(), "Error creating/updating repository: " + e.toString());
        log.logError(toString(), Const.getStackTracker(e));
        showErrorDialog(e);
        retval = false;
    } catch (InterruptedException e) {
        log.logError(UpgradeRepositoryProgressDialog.class.toString(), "Error creating/updating repository: " + e.toString());
        log.logError(toString(), Const.getStackTracker(e));
        showErrorDialog(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) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 73 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project pentaho-kettle by pentaho.

the class TransLoadProgressDialog method open.

public TransMeta 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.TransBeforeOpen.id, (objectId == null) ? transname : objectId.toString());
                if (objectId != null) {
                    transInfo = rep.loadTransformation(objectId, versionLabel);
                } else {
                    transInfo = rep.loadTransformation(transname, repdir, new ProgressMonitorAdapter(monitor), true, versionLabel);
                }
                // Call extension point(s) now that the file has been opened
                ExtensionPointHandler.callExtensionPoint(spoon.getLog(), KettleExtensionPoint.TransAfterOpen.id, transInfo);
                if (transInfo.hasMissingPlugins()) {
                    StepMeta stepMeta = transInfo.getStep(0);
                    Display.getDefault().syncExec(() -> {
                        MissingTransDialog missingTransDialog = new MissingTransDialog(shell, transInfo.getMissingTrans(), stepMeta.getStepMetaInterface(), transInfo, stepMeta.getName());
                        if (missingTransDialog.open() == null) {
                            transInfo = null;
                        }
                    });
                }
            } catch (KettleException e) {
                throw new InvocationTargetException(e, BaseMessages.getString(PKG, "TransLoadProgressDialog.Exception.ErrorLoadingTransformation"));
            }
        }
    };
    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, BaseMessages.getString(PKG, "TransLoadProgressDialog.ErrorLoadingTransformation.DialogTitle"), BaseMessages.getString(PKG, "TransLoadProgressDialog.ErrorLoadingTransformation.DialogMessage"), e);
        transInfo = null;
    } catch (InterruptedException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "TransLoadProgressDialog.ErrorLoadingTransformation.DialogTitle"), BaseMessages.getString(PKG, "TransLoadProgressDialog.ErrorLoadingTransformation.DialogMessage"), e);
        transInfo = null;
    }
    return transInfo;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MissingTransDialog(org.pentaho.di.ui.trans.steps.missing.MissingTransDialog) 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) StepMeta(org.pentaho.di.trans.step.StepMeta) KettleRepositoryLostException(org.pentaho.di.repository.KettleRepositoryLostException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 74 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project pentaho-kettle by pentaho.

the class TransPreviewProgressDialog method open.

/**
 * Opens the progress dialog
 * @param showErrorDialogs dictates whether error dialogs should be shown when errors occur - can be set to false
 *                         to let the caller control error dialogs instead.
 * @return a {@link TransMeta}
 */
public TransMeta open(final boolean showErrorDialogs) {
    IRunnableWithProgress op = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            doPreview(monitor, showErrorDialogs);
        }
    };
    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 {
                        trans.stopAll();
                    } catch (Exception e) {
                    /* Ignore */
                    }
                }
            }
        };
        // Start the cancel tracker in the background!
        new Thread(run).start();
        pmd.run(true, true, op);
    } catch (InvocationTargetException e) {
        if (showErrorDialogs) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "TransPreviewProgressDialog.ErrorLoadingTransformation.DialogTitle"), BaseMessages.getString(PKG, "TransPreviewProgressDialog.ErrorLoadingTransformation.DialogMessage"), e);
        }
        transMeta = null;
    } catch (InterruptedException e) {
        if (showErrorDialogs) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "TransPreviewProgressDialog.ErrorLoadingTransformation.DialogTitle"), BaseMessages.getString(PKG, "TransPreviewProgressDialog.ErrorLoadingTransformation.DialogMessage"), e);
        }
        transMeta = null;
    }
    return transMeta;
}
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 75 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project xtext-eclipse by eclipse.

the class TemplateNewProjectWizard method performFinish.

@Override
public boolean performFinish() {
    final IProjectInfo projectInfo = getProjectInfo();
    IRunnableWithProgress op = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                doFinish(projectInfo, monitor);
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            } finally {
                monitor.done();
            }
        }
    };
    try {
        getContainer().run(true, false, op);
    } catch (InterruptedException e) {
        return false;
    } catch (InvocationTargetException e) {
        logger.error(e.getMessage(), e);
        Throwable realException = e.getTargetException();
        // $NON-NLS-1$
        MessageDialog.openError(getShell(), "Error", realException.getMessage());
        return false;
    }
    return true;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IProjectInfo(org.eclipse.xtext.ui.wizard.IProjectInfo) InvocationTargetException(java.lang.reflect.InvocationTargetException) 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