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:ca.mcgill.sable.soot.launching.SootLauncher.java
License:Open Source License
protected void runSootDirectly(String mainClass) { int length = getSootCommandList().getList().size(); String temp[] = new String[length]; getSootCommandList().getList().toArray(temp); String mainProject;//from w w w . j a va 2 s. c o m String realMainClass; if (mainClass.contains(":")) { String[] split = mainClass.split(":"); mainProject = split[0]; realMainClass = split[1]; } else { mainProject = null; realMainClass = mainClass; } newProcessStarting(realMainClass, mainProject); sendSootOutputEvent(realMainClass); sendSootOutputEvent(" "); for (int i = 0; i < temp.length; i++) { sendSootOutputEvent(temp[i]); sendSootOutputEvent(" "); } sendSootOutputEvent("\n"); IRunnableWithProgress op; try { op = new SootRunner(temp, Display.getCurrent(), mainClass); ((SootRunner) op).setParent(this); ModalContext.run(op, true, new NullProgressMonitor(), Display.getCurrent()); } catch (InvocationTargetException e1) { // handle exception System.out.println("InvocationTargetException: " + e1.getMessage()); System.out.println("InvocationTargetException: " + e1.getTargetException()); System.out.println(e1.getStackTrace()); } catch (InterruptedException e2) { // handle cancelation System.out.println("InterruptedException: " + e2.getMessage()); } }
From source file:com.aptana.git.ui.internal.preferences.GithubAccountPageProvider.java
License:Open Source License
private boolean login(boolean test) { final String username = usernameText.getText(); final String password = passwordText.getText(); if (StringUtil.isEmpty(username)) { if (test) { MessageDialog.openError(main.getShell(), Messages.GithubAccountPageProvider_InvalidInputTitle, Messages.GithubAccountPageProvider_EmptyUsername); return false; }/*w ww. j a va 2 s.co m*/ return true; } if (StringUtil.isEmpty(password)) { if (test) { MessageDialog.openError(main.getShell(), Messages.GithubAccountPageProvider_InvalidInputTitle, Messages.GithubAccountPageProvider_EmptyPassword); return false; } return true; } setUILocked(true); firePreValidationStartEvent(); try { ModalContext.run(new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(Messages.GithubAccountPageProvider_ValidatingCredentials, IProgressMonitor.UNKNOWN); try { IStatus status = getGithubManager().login(username, password); if (status.isOK()) { // successful; now re-layout to show the logout components UIUtils.getDisplay().asyncExec(new Runnable() { public void run() { updateUserText(); layout(); } }); fireLoggedInEvent(); } else { throw new InvocationTargetException(new CoreException(status)); } } finally { if (!monitor.isCanceled()) { monitor.done(); } } } }, true, getProgressMonitor(), UIUtils.getDisplay()); } catch (InvocationTargetException e) { if (main != null && !main.isDisposed()) { MessageDialog.openError(main.getShell(), Messages.GithubAccountPageProvider_LoginFailed, e.getTargetException().getMessage()); } return false; } catch (Exception e) { IdeLog.logError(GitUIPlugin.getDefault(), e); } finally { setUILocked(false); firePostValidationEndEvent(); } return true; }
From source file:com.aptana.ide.ui.ftp.dialogs.FTPConnectionPointPropertyDialog.java
License:Open Source License
public boolean testConnection(ConnectionContext context, final IConnectionRunnable connectRunnable) { // WORKAROUND: getting contents after the control is disabled will return empty string if not called here hostText.getText();//from w w w.jav a 2s .c om loginCombo.getText(); passwordText.getText(); remotePathText.getText(); lockUI(true); ((GridData) progressMonitorPart.getLayoutData()).exclude = false; layoutShell(); try { final IBaseRemoteConnectionPoint connectionPoint = isNew ? ftpConnectionPoint : (IBaseRemoteConnectionPoint) CoreIOPlugin.getConnectionPointManager() .cloneConnectionPoint(ftpConnectionPoint); savePropertiesTo(connectionPoint); if (context == null) { context = new ConnectionContext(); context.setBoolean(ConnectionContext.QUICK_CONNECT, true); } context.setBoolean(ConnectionContext.NO_PASSWORD_PROMPT, true); CoreIOPlugin.setConnectionContext(connectionPoint, context); ModalContext.run(new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { try { if (connectRunnable != null) { connectRunnable.beforeConnect(connectionPoint); } connectionPoint.connect(monitor); if (connectRunnable != null) { connectRunnable.afterConnect(connectionPoint, monitor); } } finally { try { connectionPoint.disconnect(monitor); } catch (CoreException e) { IdeLog.logImportant(Activator.getDefault(), StringUtils.EMPTY, e); } } } catch (CoreException e) { throw new InvocationTargetException(e); } finally { monitor.done(); } } }, true, progressMonitorPart, getShell().getDisplay()); return connectionTested = true; } catch (InterruptedException e) { } catch (InvocationTargetException e) { showErrorDialog(e.getTargetException()); } catch (CoreException e) { showErrorDialog(e); } finally { if (!progressMonitorPart.isDisposed()) { ((GridData) progressMonitorPart.getLayoutData()).exclude = true; layoutShell(); lockUI(false); } } return false; }
From source file:com.aptana.jira.ui.preferences.JiraPreferencePageProvider.java
License:Open Source License
private boolean login(boolean test) { final String username = usernameText.getText(); final String password = passwordText.getText(); if (StringUtil.isEmpty(username)) { if (test) { MessageDialog.openError(main.getShell(), Messages.JiraPreferencePageProvider_ERR_InvalidInput_Title, Messages.JiraPreferencePageProvider_ERR_EmptyUsername); return false; }//from w w w . j a v a 2s .c o m return true; } if (StringUtil.isEmpty(password)) { if (test) { MessageDialog.openError(main.getShell(), Messages.JiraPreferencePageProvider_ERR_InvalidInput_Title, Messages.JiraPreferencePageProvider_ERR_EmptyPassword); return false; } return true; } setUILocked(true); firePreValidationStartEvent(); try { ModalContext.run(new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(Messages.JiraPreferencePageProvider_ValidateCredentials, IProgressMonitor.UNKNOWN); try { getJiraManager().login(username, password); // successful; now re-layout to show the logout components UIUtils.getDisplay().asyncExec(new Runnable() { public void run() { updateUserText(); layout(); } }); } catch (JiraException e) { throw new InvocationTargetException(e); } finally { if (!monitor.isCanceled()) { monitor.done(); } } } }, true, getProgressMonitor(), UIUtils.getDisplay()); } catch (InvocationTargetException e) { if (main != null && !main.isDisposed()) { MessageDialog.openError(main.getShell(), Messages.JiraPreferencePageProvider_ERR_LoginFailed_Title, e.getTargetException().getMessage()); } return false; } catch (Exception e) { IdeLog.logError(JiraUIPlugin.getDefault(), e); } finally { setUILocked(false); firePostValidationEndEvent(); } return true; }
From source file:com.aptana.ui.ftp.internal.FTPConnectionPropertyComposite.java
License:Open Source License
public boolean testConnection(ConnectionContext context, final IConnectionRunnable connectRunnable) { // WORKAROUND: getting contents after the control is disabled will return empty string if not called here hostText.getText();// ww w.ja v a 2 s.c om loginCombo.getText(); passwordText.getText(); remotePathText.getText(); lockUI(true); ((GridData) progressMonitorPart.getLayoutData()).exclude = false; listener.layoutShell(); try { final IBaseRemoteConnectionPoint connectionPoint = isNew ? ftpConnectionPoint : (IBaseRemoteConnectionPoint) CoreIOPlugin.getConnectionPointManager() .cloneConnectionPoint(ftpConnectionPoint); savePropertiesTo(connectionPoint); if (context == null) { context = new ConnectionContext(); // $codepro.audit.disable questionableAssignment context.setBoolean(ConnectionContext.QUICK_CONNECT, true); } context.setBoolean(ConnectionContext.NO_PASSWORD_PROMPT, true); CoreIOPlugin.setConnectionContext(connectionPoint, context); ModalContext.run(new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { try { if (connectRunnable != null) { connectRunnable.beforeConnect(connectionPoint); } connectionPoint.connect(monitor); if (connectRunnable != null) { connectRunnable.afterConnect(connectionPoint, monitor); } } finally { try { connectionPoint.disconnect(monitor); } catch (CoreException e) { IdeLog.logWarning(FTPUIPlugin.getDefault(), e); } } } catch (CoreException e) { throw new InvocationTargetException(e); } finally { CoreIOPlugin.clearConnectionContext(connectionPoint); monitor.done(); } } }, true, progressMonitorPart, getShell().getDisplay()); return connectionTested = true; } catch (InterruptedException e) { e.getCause(); } catch (InvocationTargetException e) { showErrorDialog(e.getTargetException()); } catch (CoreException e) { showErrorDialog(e); } finally { if (!progressMonitorPart.isDisposed()) { ((GridData) progressMonitorPart.getLayoutData()).exclude = true; listener.layoutShell(); lockUI(false); } } return false; }
From source file:com.aptana.ui.s3.internal.S3ConnectionPropertyComposite.java
License:Open Source License
public boolean testConnection(ConnectionContext context, final IConnectionRunnable connectRunnable) { // WORKAROUND: getting contents after the control is disabled will return empty string if not called here hostText.getText();//from w ww. ja v a2 s .c om accessKeyText.getText(); passwordText.getText(); remotePathText.getText(); lockUI(true); ((GridData) progressMonitorPart.getLayoutData()).exclude = false; listener.layoutShell(); try { final IBaseRemoteConnectionPoint connectionPoint = isNew ? s3ConnectionPoint : (IBaseRemoteConnectionPoint) CoreIOPlugin.getConnectionPointManager() .cloneConnectionPoint(s3ConnectionPoint); savePropertiesTo(connectionPoint); if (context == null) { context = new ConnectionContext(); context.setBoolean(ConnectionContext.QUICK_CONNECT, true); } context.setBoolean(ConnectionContext.NO_PASSWORD_PROMPT, true); CoreIOPlugin.setConnectionContext(connectionPoint, context); ModalContext.run(new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { try { if (connectRunnable != null) { connectRunnable.beforeConnect(connectionPoint); } connectionPoint.connect(monitor); if (connectRunnable != null) { connectRunnable.afterConnect(connectionPoint, monitor); } } finally { try { connectionPoint.disconnect(monitor); } catch (CoreException e) { IdeLog.logWarning(S3UIPlugin.getDefault(), e); } } } catch (CoreException e) { throw new InvocationTargetException(e); } finally { CoreIOPlugin.clearConnectionContext(connectionPoint); monitor.done(); } } }, true, progressMonitorPart, getShell().getDisplay()); return connectionTested = true; } catch (InterruptedException e) { } catch (InvocationTargetException e) { showErrorDialog(e.getTargetException()); } catch (CoreException e) { showErrorDialog(e); } finally { if (!progressMonitorPart.isDisposed()) { ((GridData) progressMonitorPart.getLayoutData()).exclude = true; listener.layoutShell(); lockUI(false); } } return false; }
From source file:com.atlassian.connector.eclipse.ui.dialogs.ProgressDialog.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 www . ja va 2s . 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. Object state = null; if (activeRunningOperations == 0) { aboutToStart(fork && cancelable); } activeRunningOperations++; try { if (!fork) { lockedUI = true; } ModalContext.run(runnable, fork, getProgressMonitor(), getShell().getDisplay()); lockedUI = false; } finally { activeRunningOperations--; // Stop if this is the last one if (activeRunningOperations <= 0) { stopped(state); } } }
From source file:com.codesourcery.internal.installer.ui.WizardDialog.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 ww w .j a va 2s . 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. Object state = null; if (activeRunningOperations++ == 0) { state = aboutToStart(fork && cancelable); } 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--; } }
From source file:com.github.haixing_hu.swt.window.ApplicationWindowEx.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.//ww w . j ava 2s . co m */ @Override public void run(final boolean fork, boolean cancelable, final IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException { try { operationInProgress = true; final StatusLineManager mgr = getStatusLineManager(); if (mgr == null) { runnable.run(new NullProgressMonitor()); return; } final boolean cancelWasEnabled = mgr.isCancelEnabled(); final Control contents = getContents(); final Display display = contents.getDisplay(); final Shell shell = getShell(); final boolean contentsWasEnabled = contents.getEnabled(); MenuManagerEx manager = getMenuBarManager(); Menu menuBar = null; if (manager != null) { menuBar = manager.getMenu(); manager = null; } boolean menuBarWasEnabled = false; if (menuBar != null) { menuBarWasEnabled = menuBar.getEnabled(); } final Control toolbarControl = getToolBarControl(); boolean toolbarWasEnabled = false; if (toolbarControl != null) { toolbarWasEnabled = toolbarControl.getEnabled(); } final Control coolbarControl = getCoolBarControl(); boolean coolbarWasEnabled = false; if (coolbarControl != null) { coolbarWasEnabled = coolbarControl.getEnabled(); } // Disable the rest of the shells on the current display final Shell[] shells = display.getShells(); final boolean[] enabled = new boolean[shells.length]; for (int i = 0; i < shells.length; i++) { final Shell current = shells[i]; if (current == shell) { continue; } if ((current != null) && !current.isDisposed()) { enabled[i] = current.getEnabled(); current.setEnabled(false); } } final Control currentFocus = display.getFocusControl(); try { contents.setEnabled(false); if (menuBar != null) { menuBar.setEnabled(false); } if (toolbarControl != null) { toolbarControl.setEnabled(false); } if (coolbarControl != null) { coolbarControl.setEnabled(false); } mgr.setCancelEnabled(cancelable); final Exception[] holder = new Exception[1]; BusyIndicator.showWhile(display, new Runnable() { @Override public void run() { try { ModalContext.run(runnable, fork, mgr.getProgressMonitor(), display); } catch (final InvocationTargetException ite) { holder[0] = ite; } catch (final InterruptedException ie) { holder[0] = ie; } } }); if (holder[0] != null) { if (holder[0] instanceof InvocationTargetException) { throw (InvocationTargetException) holder[0]; } else if (holder[0] instanceof InterruptedException) { throw (InterruptedException) holder[0]; } } } finally { operationInProgress = false; // Enable the rest of the shells on the current display for (int i = 0; i < shells.length; i++) { final Shell current = shells[i]; if (current == shell) { continue; } if ((current != null) && !current.isDisposed()) { current.setEnabled(enabled[i]); } } if (!contents.isDisposed()) { contents.setEnabled(contentsWasEnabled); } if ((menuBar != null) && !menuBar.isDisposed()) { menuBar.setEnabled(menuBarWasEnabled); } if ((toolbarControl != null) && !toolbarControl.isDisposed()) { toolbarControl.setEnabled(toolbarWasEnabled); } if ((coolbarControl != null) && !coolbarControl.isDisposed()) { coolbarControl.setEnabled(coolbarWasEnabled); } mgr.setCancelEnabled(cancelWasEnabled); if ((currentFocus != null) && !currentFocus.isDisposed()) { // It's necessary to restore focus after reenabling the controls // because disabling them causes focus to jump elsewhere. // Use forceFocus rather than setFocus to avoid SWT's // search for children which can take focus, so focus // ends up back on the actual control that previously had it. currentFocus.forceFocus(); } } } finally { operationInProgress = false; } }
From source file:com.google.dart.tools.search.internal.ui.util.ExtendedDialogWindow.java
License:Open Source License
@Override 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;/*www . j ava 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--; } }