List of usage examples for org.eclipse.jface.operation IRunnableWithProgress run
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException;
From source file:org.eclipse.php.internal.ui.wizards.FragmentedWizard.java
License:Open Source License
public boolean performFinish() { if (currentFragment != null) currentFragment.exit();// www. ja v a2 s . c om final WizardFragment cFragment = currentFragment; status = Status.OK_STATUS; final List<WizardFragment> list = getAllWizardFragments(); IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) { // enter & exit the remaining pages int index = list.indexOf(cFragment); while (index > 0 && index < list.size() - 1) { final WizardFragment fragment = (WizardFragment) list.get(++index); try { Display.getDefault().syncExec(new Runnable() { public void run() { FragmentedWizardPage page = getFragmentData(fragment); if (page.getControl() == null && pageContainerHook != null) { page.createControl(pageContainerHook); } fragment.enter(); fragment.exit(); } }); } catch (Exception e) { PHPUiPlugin .log(new Status(IStatus.ERROR, PHPUiPlugin.ID, 0, "Could not enter/exit page", e)); //$NON-NLS-1$ } } if (useJob()) { class FinishWizardJob extends Job { public FinishWizardJob() { super(getJobTitle()); } public boolean belongsTo(Object family) { return "org.eclipse.wst.server.ui.family".equals(family); //$NON-NLS-1$ } public IStatus run(IProgressMonitor monitor2) { try { Iterator<WizardFragment> iterator = list.iterator(); while (iterator.hasNext()) executeTask(iterator.next(), FINISH, monitor2); } catch (CoreException ce) { Status status = new Status(IStatus.ERROR, PHPUiPlugin.ID, 0, ce.getLocalizedMessage(), null); PHPUiPlugin.log(status); return status; } return Status.OK_STATUS; } } FinishWizardJob job = new FinishWizardJob(); job.setUser(true); job.schedule(); } else { Iterator<WizardFragment> iterator = list.iterator(); while (iterator.hasNext()) try { WizardFragment fragment = (WizardFragment) iterator.next(); if (!executeTask(fragment, FINISH, monitor)) { status = new Status(IStatus.ERROR, PHPUiPlugin.ID, "Error during wizard page execution."); //$NON-NLS-1$ } } catch (CoreException e) { PHPUiPlugin.log(e); } } } }; Throwable t = null; try { if (getContainer() != null) getContainer().run(true, true, runnable); else runnable.run(new NullProgressMonitor()); if (status.getSeverity() != IStatus.OK) { return false; } return true; } catch (InvocationTargetException te) { PHPUiPlugin.log(new Status(IStatus.ERROR, PHPUiPlugin.ID, 0, "Error finishing task wizard", te)); //$NON-NLS-1$ t = te.getCause(); } catch (Exception e) { PHPUiPlugin.log(new Status(IStatus.ERROR, PHPUiPlugin.ID, 0, "Error finishing task wizard 2", e)); //$NON-NLS-1$ t = e; } if (t instanceof CoreException) { openError(t.getLocalizedMessage(), ((CoreException) t).getStatus()); } else if (t instanceof NullPointerException) openError(PHPUIMessages.FragmentedWizard_7); else openError(t.getLocalizedMessage()); return false; }
From source file:org.eclipse.rap.ui.internal.launch.rwt.shortcut.EntryPointSearchEngine_Test.java
License:Open Source License
protected void setUp() throws Exception { IRunnableContext runnableContext = new IRunnableContext() { public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException { runnable.run(new NullProgressMonitor()); }//from w w w .ja v a 2 s .c o m }; searchEngine = new EntryPointSearchEngine(runnableContext); project = new TestProject(); }
From source file:org.eclipse.rap.ui.internal.launch.rwt.shortcut.RunnableContextHelper_Test.java
License:Open Source License
protected void setUp() throws Exception { IRunnableContext context = new IRunnableContext() { public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException { runnable.run(new NullProgressMonitor()); }/*from w w w . j a va2 s . com*/ }; runnableContextHelper = new RunnableContextHelper(context); }
From source file:org.eclipse.rap.ui.internal.launch.rwt.shortcut.RWTLaunchShortcut_Test.java
License:Open Source License
private static IRunnableContext createRunnableContext() { return new IRunnableContext() { public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException { runnable.run(new NullProgressMonitor()); }/*from ww w . ja va2 s . co m*/ }; }
From source file:org.eclipse.rcptt.internal.launching.ext.ui.AUTLocationBlock.java
License:Open Source License
private void runInDialog(final IRunnableWithProgress run) { final TimeTriggeredProgressMonitorDialog dialog = new TimeTriggeredProgressMonitorDialog( fTab.getControl().getShell(), 500); try {/*from ww w . j a v a2 s.co m*/ dialog.run(true, false, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { run.run(new SyncProgressMonitor(monitor, dialog.getShell().getDisplay())); } }); } catch (InvocationTargetException e) { Activator.log(e); } catch (InterruptedException e) { Activator.log(e); } }
From source file:org.eclipse.rcptt.internal.launching.ext.ui.wizards.NewAUTPage.java
License:Open Source License
private Job runInDialog(final IRunnableWithProgress run) { Job.getJobManager().cancel(JobFamily); Job myJob = new UIJob("Validate install location") { @Override/*from ww w . j a va2 s . c om*/ public IStatus runInUIThread(IProgressMonitor monitor) { final TimeTriggeredProgressMonitorDialog dialog = new TimeTriggeredProgressMonitorDialog(shell, 500); try { dialog.run(true, false, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { run.run(new SyncProgressMonitor(monitor, dialog.getShell().getDisplay())); } }); } catch (InvocationTargetException e) { Activator.log(e); } catch (InterruptedException e) { Activator.log(e); } return Status.OK_STATUS; } @Override public boolean belongsTo(Object family) { return JobFamily.equals(family); } }; myJob.schedule(); return myJob; }
From source file:org.eclipse.scout.rt.ui.swt.busy.SwtBusyUtility.java
License:Open Source License
/** * Must be called outside of the display thread. * <p>//from w w w. j av a 2 s .com * Does NOT call {@link Display#syncExec(Runnable)} since this could lead to dead-locks. * <p> * Blocks and returns once the runnable has finished running. * <p> * Uses {@link BusyIndicator#showWhile(Display, Runnable)} and * {@link ModalContext#run(IRunnableWithProgress, boolean, IProgressMonitor, Display)} */ public static void showBusyIndicator(final SwtBusyHandler busyHandler, final IRunnableWithProgress runnable, IProgressMonitor monitor) { if (!busyHandler.isEnabled()) { return; } final Object lock = new Object(); synchronized (lock) { final Display display = busyHandler.getDisplay(); display.asyncExec(new Runnable() { @Override public void run() { if (!busyHandler.isEnabled()) { return; } BusyIndicator.showWhile(display, new Runnable() { @Override public void run() { try { //use modal context to prevent freezing of the gui ModalContext.run(new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor2) throws InvocationTargetException, InterruptedException { try { runnable.run(monitor2); } finally { synchronized (lock) { lock.notifyAll(); } } } }, true, new NullProgressMonitor(), display); } catch (Throwable t) { LOG.warn("run modal context", t); } } }); } }); try { lock.wait(); } catch (InterruptedException e) { //nop } } }
From source file:org.eclipse.scout.rt.ui.swt.busy.SwtBusyUtility.java
License:Open Source License
/** * Must be called outside of the display thread. * <p>/* w w w .j av a2s . c om*/ * Does NOT call {@link Display#syncExec(Runnable)} since this could lead to dead-locks. * <p> * Blocks and returns once the runnable has finished running. */ public static void showWorkbenchIndicator(final SwtBusyHandler busyHandler, final IRunnableWithProgress runnable) { if (!busyHandler.isEnabled()) { return; } final Object lock = new Object(); synchronized (lock) { final Display display = busyHandler.getDisplay(); display.asyncExec(new Runnable() { @Override public void run() { if (!busyHandler.isEnabled()) { return; } IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (activeWorkbenchWindow == null) { return; } try { activeWorkbenchWindow.run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor workbenchJobMonitor) throws InvocationTargetException, InterruptedException { try { runnable.run(workbenchJobMonitor); } finally { synchronized (lock) { lock.notifyAll(); } } } }); } catch (InvocationTargetException e) { LOG.warn("Exception while showing workbench busy indicator.", e); } catch (InterruptedException e) { LOG.warn("Exception while showing workbench busy indicator.", e); } } }); try { lock.wait(); } catch (InterruptedException e) { //nop } } }
From source file:org.eclipse.search.InternalSearchUI.java
License:Open Source License
/** * Run a runnable. Convert all thrown exceptions to either * InterruptedException or InvocationTargetException *//*ww w .j av a2 s.co m*/ private static void runInCurrentThread(IRunnableWithProgress runnable, IProgressMonitor progressMonitor) throws InterruptedException, InvocationTargetException { try { if (runnable != null) { runnable.run(progressMonitor); } } catch (InvocationTargetException e) { throw e; } catch (InterruptedException e) { throw e; } catch (OperationCanceledException e) { throw new InterruptedException(); } catch (ThreadDeath e) { // Make sure to propagate ThreadDeath, or threads will never fully // terminate throw e; } catch (RuntimeException e) { throw new InvocationTargetException(e); } catch (Error e) { throw new InvocationTargetException(e); } }
From source file:org.eclipse.servicesregistry.testutils.TestContext.java
License:Open Source License
/** * Runs the operation in the current thread * //from ww w .j a v a 2s. c o m * @param operation * the operation * @throws InvocationTargetException * if a {@link Throwable} has been thrown during operation execution. The exception wraps that {@link Throwable} */ private static void runInCurrentThread(final IRunnableWithProgress operation, final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { operation.run(monitor); }