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.jboss.tools.central.editors.SoftwarePage.java

License:Open Source License

@Override
public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
        throws InvocationTargetException, InterruptedException {
    ModalContext.run(runnable, fork, monitor, getDisplay());
}

From source file:org.jboss.tools.common.model.ui.wizards.special.ProgressPart.java

License:Open Source License

public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
        throws InvocationTargetException, InterruptedException {
    // The operation can only be canceled if it is executed in a separate thread.
    // Otherwise the UI is blocked anyway.
    Map<Object, Object> state = null;
    if (activeRunningOperations == 0)
        state = aboutToStart(fork && cancelable);
    activeRunningOperations++;/*from  w ww.j  a v a2s.com*/
    try {
        if (!fork)//If we are not forking do not open other dialogs
            lockedUI = true;
        ModalContext.run(runnable, fork, getProgressMonitor(), getShell().getDisplay());
        lockedUI = false;
    } finally {
        activeRunningOperations--;
        //Stop if this is the last one
        if (state != null)
            stopped(state);
    }
}

From source file:org.jkiss.dbeaver.ui.dialogs.MultiPageWizardDialog.java

License:Open Source License

@Override
public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
        throws InvocationTargetException, InterruptedException {
    // Code copied from WizardDialog
    if (monitorPart != null) {
        monitorPart.setVisible(true);/*from   w  ww . j  a v a2  s  .  com*/
        monitorPart.layout();
        monitorPart.attachToCancelComponent(null);
    }
    ControlEnableState pageEnableState = ControlEnableState.disable(wizardSash);
    ControlEnableState buttonsEnableState = ControlEnableState.disable(getButtonBar());
    try {
        runningOperations++;
        ModalContext.run(runnable, true, monitorPart, getShell().getDisplay());
    } finally {
        runningOperations--;
        buttonsEnableState.restore();
        pageEnableState.restore();
        if (monitorPart != null) {
            monitorPart.done();
            monitorPart.setVisible(false);
        }
    }
}

From source file:org.kalypso.contribs.eclipse.jface.operation.ModalRunnableContext.java

License:Open Source License

/**
 * @see org.eclipse.jface.operation.IRunnableContext#run(boolean, boolean,
 *      org.eclipse.jface.operation.IRunnableWithProgress)
 *//*from ww w  .  j  a va2s .  c om*/
@Override
public void run(final boolean fork, final boolean cancelable, final IRunnableWithProgress runnable)
        throws InvocationTargetException, InterruptedException {
    ModalContext.run(runnable, fork, m_monitor, m_display);
}

From source file:org.modelio.api.ui.ModelioWizardDialog.java

License:Apache License

/**
 * This implementation of IRunnableContext#run(boolean, boolean,
 * IRunnableWithProgress) blocks until the runnable has been run, regardless
 * of the value of <code>fork</code>. It is recommended that
 * <code>fork</code> is set to true in most cases. If <code>fork</code>
 * is set to <code>false</code>, the runnable will run in the UI thread
 * and it is the runnable's responsibility to call
 * <code>Display.readAndDispatch()</code> to ensure UI responsiveness.
 * /*  w  ww  .  jav a 2  s .  c o m*/
 * UI state is saved prior to executing the long-running operation and is
 * restored after the long-running operation completes executing. Any
 * attempt to change the UI state of the wizard in the long-running
 * operation will be nullified when original UI state is restored.
 */
@objid("bc1f49e4-120f-11e2-b5c6-002564c97630")
@Override
public void run(final boolean fork, final boolean cancelable, final IRunnableWithProgress runnable)
        throws InvocationTargetException, InterruptedException {
    // The operation can only be canceled if it is executed in a separate
    // thread.
    // Otherwise the UI is blocked anyway.
    Object state = null;
    if (this.activeRunningOperations == 0) {
        state = aboutToStart(fork && cancelable);
    }
    this.activeRunningOperations++;
    try {
        if (!fork) {
            this.lockedUI = true;
        }
        ModalContext.run(runnable, fork, getProgressMonitor(), getShell().getDisplay());
        this.lockedUI = false;
    } finally {
        // explicitly invoke done() on our progress monitor so that its
        // label does not spill over to the next invocation, see bug 271530
        if (getProgressMonitor() != null) {
            getProgressMonitor().done();
        }
        // Stop if this is the last one
        if (state != null) {
            this.timeWhenLastJobFinished = System.currentTimeMillis();
            stopped(state);
        }
        this.activeRunningOperations--;
    }
}

From source file:org.org.eclipse.core.utils.platform.dialogs.selection.ProgressMonitorDialog.java

License:Open Source License

public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
        throws InvocationTargetException, InterruptedException {
    setCancelable(cancelable);/*  w  ww. j  av  a2  s  . c  o  m*/
    try {
        aboutToRun();
        // Let the progress monitor know if they need to update in UI Thread
        progressMonitor.forked = fork;
        ModalContext.run(runnable, fork, getProgressMonitor(), getShell().getDisplay());
    } finally {
        finishedRun();
    }
}

From source file:org.rdm.authentication.core.AbstractLoginDialog.java

License:Open Source License

