List of usage examples for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress
IRunnableWithProgress
From source file:com.aliyun.odps.eclipse.launch.configuration.udf.UDFSearchEngine.java
License:Apache License
/** * Searches for all main methods in the given scope. Valid styles are * IJavaElementSearchConstants.CONSIDER_BINARIES and * IJavaElementSearchConstants.CONSIDER_EXTERNAL_JARS * // w w w .j a v a2 s . c o m * @param includeSubtypes whether to consider types that inherit a main method */ public IType[] searchUDFClass(IRunnableContext context, final IJavaSearchScope scope, final boolean includeSubtypes) throws InvocationTargetException, InterruptedException { final IType[][] res = new IType[1][]; IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor pm) throws InvocationTargetException { res[0] = searchUDFClass(pm, scope, includeSubtypes); } }; context.run(true, true, runnable); return res[0]; }
From source file:com.aljoschability.defectr.ui.handlers.SaveHandler.java
License:Open Source License
@Execute public void execute(IEclipseContext context, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell, @Named(IServiceConstants.ACTIVE_PART) final MContribution contribution) throws InvocationTargetException, InterruptedException { final IEclipseContext pmContext = context.createChild(); ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell); dialog.open();//from w ww . j a v a 2s .com dialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { pmContext.set(IProgressMonitor.class.getName(), monitor); if (contribution != null) { Object clientObject = contribution.getObject(); System.out.println(clientObject); // ContextInjectionFactory.invoke(clientObject, Persist.class, //$NON-NLS-1$ // pmContext, null); } } }); pmContext.dispose(); }
From source file:com.amalto.workbench.editors.TransformerMainPage.java
License:Open Source License
public void execute() { try {/* w w w .j a v a 2 s . co m*/ service = getService(); if (service == null) { return; } java.util.List<WSTransformerContextPipelinePipelineItem> items = new ArrayList<WSTransformerContextPipelinePipelineItem>(); for (Line line : cacheList) { String variableName = line.keyValues.get(0).value; String contentType = line.keyValues.get(1).value; String value = line.keyValues.get(2).value; items.add(new WSTransformerContextPipelinePipelineItem(variableName, new WSTypedContent(contentType, null, new WSByteArray(value.getBytes("utf-8"))))); //$NON-NLS-1$ } final WSBackgroundJobPK jobPK = service.executeTransformerV2AsJob(new WSExecuteTransformerV2AsJob( new WSTransformerContext(new WSTransformerContextPipeline(items), null, new WSTransformerV2PK(transformer.getName())))); IRunnableWithProgress progress = new IRunnableWithProgress() { WSBackgroundJob job = null; public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { /****************************************** * Watch the Background Job ******************************************/ try { boolean firstTime = true; do { if (firstTime) { Thread.sleep(1500L); firstTime = false; } else { Thread.sleep(5000L); } if (monitor.isCanceled()) { throw new InterruptedException(Messages.TransformerMainPage_UserCancel); } job = service.getBackgroundJob(new WSGetBackgroundJob(jobPK.getPk())); monitor.subTask(job.getMessage()); } while (job.getStatus().equals(BackgroundJobStatusType.RUNNING) || job.getStatus().equals(BackgroundJobStatusType.SCHEDULED)); if (job.getStatus().equals(BackgroundJobStatusType.STOPPED)) { getSite().getShell().getDisplay().syncExec(new Runnable() { public void run() { MessageDialog.openError( TransformerMainPage.this.getEditor().getSite().getShell(), Messages.bind(Messages.TransformerMainPage_ErrorMsg, transformer.getName()), job.getMessage()); } }); throw new XtentisException( Messages.bind(Messages.TransformerMainPage_JobWasStoped, job.getMessage())); } monitor.worked(1); monitor.done(); /****************************************** * Build the result console ******************************************/ // Auto sorts the entries final TreeMap pipeline = new TreeMap<String, WSExtractedContent>(); WSPipeline wsPipeline = job.getPipeline(); java.util.List<WSPipelineTypedContentEntry> entries = wsPipeline.getTypedContentEntry(); for (WSPipelineTypedContentEntry entry : entries) { pipeline.put(entry.getOutput(), entry.getWsExtractedContent()); } getSite().getShell().getDisplay().asyncExec(new Runnable() { public void run() { try { /* * ProcessResultsPage page = new ProcessResultsPage(editor,pipeline); * parent.editor.addPage(page); parent.editor.setActivePage(page.getId()); * * parent.editor.getEditorSite().getShell() */ // Shell shell = new Shell(SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN); ProcessResultsDialog dialog = new ProcessResultsDialog(getSite().getShell(), Messages.bind(Messages.TransformerMainPage_DailogTitle, sdf.format(new Date(System.currentTimeMillis()))), pipeline); dialog.setBlockOnOpen(false); dialog.open(); } catch (Exception e) { log.error(e.getMessage(), e); throw new RuntimeException(e); } } }); } catch (Exception e1) { log.error(e1.getMessage(), e1); } } }; new ProgressMonitorDialog(TransformerMainPage.this.getSite().getWorkbenchWindow().getShell()).run(true, // fork true, progress); } catch (Exception e1) { log.error(e1.getMessage(), e1); } }
From source file:com.amalto.workbench.export.ImportItemsWizard.java
License:Open Source License
@Override public boolean performFinish() { closeOpenEditors();/*from www .j a v a2 s . co m*/ final String zipFilePath = getZipFilePath(); final boolean selectZip = zipBtn.getSelection(); if (selectZip) { try { ZipToFile.unZipFile(zipFilePath, importFolder); } catch (Exception e) { log.error(e.getMessage(), e); } } if (folderBtn.getSelection()) { importFolder = folder.getText().getText(); } final Object[] objs = getCheckedObjects(); IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { doImport(objs, monitor); // run initMDM to call backend migration task if (service != null) { service.initMDM(null); } } catch (Exception e) { log.error(e.getMessage(), e); } finally { refreshViewJob(); // modified by honghb ,fix bug 21552 if (selectZip && zipFilePath != null && new File(importFolder).exists()) { ZipToFile.deleteDirectory(new File(importFolder)); } } } }; try { new ProgressMonitorDialog(getShell()).run(true, true, iRunnableWithProgress); } catch (Exception e) { log.error(e.getMessage(), e); } return true; }
From source file:com.amazonaws.eclipse.codedeploy.deploy.wizard.DeployProjectToCodeDeployWizard.java
License:Open Source License
@Override public boolean performFinish() { // Pull the template parameter values from the wizard page dataModel.setTemplateParameterValues(appspecTemplateSelectionPage.getParamValuesForSelectedTemplate()); try {/*from ww w . ja v a2 s . c o m*/ getContainer().run(true, false, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask( "Deploying web project [" + dataModel.getProject().getName() + "] to CodeDeploy", 100); // Initiate deployment (80/100 units) final String deploymentId = DeployUtils.createDeployment(dataModel, monitor); if (CodeDeployContentProvider.getInstance() != null) { CodeDeployContentProvider.getInstance().refresh(); } // Open deployment progress tracker (10/100) monitor.subTask("Open deployment progress tracker..."); Display.getDefault().asyncExec(new Runnable() { public void run() { DeploymentProgressTrackerDialog dialog = new DeploymentProgressTrackerDialog( Display.getDefault().getActiveShell(), deploymentId, dataModel.getDeploymentGroupName(), dataModel.getApplicationName(), dataModel.getRegion()); dialog.open(); } }); monitor.worked(10); monitor.done(); } }); } catch (InvocationTargetException e) { CodeDeployPlugin.getDefault().reportException("Unexpected error during deployment", e.getCause()); } catch (InterruptedException e) { CodeDeployPlugin.getDefault().reportException("Unexpected InterruptedException during deployment", e.getCause()); } return true; }
From source file:com.amazonaws.eclipse.elasticbeanstalk.server.ui.ImportEnvironmentsWizard.java
License:Apache License
@Override public boolean performFinish() { try {//from ww w . j a va2 s .c o m getContainer().run(true, false, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Importing servers", toImport.length * 3); try { for (Object elasticBeanstalkEnv : toImport) { try { ElasticBeanstalkPlugin .importEnvironment((EnvironmentDescription) elasticBeanstalkEnv, monitor); } catch (CoreException e) { throw new RuntimeException(e); } } } finally { monitor.done(); } } }); } catch (Exception e) { throw new RuntimeException(e); } return true; }
From source file:com.amazonaws.eclipse.opsworks.deploy.wizard.DeployProjectToOpsworksWizard.java
License:Open Source License
@Override public boolean performFinish() { try {//from w w w . j a v a 2 s .c om getContainer().run(true, false, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask( "Deploying local project [" + dataModel.getProject().getName() + "] to OpsWorks", 110); final String deploymentId = DeployUtils.runDeployment(dataModel, monitor); // Open deployment progress tracker (10/110) monitor.subTask("Waiting for the deployment to finish..."); Job trackProgressJob = new Job("Waiting for the deployment to finish") { @Override protected IStatus run(IProgressMonitor monitor) { monitor.beginTask(String.format("Waiting deployment [%s] to finish...", deploymentId), IProgressMonitor.UNKNOWN); String endpoint = dataModel.getRegion().getServiceEndpoints() .get(ServiceAbbreviations.OPSWORKS); AWSOpsWorks client = AwsToolkitCore.getClientFactory() .getOpsWorksClientByEndpoint(endpoint); try { final Deployment deployment = waitTillDeploymentFinishes(client, deploymentId, monitor); if ("successful".equalsIgnoreCase(deployment.getStatus())) { final App appDetail = client .describeApps( new DescribeAppsRequest().withAppIds(deployment.getAppId())) .getApps().get(0); Display.getDefault().syncExec(new Runnable() { public void run() { MessageDialog.openInformation(Display.getDefault().getActiveShell(), "Deployment success", String.format("Deployment [%s] succeeded (Instance count: %d). " + "The application will be available at %s://{instance-public-endpoint}/%s/", deployment.getDeploymentId(), deployment.getInstanceIds().size(), appDetail.isEnableSsl() ? "https" : "http", appDetail.getShortname())); } }); return ValidationStatus.ok(); } else { Display.getDefault().syncExec(new Runnable() { public void run() { MessageDialog.openError(Display.getDefault().getActiveShell(), "Deployment failed", ""); } }); return ValidationStatus.error("The deployment failed."); } } catch (Exception e) { return ValidationStatus.error("Unable to query the progress of the deployment", e); } } private Deployment waitTillDeploymentFinishes(AWSOpsWorks client, String deploymentId, IProgressMonitor monitor) throws InterruptedException { while (true) { Deployment deployment = client .describeDeployments( new DescribeDeploymentsRequest().withDeploymentIds(deploymentId)) .getDeployments().get(0); monitor.subTask(String.format("Instance count: %d, Last status: %s", deployment.getInstanceIds().size(), deployment.getStatus())); if ("successful".equalsIgnoreCase(deployment.getStatus()) || "failed".equalsIgnoreCase(deployment.getStatus())) { return deployment; } Thread.sleep(5 * 1000); } } }; trackProgressJob.setUser(true); trackProgressJob.schedule(); monitor.worked(10); monitor.done(); } }); } catch (InvocationTargetException e) { OpsWorksPlugin.getDefault().reportException("Unexpected error during deployment", e.getCause()); } catch (InterruptedException e) { OpsWorksPlugin.getDefault().reportException("Unexpected InterruptedException during deployment", e.getCause()); } return true; }
From source file:com.android.ddmuilib.screenrecord.ScreenRecorderAction.java
License:Apache License
public void performAction() { ScreenRecorderOptionsDialog optionsDialog = new ScreenRecorderOptionsDialog(mParentShell); if (optionsDialog.open() == Window.CANCEL) { return;//from w ww . j av a2 s . c o m } final ScreenRecorderOptions options = new ScreenRecorderOptions.Builder() .setBitRate(optionsDialog.getBitRate()).setSize(optionsDialog.getWidth(), optionsDialog.getHeight()) .build(); final CountDownLatch latch = new CountDownLatch(1); final CollectingOutputReceiver receiver = new CollectingOutputReceiver(latch); new Thread(new Runnable() { @Override public void run() { try { mDevice.startScreenRecorder(REMOTE_PATH, options, receiver); } catch (Exception e) { showError("Unexpected error while launching screenrecorder", e); latch.countDown(); } } }, "Screen Recorder").start(); try { new ProgressMonitorDialog(mParentShell).run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { int timeInSecond = 0; monitor.beginTask("Recording...", IProgressMonitor.UNKNOWN); while (true) { // Wait for a second to see if the command has completed if (latch.await(1, TimeUnit.SECONDS)) { break; } // update recording time in second monitor.subTask(String.format("Recording...%d seconds elapsed", timeInSecond++)); // If not, check if user has cancelled if (monitor.isCanceled()) { receiver.cancel(); monitor.subTask("Stopping..."); // wait for an additional second to make sure that the command // completed and screenrecorder finishes writing the output latch.await(1, TimeUnit.SECONDS); break; } } } }); } catch (InvocationTargetException e) { showError("Unexpected error while recording: ", e.getTargetException()); return; } catch (InterruptedException ignored) { } try { mDevice.pullFile(REMOTE_PATH, optionsDialog.getDestination().getAbsolutePath()); } catch (Exception e) { showError("Unexpected error while copying video recording from device", e); } MessageDialog.openInformation(mParentShell, TITLE, "Screen recording saved at " + optionsDialog.getDestination().getAbsolutePath()); }
From source file:com.android.ddmuilib.SyncProgressHelper.java
License:Apache License
/** * Runs a {@link SyncRunnable} in a {@link ProgressMonitorDialog}. * @param runnable The {@link SyncRunnable} to run. * @param progressMessage the message to display in the progress dialog * @param parentShell the parent shell for the progress dialog. * * @throws InvocationTargetException//from www.j a v a 2 s . co m * @throws InterruptedException * @throws SyncException if an error happens during the push of the package on the device. * @throws IOException * @throws TimeoutException */ public static void run(final SyncRunnable runnable, final String progressMessage, final Shell parentShell) throws InvocationTargetException, InterruptedException, SyncException, IOException, TimeoutException { final Exception[] result = new Exception[1]; new ProgressMonitorDialog(parentShell).run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) { try { runnable.run(new SyncProgressMonitor(monitor, progressMessage)); } catch (Exception e) { result[0] = e; } finally { runnable.close(); } } }); if (result[0] instanceof SyncException) { SyncException se = (SyncException) result[0]; if (se.wasCanceled()) { // no need to throw this return; } throw se; } // just do some casting so that the method declaration matches what's thrown. if (result[0] instanceof TimeoutException) { throw (TimeoutException) result[0]; } if (result[0] instanceof IOException) { throw (IOException) result[0]; } if (result[0] instanceof RuntimeException) { throw (RuntimeException) result[0]; } }
From source file:com.android.ide.eclipse.adt.cdt.internal.wizards.AddNativeWizard.java
License:Open Source License
@Override public boolean performFinish() { // Switch to C/C++ Perspective try {//from w ww . ja va 2s . c om window.getWorkbench().showPerspective(CUIPlugin.ID_CPERSPECTIVE, window); } catch (WorkbenchException e1) { Activator.log(e1); } addNativeWizardPage.updateArgs(templateArgs); IRunnableWithProgress op = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { IWorkspaceRunnable op = new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { // Convert to CDT project CCorePlugin.getDefault().convertProjectToCC(project, monitor, MakeCorePlugin.MAKE_PROJECT_ID); // Set up build information new NDKWizardHandler().convertProject(project, monitor); // Run the template NDKManager.addNativeSupport(project, templateArgs, monitor); } }; // TODO run from a job IWorkspace workspace = ResourcesPlugin.getWorkspace(); try { workspace.run(op, workspace.getRoot(), 0, new NullProgressMonitor()); } catch (CoreException e) { throw new InvocationTargetException(e); } } }; try { getContainer().run(false, true, op); return true; } catch (InterruptedException e) { Activator.log(e); return false; } catch (InvocationTargetException e) { Activator.log(e); return false; } }