List of usage examples for org.eclipse.jface.operation IRunnableWithProgress run
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException;
From source file:org.locationtech.udig.catalog.ui.workflow.WorkflowWizard.java
License:Open Source License
/** * Run using the wizard progress bar./*w ww.j a v a2 s.c o m*/ * * @param runnable * @throws InvocationTargetException * @throws InterruptedException */ private void run(final IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException { IWizardContainer wizardContainer = getContainer(); if (wizardContainer != null && Display.getCurrent() != null) { wizardContainer.run(false, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { runnable.run(monitor); } }); } else { runnable.run(new NullProgressMonitor()); } }
From source file:org.locationtech.udig.catalog.ui.workflow.WorkflowWizardDialog.java
License:Open Source License
/** * Performs the initialization of the workflow. *//*ww w .j a v a 2 s .com*/ protected void initWorkflow() { // start the workflow // TODO: This can potentially freeze up the ui if the fist state // does alot of work in the #init(IProgressMonitor) method. Perhaps // it should be made part of the contract of the dialog that the pipe // already be started before open is called. final Workflow pipe = getWizard().getWorkflow(); final IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { if (!pipe.started) pipe.start(monitor); } }; if (Display.getCurrent() != null) { try { runnable.run(ProgressManager.instance().get()); } catch (Exception e) { throw (RuntimeException) new RuntimeException().initCause(e); } } else { PlatformGIS.syncInDisplayThread(new Runnable() { public void run() { try { PlatformUI.getWorkbench().getActiveWorkbenchWindow().run(false, false, runnable); } catch (Throwable e) { throw new RuntimeException(e); } } }); } }
From source file:org.locationtech.udig.ui.PlatformGIS.java
License:Open Source License
/** * This method runs the runnable in a separate thread. It is useful in cases where a thread must * wait for a long running and potentially blocking operation (for example an IO operation). If * the IO is done in the UI thread then the user interface will lock up. This allows synchronous * execution of a long running thread in the UI thread without locking the UI. * <p>/*w ww. j ava 2 s. c om*/ * When called from the display thread, a {@link #executor} is used to schedule the background * runnable, and we will take over the {@link Display#readAndDispatch()} cycle while waiting * for the background runable to complete. When completed normal display thread execution will * resume. * * @param runnable The runnable(operation) to run * @param monitor the progress monitor to update. * @throws InvocationTargetException * @throws InterruptedException */ public static void runBlockingOperation(final IRunnableWithProgress runnable, final IProgressMonitor monitor2) throws InvocationTargetException, InterruptedException { final IProgressMonitor monitor = monitor2 == null ? new NullProgressMonitor() : monitor2; final InterruptedException[] interruptedException = new InterruptedException[1]; final InvocationTargetException[] invocationTargetException = new InvocationTargetException[1]; Display d = Display.getCurrent(); if (d == null) d = Display.getDefault(); final Display display = d; final AtomicBoolean done = new AtomicBoolean(); final Object mutex = new Object(); done.set(false); Future<Object> future = executor.submit(new Callable<Object>() { @SuppressWarnings("unused") Exception e = new Exception("For debugging"); //$NON-NLS-1$ public Object call() throws Exception { try { runnable.run(new OffThreadProgressMonitor( monitor != null ? monitor : ProgressManager.instance().get(), display)); } catch (InvocationTargetException ite) { invocationTargetException[0] = ite; } catch (InterruptedException ie) { interruptedException[0] = ie; } finally { done.set(true); synchronized (mutex) { mutex.notify(); } } return null; } }); while (!monitor.isCanceled() && !done.get() && !Thread.interrupted()) { Thread.yield(); if (Display.getCurrent() == null) { wait(mutex, 200); } else { try { if (!d.readAndDispatch()) { wait(mutex, 200); } } catch (Exception e) { UiPlugin.log("Error occurred while waiting for an operation to complete", e); //$NON-NLS-1$ } } } if (monitor.isCanceled()) { future.cancel(true); } if (interruptedException[0] != null) throw interruptedException[0]; else if (invocationTargetException[0] != null) throw invocationTargetException[0]; }
From source file:org.occiware.clouddesigner.occi.infrastructure.connector.vmware.utils.thread.UIDialog.java
License:Open Source License
/** * Encapsulate in a thread the runnable with dialog progress if in cloud * designer mode/* w w w. ja v a 2s. c om*/ * * @param runnable */ public static void executeActionThread(final IRunnableWithProgress runnable, final String actionName) { try { IRunnableWithProgress runnableWithProgress = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { if (!monitor.isCanceled()) { monitor.beginTask("Operation in progress : " + actionName, 0); runnable.run(monitor); monitor.done(); } else { return; } } }; Shell shell = getCurrentShell(); ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell); dialog.setOpenOnRun(true); dialog.run(true, true, runnableWithProgress); } catch (IllegalStateException | InvocationTargetException | InterruptedException ex) { LOGGER.error("Error while executing an action task : " + ex.getMessage()); ex.printStackTrace(); } }
From source file:org.python.pydev.customizations.app_engine.wizards.AppEngineConfigWizardPageTestWorkbench.java
License:Open Source License
public void testCreateLaunchAndDebugGoogleAppProject() throws Exception { final Display display = Display.getDefault(); final Boolean[] executed = new Boolean[] { false }; display.syncExec(new Runnable() { public void run() { final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); Composite pageContainer = new Composite(shell, 0); AppEngineWizard appEngineWizard = new AppEngineWizard(); appEngineWizard.setContainer(new IWizardContainer() { public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException { runnable.run(new NullProgressMonitor()); }//from www . j a va2s.c o m public void updateWindowTitle() { throw new RuntimeException("Not implemented"); } public void updateTitleBar() { throw new RuntimeException("Not implemented"); } public void updateMessage() { throw new RuntimeException("Not implemented"); } public void updateButtons() { throw new RuntimeException("Not implemented"); } public void showPage(IWizardPage page) { throw new RuntimeException("Not implemented"); } public Shell getShell() { throw new RuntimeException("Not implemented"); } public IWizardPage getCurrentPage() { return null; } }); appEngineWizard.init(PlatformUI.getWorkbench(), new StructuredSelection()); appEngineWizard.addPages(); appEngineWizard.createPageControls(pageContainer); IWizardPage[] pages = appEngineWizard.getPages(); NewProjectNameAndLocationWizardPage nameAndLocation = (NewProjectNameAndLocationWizardPage) pages[0]; AppEngineConfigWizardPage appEnginePage = (AppEngineConfigWizardPage) pages[1]; assertFalse(nameAndLocation.isPageComplete()); nameAndLocation.setProjectName("AppEngineTest"); assertTrue(nameAndLocation.isPageComplete()); assertFalse(appEnginePage.isPageComplete()); appEnginePage.setAppEngineLocationFieldValue( TestDependent.GOOGLE_APP_ENGINE_LOCATION + "invalid_path_xxx"); assertFalse(appEnginePage.isPageComplete()); appEnginePage.setAppEngineLocationFieldValue(TestDependent.GOOGLE_APP_ENGINE_LOCATION); assertTrue(appEnginePage.isPageComplete()); assertTrue(appEngineWizard.performFinish()); IProject createdProject = appEngineWizard.getCreatedProject(); PythonNature nature = PythonNature.getPythonNature(createdProject); Map<String, String> expected = new HashMap<String, String>(); expected.put(AppEngineConstants.GOOGLE_APP_ENGINE_VARIABLE, new File(TestDependent.GOOGLE_APP_ENGINE_LOCATION).getAbsolutePath()); IPythonPathNature pythonPathNature = nature.getPythonPathNature(); try { assertEquals(expected, pythonPathNature.getVariableSubstitution()); String projectExternalSourcePath = pythonPathNature.getProjectExternalSourcePath(false); assertTrue( projectExternalSourcePath.indexOf(AppEngineConstants.GOOGLE_APP_ENGINE_VARIABLE) != -1); projectExternalSourcePath = pythonPathNature.getProjectExternalSourcePath(true); assertTrue( projectExternalSourcePath.indexOf(AppEngineConstants.GOOGLE_APP_ENGINE_VARIABLE) == -1); } catch (Exception e) { throw new RuntimeException(e); } // goToManual(); executed[0] = true; } }); assertTrue(executed[0]); }
From source file:org.search.niem.uml.evl.validation.ModelValidator.java
License:Open Source License
private void handleDiagnostic(final Diagnostic diagnostic) { final EclipseResourcesUtil markerHelper = new EclipseResourcesUtil(); final IRunnableWithProgress operation = markerHelper .getWorkspaceModifyOperation(new IRunnableWithProgress() { @Override/*w ww . j a v a2 s. c o m*/ public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { if (resource.getResourceSet() == null) { // the resource editor is closed return; } markerHelper.deleteMarkers(resource); for (final Diagnostic childDiagnostic : diagnostic.getChildren()) { markerHelper.createMarkers(resource, childDiagnostic); } } }); Display.getDefault().asyncExec(new Runnable() { @Override public void run() { try { operation.run(new NullProgressMonitor()); } catch (final InvocationTargetException e) { Activator.INSTANCE.log(e); } catch (final InterruptedException e) { // no-op } } }); }
From source file:org.springframework.ide.eclipse.boot.dash.test.mocks.MockRunnableContext.java
License:Open Source License
@Override public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException { //TODO: we are ignoring the 'fork' flag. Is that bad? runnable.run(new NullProgressMonitor()); }
From source file:org.springframework.ide.eclipse.boot.test.BootProjectTestHarness.java
License:Open Source License
public static IProject createPredefinedMavenProject(final String projectName, final String bundleName) throws CoreException, Exception { IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); if (project.exists()) { return project; }//from w w w.j a v a 2 s.co m StsTestUtil.setAutoBuilding(false); ImportConfiguration importConf = new ImportConfiguration() { @Override public String getProjectName() { return projectName; } @Override public String getLocation() { return ResourcesPlugin.getWorkspace().getRoot().getLocation().append(projectName).toString(); } @Override public CodeSet getCodeSet() { File sourceWorkspace = new File(StsTestUtil.getSourceWorkspacePath(bundleName)); File sourceProject = new File(sourceWorkspace, projectName); return new CopyFromFolder(projectName, sourceProject); } }; final IRunnableWithProgress importOp = BuildType.MAVEN.getDefaultStrategy().createOperation(importConf); Job runner = new Job("Import " + projectName) { @Override protected IStatus run(IProgressMonitor monitor) { try { importOp.run(monitor); } catch (Throwable e) { return ExceptionUtil.status(e); } return Status.OK_STATUS; } }; runner.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule()); runner.schedule(); waitForImportJob(project, runner); // BootProjectTestHarness.assertNoErrors(project); return project; }
From source file:org.springframework.ide.eclipse.boot.wizard.guides.GSImportWizardModel.java
License:Open Source License
/** * Performs the final step of the wizard when user clicks on Finish button. * @throws InterruptedException/*from www . ja va 2 s.c om*/ * @throws InvocationTargetException */ public boolean performFinish(IProgressMonitor mon) throws InvocationTargetException, InterruptedException { //The import will be carried out with whatever the currently selected values are // in all the input fields / variables / widgets. GSContent g = guide.getValue(); ImportStrategy is = importStrategy.getValue(); Set<String> codesetNames = codesets.getValue(); mon.beginTask("Import guide content", codesetNames.size() + 1); try { for (String name : codesetNames) { CodeSet cs = g.getCodeSet(name); if (cs == null) { //Ignore 'invalid' codesets. This is a bit of a hack so that we can retain selected codeset names // across guide selection changes. To do that we remember 'selected' cs names even if they // aren't valid for the current guide. That way the checkbox state stays consistent // when switching between guides (otherwise 'invalid' names would have to be cleared when switching to // a guide). mon.worked(1); } else { IRunnableWithProgress oper = is.createOperation(ImportUtils.importConfig(g, cs)); oper.run(SubMonitor.convert(mon, 1)); } } if (enableOpenHomePage.getValue()) { openHomePage(); } return true; } catch (UIThreadDownloadDisallowed e) { //This shouldn't be possible... Finish button won't be enabled unless all is validated. //This implies the content has been downloaded (can't be validated otherwise). BootWizardActivator.log(e); return false; } finally { mon.done(); } }
From source file:org.springframework.ide.eclipse.boot.wizard.NewSpringBootWizardModel.java
License:Open Source License
public void performFinish(IProgressMonitor mon) throws InvocationTargetException, InterruptedException { mon.beginTask("Importing " + baseUrl.getValue(), 4); updateUsageCounts();/*from w w w .j a v a 2 s. co m*/ preferredSelections.save(this); DownloadManager downloader = null; try { downloader = new DownloadManager(urlConnectionFactory).allowUIThread(allowUIThread); DownloadableItem zip = new DownloadableItem(newURL(downloadUrl.getValue()), downloader); String projectNameValue = projectName.getValue(); CodeSet cs = CodeSet.fromZip(projectNameValue, zip, new Path("/")); ImportStrategy strat = getImportStrategy(); if (strat == null) { strat = BuildType.GENERAL.getDefaultStrategy(); } IRunnableWithProgress oper = strat .createOperation(ImportUtils.importConfig(new Path(location.getValue()), projectNameValue, cs)); oper.run(SubMonitor.convert(mon, 3)); IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectNameValue); addToWorkingSets(project, SubMonitor.convert(mon, 1)); } catch (IOException e) { throw new InvocationTargetException(e); } finally { if (downloader != null) { downloader.dispose(); } mon.done(); } }