public void handle(final Callback[] callbacks) throws IOException {
    this.callbackArray = callbacks;
    final Display display = Display.getDefault();
    display.syncExec(new Runnable() {

        public void run() {
            isCancelled = false;// w ww .  j av a  2 s.  c  o  m
            setBlockOnOpen(false);
            open();
            final Button okButton = getButton(IDialogConstants.OK_ID);
            okButton.setText("Login");
            okButton.addSelectionListener(new SelectionListener() {
                private static final long serialVersionUID = 1L;

                public void widgetSelected(final SelectionEvent event) {
                    processCallbacks = true;
                }

                public void widgetDefaultSelected(final SelectionEvent event) {
                    // nothing to do
                }
            });
            final Button cancel = getButton(IDialogConstants.CANCEL_ID);
            cancel.addSelectionListener(new SelectionListener() {
                private static final long serialVersionUID = 1L;

                public void widgetSelected(final SelectionEvent event) {
                    isCancelled = true;
                    processCallbacks = true;
                }

                public void widgetDefaultSelected(final SelectionEvent event) {
                    // nothing to do
                }
            });
        }
    });
    try {
        ModalContext.setAllowReadAndDispatch(true); // Works for now.
        ModalContext.run(new IRunnableWithProgress() {

            public void run(final IProgressMonitor monitor) {
                // Wait here until OK or cancel is pressed, then let it rip. The event
                // listener
                // is responsible for closing the dialog (in the loginSucceeded
                // event).
                while (!processCallbacks) {
                    try {
                        Thread.sleep(100);
                    } catch (final Exception e) {
                        // do nothing
                    }
                }
                processCallbacks = false;
                // Call the adapter to handle the callbacks
                if (!isCancelled())
                    internalHandle();
            }
        }, true, new NullProgressMonitor(), Display.getDefault());
    } catch (final Exception e) {
        final IOException ioe = new IOException();
        ioe.initCause(e);
        throw ioe;
    }
}

From source file:org.springsource.ide.eclipse.commons.gettingstarted.dashboard.ExtensionsEditor.java

License:Open Source License

public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
        throws InvocationTargetException, InterruptedException {
    // The operation can only be canceled if it is executed in a separate
    // thread./*w  ww. ja  v a  2 s  .  co m*/
    // Otherwise the UI is blocked anyway.
    if (activeRunningOperations == 0) {
        aboutToStart(fork && cancelable);
    }
    activeRunningOperations++;
    try {
        ModalContext.run(runnable, fork, monitor, getEditorSite().getShell().getDisplay());
    } finally {
        activeRunningOperations--;
        // Stop if this is the last one
        if (activeRunningOperations <= 0) {
            stopped();
        }
    }
}

From source file:org.springsource.ide.eclipse.dashboard.internal.ui.discovery.DashboardExtensionsPage.java

License:Open Source License

public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
        throws InvocationTargetException, InterruptedException {
    // The operation can only be canceled if it is executed in a separate
    // thread./*from w  w w. j a  va  2s .c o m*/
    // Otherwise the UI is blocked anyway.
    if (activeRunningOperations == 0) {
        aboutToStart(fork && cancelable);
    }
    activeRunningOperations++;
    try {
        ModalContext.run(runnable, fork, monitor, getManagedForm().getForm().getShell().getDisplay());
    } finally {
        activeRunningOperations--;
        // Stop if this is the last one
        if (activeRunningOperations <= 0) {
            stopped();
        }
    }
}

From source file:org.talend.librariesmanager.ui.dialogs.ExternalModulesInstallDialogWithProgress.java

License:Open Source License

/**
 * This implementation of IRunnableContext#run(boolean, boolean, IRunnableWithProgress) blocks until the runnable
 * has been run, regardless of the value of <code>fork</code>. It is recommended that <code>fork</code> is set to
 * true in most cases. If <code>fork</code> is set to <code>false</code>, the runnable will run in the UI thread and
 * it is the runnable's responsibility to call <code>Display.readAndDispatch()</code> to ensure UI responsiveness.
 * //from  w  w  w  .ja va 2 s.c om
 * UI state is saved prior to executing the long-running operation and is restored after the long-running operation
 * completes executing. Any attempt to change the UI state of the wizard in the long-running operation will be
 * nullified when original UI state is restored.
 * 
 */
public void run(IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException {
    // The operation can only be canceled if it is executed in a separate
    // thread.
    // Otherwise the UI is blocked anyway.
    Object state = null;
    if (activeRunningOperations == 0) {
        state = aboutToStart();
    }
    activeRunningOperations++;
    progressMonitorPart.attachToCancelComponent(null);// nasty hack to enable the cancel button
    try {
        ModalContext.run(runnable, fork, getProgressMonitor(), getShell().getDisplay());
    } finally {
        // explicitly invoke done() on our progress monitor so that its
        // label does not spill over to the next invocation, see bug 271530
        if (getProgressMonitor() != null) {
            getProgressMonitor().done();
        }
        // Stop if this is the last one
        if (state != null) {
            timeWhenLastJobFinished = System.currentTimeMillis();
            stopped(state);
        }
        activeRunningOperations--;
    }
}