List of usage examples for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress
IRunnableWithProgress
From source file:com.ebmwebsourcing.petals.common.extensions.internal.wizards.WebServiceClientWizard.java
License:Open Source License
@Override public boolean performFinish() { final IContainer container = this.mainPage.getOutputContainer(); final String wsdlUrl = this.mainPage.getWsdlUri().toString(); IRunnableWithProgress op = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { monitor.beginTask("Java generation in progress...", 10); // Count the "clients" that are already in the container container.refreshLocal(IResource.DEPTH_INFINITE, monitor); List<IFile> clientsBefore = ResourceUtils.getFilesByRegexp(container, CLIENT_PATTERN); monitor.worked(2);//from www .ja v a2 s .c o m // Generate the Java client monitor.worked(2); WsdlExtUtils.generateWebServiceClient(wsdlUrl, container.getLocation().toString()); monitor.worked(3); // Refresh the project (and build it if required) container.refreshLocal(IResource.DEPTH_INFINITE, monitor); if (container.getProject().hasNature(JavaCore.NATURE_ID)) container.getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor); // Find the client class WebServiceClientWizard.this.resourcesToSelect = ResourceUtils.getFilesByRegexp(container, CLIENT_PATTERN); WebServiceClientWizard.this.resourcesToSelect.removeAll(clientsBefore); monitor.worked(2); } catch (Exception e) { throw new InvocationTargetException(e); } finally { monitor.done(); } } }; try { // Generate the client getContainer().run(true, false, op); // Open the client file Display.getDefault().asyncExec(new Runnable() { public void run() { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); try { for (IFile f : WebServiceClientWizard.this.resourcesToSelect) { IDE.openEditor(page, f, true); } } catch (PartInitException e) { PetalsCommonWsdlExtPlugin.log(e, IStatus.WARNING); } } }); // Select it in the explorer ResourceUtils.selectResourceInJavaView(true, this.resourcesToSelect); } catch (Exception e) { PetalsCommonWsdlExtPlugin.log(e, IStatus.ERROR); } return true; }
From source file:com.ebmwebsourcing.petals.common.extensions.internal.wizards.WSDLtoJavaWizard.java
License:Open Source License
@Override public boolean performFinish() { IContainer container = this.mainPage.getOutputContainer(); final String location = container.getLocation().toString(); final String wsdlUrl = this.mainPage.getWsdlUri().toString(); IRunnableWithProgress op = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { monitor.beginTask("Java generation in progress...", 6); monitor.worked(2);//from www . j a va2 s .c om WsdlExtUtils.generateJavaCode(wsdlUrl, location); monitor.worked(3); } catch (Exception e) { throw new InvocationTargetException(e); } finally { monitor.done(); } } }; try { getContainer().run(true, false, op); container.refreshLocal(IResource.DEPTH_INFINITE, null); ResourceUtils.selectResourceInJavaView(true, container); } catch (Exception e) { PetalsCommonWsdlExtPlugin.log(e, IStatus.ERROR); } return true; }
From source file:com.ebmwebsourcing.petals.common.internal.commands.RefreshCategoryHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { // Check the target view IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart(); if (part instanceof CommonNavigator) { final CommonViewer viewer = ((CommonNavigator) part).getCommonViewer(); // Check the selection ISelection s = null;//from w w w . j a va 2 s. c o m try { s = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection(); } catch (Exception e1) { PetalsCommonPlugin.log(e1, IStatus.WARNING); } if (s != null && !s.isEmpty()) { final PetalsProjectCategory category = (PetalsProjectCategory) ((IStructuredSelection) s) .getFirstElement(); IRunnableWithProgress irwp = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Refresh in progress...", 2); // Refresh the workspace try { ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, monitor); PetalsProjectManager.INSTANCE.rebuildCategoryAssociations(); } catch (CoreException e1) { PetalsCommonPlugin.log(e1, IStatus.WARNING); } finally { // Refresh the category contents monitor.worked(1); Display.getDefault().asyncExec(new Runnable() { @Override public void run() { viewer.refresh(category, true); } }); monitor.done(); } } }; // Run it try { IProgressService ps = PlatformUI.getWorkbench().getProgressService(); ps.busyCursorWhile(irwp); } catch (InterruptedException e) { // nothing } catch (InvocationTargetException e) { PetalsCommonPlugin.log(e, IStatus.ERROR); } } } return null; }
From source file:com.ebmwebsourcing.petals.components.drivers.ZipUrlInputDialog.java
License:Open Source License
@Override protected void okPressed() { // Parse the jbi.xml of the URL ProgressMonitorDialog dlg = new ProgressMonitorDialog(getShell()); dlg.setOpenOnRun(true);// w ww. j av a 2 s. c om try { dlg.run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { // To report progression and support cancellation, the parsing is made in another thread final AtomicBoolean isParsed = new AtomicBoolean(false); Thread parsingThread = new Thread() { @Override public void run() { try { URI uri = UriAndUrlHelper.urlToUri(getValue()); ZipUrlInputDialog.this.slProperties = ArtifactArchiveUtils .getSharedLibraryVersion(uri); } catch (InvalidJbiXmlException e) { PetalsComponentsPlugin.log(e, IStatus.ERROR); } finally { isParsed.set(true); } } }; try { monitor.beginTask("", IProgressMonitor.UNKNOWN); parsingThread.start(); while (!isParsed.get()) { Thread.sleep(500); monitor.worked(2); // Cancelled operation? Let the thread finish its job... if (monitor.isCanceled()) { ZipUrlInputDialog.this.cancelled = true; break; } } } finally { monitor.done(); } } }); } catch (InvocationTargetException e) { PetalsComponentsPlugin.log(e, IStatus.ERROR); } catch (InterruptedException e) { // nothing } // Close the dialog super.okPressed(); }
From source file:com.ebmwebsourcing.petals.services.explorer.sources.EndpointSource.java
License:Open Source License
/** * @return the serviceUnits/*from ww w . j a v a 2 s. com*/ */ public final Collection<ServiceUnitBean> getServiceUnits() { if (this.serviceUnits == null) { final IRunnableWithProgress rwp = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { monitor.beginTask("Getting service units for " + EndpointSource.this.name + "...", IProgressMonitor.UNKNOWN); EndpointSource.this.serviceUnits = refreshServiceUnits(monitor); } finally { monitor.done(); } } }; Display.getDefault().syncExec(new Runnable() { @Override public void run() { try { PlatformUI.getWorkbench().getActiveWorkbenchWindow().run(false, false, rwp); } catch (InvocationTargetException e) { PetalsServicesPlugin.log(e, IStatus.ERROR); } catch (InterruptedException e) { // nothing } } }); } return this.serviceUnits; }
From source file:com.ebmwebsourcing.petals.services.sa.commands.SaFastExportCommandHandler.java
License:Open Source License
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { // Define the objects processing final List<IStatus> errors = new ArrayList<IStatus>(); final List<IResource> resourcesToSelect = new ArrayList<IResource>(); IRunnableWithProgress op = new IRunnableWithProgress() { @Override/*www.j av a 2 s . co m*/ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Service Assembly export in progress...", IProgressMonitor.UNKNOWN); try { for (IProject p : SaFastExportCommandHandler.this.saProjects) { monitor.subTask(p.getName()); String outputDirectoryLocation = p.getLocation().toString(); IStatus s = ExportUtils.exportSaProject(outputDirectoryLocation, p, monitor); if (!s.isOK()) errors.add(s); monitor.worked(5); resourcesToSelect.add(p.getFile(p.getName() + ".zip")); } } finally { monitor.done(); } } }; // Start processing IWorkbench wb = PlatformUI.getWorkbench(); IProgressService ps = wb.getProgressService(); try { ps.runInUI(ps, op, null); } catch (InvocationTargetException e) { IStatus status = StatusUtils.createStatus(e, ""); errors.add(status); } catch (InterruptedException e) { // nothing } // Select the resulting files for (IResource res : resourcesToSelect) { try { res.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); } catch (CoreException e) { PetalsServicesPlugin.log(e, IStatus.ERROR); } } IResource[] resources = new IResource[resourcesToSelect.size()]; ResourceUtils.selectResourceInPetalsExplorer(true, resourcesToSelect.toArray(resources)); // Errors to display if (!errors.isEmpty()) { IStatus[] children = new IStatus[errors.size()]; MultiStatus status = new MultiStatus(PetalsServicesPlugin.PLUGIN_ID, 0, errors.toArray(children), (errors.size() > 1 ? "Errors" : "An error") + " occured during the export.", null); PetalsServicesPlugin.getDefault().getLog().log(status); ErrorDialog dlg = new ErrorDialog(new Shell(), "Export Errors", status.getMessage(), status, IStatus.ERROR); dlg.open(); } return null; }
From source file:com.ebmwebsourcing.petals.services.sa.export.SaExportWizard.java
License:Open Source License
/** * * @return//from w w w .j a v a 2 s .c om */ private IRunnableWithProgress getExportOperation() { IRunnableWithProgress op = null; switch (this.page.getExportMode()) { case IN_PROJECT: op = new WorkspaceModifyOperation() { @Override protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { monitor.beginTask("Export in progress...", IProgressMonitor.UNKNOWN); try { Collection<IProject> projects = SaExportWizard.this.page.getSaProjectsToExport(); for (IProject p : projects) { if (monitor.isCanceled()) break; monitor.subTask(p.getName()); String outputDirectoryLocation = p.getLocation().toString(); IStatus s = ExportUtils.exportSaProject(outputDirectoryLocation, p, monitor); if (!s.isOK()) SaExportWizard.this.status.add(s); monitor.worked(2); try { p.refreshLocal(IResource.DEPTH_ONE, monitor); SaExportWizard.this.resourcesToSelect.add(p.getFile(p.getName() + ".zip")); } catch (Exception e) { PetalsServicesPlugin.log(e, IStatus.ERROR); } } } finally { monitor.done(); } } }; break; case IN_SAME_LOCATION: op = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) { monitor.beginTask("Export in progress...", IProgressMonitor.UNKNOWN); try { Collection<IProject> projects = SaExportWizard.this.page.getSaProjectsToExport(); for (IProject p : projects) { if (monitor.isCanceled()) break; monitor.subTask(p.getName()); String outputDirectoryLocation = SaExportWizard.this.page.getOutputFile() .getAbsolutePath(); IStatus s = ExportUtils.exportSaProject(outputDirectoryLocation, p, monitor); if (!s.isOK()) SaExportWizard.this.status.add(s); monitor.worked(2); try { p.refreshLocal(IResource.DEPTH_ONE, monitor); SaExportWizard.this.resourcesToSelect.add(p.getFile(p.getName() + ".zip")); } catch (Exception e) { PetalsServicesPlugin.log(e, IStatus.ERROR); } } } finally { monitor.done(); } } }; break; } return op; }
From source file:com.ebmwebsourcing.petals.services.su.export.SuBulkExportWizard.java
License:Open Source License
@Override public boolean performFinish() { // Define the wizard completion process IRunnableWithProgress op = new IRunnableWithProgress() { @Override//from w ww .j a v a 2 s .com public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { doFinish(monitor); } catch (Exception e) { throw new InvocationTargetException(e); } finally { monitor.done(); } } }; // Run the operation try { getContainer().run(true, false, op); } catch (InterruptedException e) { // nothing } catch (InvocationTargetException e) { PetalsServicesPlugin.log(e, IStatus.ERROR, "An error occurred during the bulk export."); MessageDialog.openError(getShell(), "Export Error", "An error occurred during the bulk export."); } return true; }
From source file:com.ebmwebsourcing.petals.services.su.export.SuExportWizard.java
License:Open Source License
/** * * @return//from w w w .j a va2s.c o m */ private IRunnableWithProgress getExportOperation() { IRunnableWithProgress op = null; switch (this.page.getExportMode()) { case SEPARATE_IN_PROJECT: op = new WorkspaceModifyOperation() { @Override protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { monitor.beginTask("Export in progress...", IProgressMonitor.UNKNOWN); try { Collection<IProject> projects = SuExportWizard.this.page.getSuProjectsToExport(); for (IProject p : projects) { if (monitor.isCanceled()) break; monitor.subTask(p.getName()); String saName = JbiUtils.createSaName(p.getName()); String saFilePath = p.getLocation().append(saName + ".zip").toString(); IStatus s = ExportUtils.exportSuProject(saName, saFilePath, Arrays.asList(p), monitor); if (!s.isOK()) SuExportWizard.this.status.add(s); monitor.worked(2); try { p.refreshLocal(IResource.DEPTH_ONE, monitor); SuExportWizard.this.resourcesToSelect.add(p.getFile(saName + ".zip")); } catch (Exception e) { PetalsServicesPlugin.log(e, IStatus.ERROR); } } } finally { monitor.done(); } } }; break; case SEPARATE_IN_DIRECTORY: op = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) { monitor.beginTask("Export in progress...", IProgressMonitor.UNKNOWN); try { Collection<IProject> projects = SuExportWizard.this.page.getSuProjectsToExport(); for (IProject p : projects) { if (monitor.isCanceled()) break; monitor.subTask(p.getName()); String saName = JbiUtils.createSaName(p.getName()); String saFilePath = new File(SuExportWizard.this.page.getOutputFile(), saName + ".zip") .getAbsolutePath(); IStatus s = ExportUtils.exportSuProject(saName, saFilePath, Arrays.asList(p), monitor); if (!s.isOK()) SuExportWizard.this.status.add(s); monitor.worked(2); } } finally { monitor.done(); } } }; break; case ALL_IN_ONE: op = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) { monitor.beginTask("Export in progress...", IProgressMonitor.UNKNOWN); try { Collection<IProject> projects = SuExportWizard.this.page.getSuProjectsToExport(); String saFilePath = SuExportWizard.this.page.getOutputFile().getAbsolutePath(); String saName = new Path(saFilePath).removeFileExtension().lastSegment(); IStatus s = ExportUtils.exportSuProject(saName, saFilePath, projects, monitor); if (!s.isOK()) SuExportWizard.this.status.add(s); monitor.worked(5); } finally { monitor.done(); } } }; break; } return op; }
From source file:com.ebmwebsourcing.petals.services.su.export.SuFastExportCommandHandler.java
License:Open Source License
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { // Define the objects processing final List<IStatus> errors = new ArrayList<IStatus>(); final List<IResource> resourcesToSelect = new ArrayList<IResource>(); IRunnableWithProgress op = new IRunnableWithProgress() { @Override//from w ww . jav a2s. c om public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Service Unit export in progress...", IProgressMonitor.UNKNOWN); try { for (IProject p : SuFastExportCommandHandler.this.suProjects) { monitor.subTask(p.getName()); String saName = JbiUtils.createSaName(p.getName()); String saFilePath = p.getLocation().append(saName + ".zip").toOSString(); IStatus status = ExportUtils.exportSuProject(saName, saFilePath, Arrays.asList(p), monitor); IResource res = ResourceUtils.getIFile(new File(saFilePath)); if (res != null) resourcesToSelect.add(res); monitor.worked(5); if (!status.isOK()) errors.add(status); } } finally { monitor.done(); } } }; // Start processing IWorkbench wb = PlatformUI.getWorkbench(); IProgressService ps = wb.getProgressService(); try { ps.runInUI(ps, op, null); } catch (InvocationTargetException e) { IStatus status = StatusUtils.createStatus(e, ""); errors.add(status); } catch (InterruptedException e) { // nothing } // Select the resulting files for (IResource res : resourcesToSelect) { try { res.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); } catch (CoreException e) { PetalsServicesPlugin.log(e, IStatus.ERROR); } } IResource[] resources = new IResource[resourcesToSelect.size()]; ResourceUtils.selectResourceInPetalsExplorer(true, resourcesToSelect.toArray(resources)); // Errors to display if (!errors.isEmpty()) { IStatus[] children = new IStatus[errors.size()]; MultiStatus status = new MultiStatus(PetalsServicesPlugin.PLUGIN_ID, 0, errors.toArray(children), (errors.size() > 1 ? "Errors" : "An error") + " occured during the export.", null); PetalsServicesPlugin.getDefault().getLog().log(status); ErrorDialog dlg = new ErrorDialog(new Shell(), "Export Errors", status.getMessage(), status, IStatus.ERROR); dlg.open(); } return null; }