Example usage for org.eclipse.jface.operation ModalContext run

List of usage examples for org.eclipse.jface.operation ModalContext run

Introduction

In this page you can find the example usage for org.eclipse.jface.operation ModalContext run.

Prototype

public static void run(IRunnableWithProgress operation, boolean fork, IProgressMonitor monitor, Display display)
        throws InvocationTargetException, InterruptedException 

Source Link

Document

Runs the given runnable in a modal context, passing it a progress monitor.

Usage

From source file:org.talend.sqlbuilder.util.UIUtils.java

License:Open Source License

/**
 * DOC dev Comment method "runWithProgress".
 * // w ww  .j  a v  a 2  s.  c  o  m
 * @param operation
 * @param fork
 * @param monitor
 * @param shell
 */
public static void runWithProgress(final IRunnableWithProgress operation, final boolean fork,
        final IProgressMonitor monitor, final Shell shell) {
    final IRunnableWithProgress progress = new IRunnableWithProgress() {

        @Override
        public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            // monitor.beginTask("test task", scale * total);
            // SubProgressMonitor sm = new SubProgressMonitor(monitor, 1 * scale);
            Thread t = new Thread() {

                @Override
                public void run() {
                    try {
                        operation.run(monitor);
                    } catch (Exception e) {
                        SqlBuilderPlugin.log(Messages.getString("UIUtils.logMessage1"), e); //$NON-NLS-1$
                    }
                }
            };
            t.start();
            try {
                t.join();
            } catch (Exception e) {
                // TODO: handle exception
            }
        }
    };

    Runnable run = new Runnable() {

        @Override
        public void run() {
            try {
                ModalContext.run(progress, fork, monitor, shell.getDisplay());
            } catch (Exception e) {
                SqlBuilderPlugin.log(Messages.getString("UIUtils.logMessage2"), e); //$NON-NLS-1$
            }
        }
    };

    BusyIndicator.showWhile(Display.getDefault(), run);
}

From source file:org.talend.updates.runtime.ui.feature.form.FeaturesSearchForm.java

License:Open Source License

private void doSearch(SearchOption searchOption) {
    final FeatureProgress progress = showProgress();
    execute(new Runnable() {

        @Override/*  w w  w .  j av  a  2s.c o  m*/
        public void run() {
            final Thread thread = Thread.currentThread();
            try {
                if (thread.isInterrupted()) {
                    return;
                }
                ModalContext.run(new IRunnableWithProgress() {

                    @Override
                    public void run(IProgressMonitor monitor)
                            throws InvocationTargetException, InterruptedException {
                        doSearch(monitor, searchOption);
                    }
                }, true, progress.getProgressMonitor(), getDisplay());
            } catch (Exception e1) {
                ExceptionHandler.process(e1);
            }
        }
    });
}

From source file:org.talend.updates.runtime.ui.feature.wizard.dialog.FeaturesUpdateNotificationDialog.java

License:Open Source License

@Override
protected Control createContents(Composite parent) {
    parent.setLayout(new FillLayout());
    Composite panel = new Composite(parent, SWT.NONE);
    panel.setLayout(new FillLayout());
    notificationForm = new FeaturesUpdatesNotificationForm(panel, SWT.NONE, runtimeData,
            runtimeData.getFeaturesManager().createUpdateNotificationItem(true), false) {
        @Override//from   ww w  .j  ava 2  s  .  c o  m
        protected Color getBackgroundColor() {
            return FeaturesUpdateNotificationDialog.this.getBackgroundColor();
        };
    };
    runtimeData.setUpdateNotificationButtonListener(new AbstractNotificationButtonListener() {

        @Override
        public void onInstallUpdatesButtonClicked(SelectionEvent e, FeaturesUpdatesNotificationForm form) {
            try {
                form.setExecuting(true);
                form.enableButtons(false);
                IProgressMonitor monitor = form.showProgress();
                Exception exception[] = new Exception[1];
                ModalContext.run(new IRunnableWithProgress() {

                    @Override
                    public void run(IProgressMonitor monitor)
                            throws InvocationTargetException, InterruptedException {
                        try {
                            installUpdates(monitor, runtimeData, form);
                        } catch (Exception e) {
                            exception[0] = e;
                        }
                    }
                }, true, monitor, Display.getDefault());
                if (exception[0] != null) {
                    throw exception[0];
                }
            } catch (Exception ex) {
                ExceptionHandler.process(ex);
                openExceptionDialog(form, ex);
            } finally {
                if (!form.isDisposed()) {
                    form.hideProgress();
                    form.setExecuting(false);
                    form.enableButtons(true);
                }
            }
        }

        @Override
        public void onShowUpdatesButtonClicked(SelectionEvent e, FeaturesUpdatesNotificationForm form) {
            final FeaturesManagerRuntimeData data = runtimeData;
            data.getDialog().close();

            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    data.setFirstShowTab(FeaturesManagerRuntimeData.TAB_UPDATE);
                    FeaturesManagerWizard wizard = new FeaturesManagerWizard(data);
                    wizard.show(DisplayUtils.getDefaultShell());
                }
            });
        }

        @Override
        public void close() {
            runtimeData.getDialog().close();
        }
    });
    return panel;
}

From source file:org.zend.core.notifications.internal.ui.progress.ProgressNotification.java

License:Open Source License

@Override
protected void startTimer() {
    final ProgressMonitor monitor = new ProgressMonitor(indicator, taskChangeListener);
    shell.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            monitor.setCanceled(true);//from   w  w w .jav  a  2 s  . c om
        }
    });
    try {
        ModalContext.run(runnable, true, monitor, parent.getDisplay());
    } catch (InvocationTargetException e) {
        showErrorDialog(e.getTargetException());
        Activator.log(e);
    } catch (InterruptedException e) {
        Activator.log(e);
    } finally {
        monitor.done();
    }
}