List of usage examples for org.eclipse.jface.operation ModalContext run
public static void run(IRunnableWithProgress operation, boolean fork, IProgressMonitor monitor, Display display) throws InvocationTargetException, InterruptedException
From source file:com.google.dart.tools.ui.feedback.FeedbackDialog.java
License:Open Source License
@Override public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException { progressMonitorPart.getParent().setVisible(true); ModalContext.run(runnable, fork, progressMonitorPart, getShell().getDisplay()); }
From source file:com.google.dart.tools.ui.feedback.FeedbackDialog2.java
License:Open Source License
@Override protected void okPressed() { // Create feedback final FeedbackSubmissionJob2 job = newFeedbackJob(); // Save settings getDialogSettings().put(INCLUDE_DATA_KEY, includeDataCheckbox.getSelection()); getDialogSettings().put(USER_EMAIL_KEY, emailText.getText().trim()); getDialogSettings().put(PUBLIC_KEY, dartbugCheckbox.getSelection()); // Send feedback okButton.setEnabled(false);/*w ww .j a v a 2 s.c o m*/ cancelButton.setEnabled(false); final IStatus[] result = new IStatus[1]; try { ModalContext.run(new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { result[0] = job.run(monitor); } }, true, progressBar, getShell().getDisplay()); } catch (Throwable e) { DartCore.logError("Failed to send feedback", e); result[0] = new Status(IStatus.ERROR, DartCore.PLUGIN_ID, e.toString(), e); } // Report result to the user if (result[0].isOK()) { super.okPressed(); MessageDialog.openInformation(getParentShell(), FeedbackMessages.FeedbackDialog_feedback_sent_label, FeedbackMessages.FeedbackDialog_feedback_sent_details); } else { setReturnCode(CANCEL); MessageDialog.openError(getParentShell(), FeedbackMessages.FeedbackDialog_error_submitting_label, FeedbackMessages.FeedbackDialog_error_submitting_detail); okButton.setEnabled(true); cancelButton.setEnabled(true); } }
From source file:com.helio.boomer.rap.security.login.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;//from w ww . ja v a 2s . c o m setBlockOnOpen(false); open(); final Button okButton = getButton(IDialogConstants.OK_ID); okButton.setText("Login"); okButton.addSelectionListener(new SelectionListener() { 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() { 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:com.nokia.carbide.search.system.internal.ui.util.ExtendedDialogWindow.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. Object state = null;//from w ww.ja v a 2s . c o m try { fActiveRunningOperations++; state = aboutToStart(fork && cancelable); if (fUseEmbeddedProgressMonitorPart) { ModalContext.run(runnable, fork, fProgressMonitorPart, getShell().getDisplay()); } else { new ProgressMonitorDialog(getShell()).run(fork, cancelable, runnable); } } finally { if (state != null) stopped(state); fActiveRunningOperations--; } }
From source file:com.nokia.tools.variant.common.ui.utils.ProgressBarShower.java
License:Open Source License
private void runTask(boolean busy, IRunnableWithProgress progress, WorkbenchWindow activeWorkbenchWindow, IProgressMonitor monitor) {/*from w w w . ja va2s . c o m*/ try { if (busy) { activeWorkbenchWindow.run(true, false, progress); } else { ModalContext.run(progress, true, monitor, Display.getDefault()); } } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:de.bmw.yamaica.ea.ui.EAElementSelectionDialog.java
License:Mozilla Public License
@Override public void run() { try {//from w w w . ja va 2s . co m state = State.LOADING; if (null == eaFile || !eaFile.isFile()) { MessageDialog.openError(getShell(), LOADING_ERROR_TITLE, LOADING_ERROR_MESSAGE); cancelAndClose(); return; } eaProjectLoader = new EAProjectLoader(eaFile, username, password); ModalContext.run(eaProjectLoader, true, progressMonitorPart, getShell().getDisplay()); if (null != eaProjectLoader && treeViewer.getTree().isDisposed() == false) { treeViewer.setInput(eaProjectLoader.getRepository()); } setWidgetEnablements(true); setPath(initialSelection); updateTreeSelection(); } catch (InvocationTargetException e) { disposeEAProjectLoader(); MessageDialog.openError(getShell(), LOADING_ERROR_TITLE, e.getTargetException().getMessage()); cancelAndClose(); } catch (InterruptedException e) { disposeEAProjectLoader(); cancelAndClose(); } finally { state = State.SELECTING; } }
From source file:de.walware.ecommons.ui.dialogs.ExtStatusDialog.java
License:Open Source License
@Override public void run(final boolean fork, final boolean cancelable, final IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException { if ((fOptions & WITH_RUNNABLE_CONTEXT) == 0) { throw new UnsupportedOperationException(); }/*from w w w . j av a 2 s. c o m*/ if (getShell() != null && getShell().isVisible()) { if (fActiveRunningOperations == 0) { // Save control state fProgressLastFocusControl = getShell().getDisplay().getFocusControl(); if (fProgressLastFocusControl != null && fProgressLastFocusControl.getShell() != getShell()) { fProgressLastFocusControl = null; } fProgressLastContentEnableState = ControlEnableState.disable(getDialogArea()); final List<Control> buttons = new ArrayList<Control>(); for (final Control child : getButton(IDialogConstants.OK_ID).getParent().getChildren()) { if (child instanceof Button) { buttons.add(child); } } fProgressLastButtonControls = buttons.toArray(new Control[buttons.size()]); fProgressLastButtonEnableStates = new boolean[fProgressLastButtonControls.length]; for (int i = 0; i < fProgressLastButtonControls.length; i++) { fProgressLastButtonEnableStates[i] = fProgressLastButtonControls[i].getEnabled(); fProgressLastButtonControls[i].setEnabled(false); } // Enable monitor fProgressMonitorCancelButton.setEnabled(cancelable); fProgressMonitorPart.attachToCancelComponent(fProgressMonitorCancelButton); fProgressComposite.setVisible(true); fProgressMonitorCancelButton.setFocus(); } fActiveRunningOperations++; try { ModalContext.run(runnable, fork, fProgressMonitorPart, getShell().getDisplay()); } finally { fActiveRunningOperations--; if (fActiveRunningOperations == 0 && getShell() != null) { fProgressComposite.setVisible(false); fProgressLastContentEnableState.restore(); for (int i = 0; i < fProgressLastButtonControls.length; i++) { fProgressLastButtonControls[i].setEnabled(fProgressLastButtonEnableStates[i]); } fProgressMonitorPart.removeFromCancelComponent(fProgressMonitorCancelButton); if (fProgressLastFocusControl != null) { fProgressLastFocusControl.setFocus(); } } } } else { PlatformUI.getWorkbench().getProgressService().run(fork, cancelable, runnable); } }
From source file:gov.redhawk.ide.sdr.ui.internal.handlers.LaunchDomainManagerWithOptionsDialog.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 va2 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. * */ 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. getOkButton().setEnabled(false); if (this.activeRunningOperations == 0) { 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 && getReturnCode() != Status.CANCEL) { getProgressMonitor().done(); } // Stop if this is the last one this.timeWhenLastJobFinished = System.currentTimeMillis(); stopped(); this.activeRunningOperations--; } if (getOkButton() != null) { getOkButton().setEnabled(true); } }
From source file:msi.gama.lang.gaml.web.workspace.ui.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;/*from w w w . j a va 2 s .co m*/ setBlockOnOpen(false); open(); } }); 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 && (RWT.getApplicationContext() .getAttribute("credential" + RWT.getUISession().getHttpSession()) == null)) { try { // System.out.println("waiting"); Thread.sleep(10); } catch (final Exception e) { e.printStackTrace(); } } processCallbacks = true; // Call the adapter to handle the callbacks if (!isCancelled()) { display.syncExec(new Runnable() { public void run() { close(); } }); } // internalHandle(); // close(); } }, true, new NullProgressMonitor(), Display.getDefault()); } catch (final Exception e) { e.printStackTrace(); } }
From source file:net.geoprism.shapefile.LocalizedWizardDialog.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 ww . jav a 2 s.co 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. * */ 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<String, Object> state = null; if (activeRunningOperations == 0) { state = aboutToStart(fork && cancelable); } activeRunningOperations++; try { if (!fork) { lockedUI = true; } ModalContext.run(runnable, fork, getProgressMonitor(), getShell().getDisplay()); 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) { timeWhenLastJobFinished = System.currentTimeMillis(); stopped(state); } activeRunningOperations--; } }