List of usage examples for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress
IRunnableWithProgress
From source file:com.google.cloud.tools.eclipse.appengine.newproject.maven.MavenArchetypeProjectWizard.java
License:Apache License
@Override public boolean performFinish() { AnalyticsPingManager.getInstance().sendPing(AnalyticsEvents.APP_ENGINE_NEW_PROJECT_WIZARD_COMPLETE, AnalyticsEvents.APP_ENGINE_NEW_PROJECT_WIZARD_TYPE, AnalyticsEvents.APP_ENGINE_NEW_PROJECT_WIZARD_TYPE_MAVEN); if (cloudSdkLocation == null) { cloudSdkLocation = CloudSdkPrompter.getCloudSdkLocation(getShell()); if (cloudSdkLocation == null) { return false; }/* w w w. j av a2s .c om*/ } final CreateMavenBasedAppEngineStandardProject operation = new CreateMavenBasedAppEngineStandardProject(); operation.setPackageName(page.getPackageName()); operation.setGroupId(page.getGroupId()); operation.setArtifactId(page.getArtifactId()); operation.setVersion(page.getVersion()); operation.setLocation(page.getLocationPath()); operation.setArchetype(archetypePage.getArchetype()); operation.setAppEngineLibraryIds(page.getSelectedLibraries()); IRunnableWithProgress runnable = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { operation.run(monitor); } }; IStatus status = Status.OK_STATUS; try { boolean fork = true; boolean cancelable = true; getContainer().run(fork, cancelable, runnable); } catch (InterruptedException ex) { status = Status.CANCEL_STATUS; } catch (InvocationTargetException ex) { status = new Status(Status.ERROR, getClass().getName(), 0, ex.getMessage(), ex.getCause()); StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.SHOW); } return status.isOK(); }
From source file:com.google.cloud.tools.eclipse.login.ui.LoginServiceUi.java
License:Apache License
private String showProgressDialogAndWaitForCode(final String message, final LocalServerReceiver codeReceiver, final String redirectUrl) throws IOException { try {//w w w . jav a 2 s . co m final Semaphore wait = new Semaphore(0 /* initially zero permit */); final ProgressMonitorDialog dialog = new ProgressMonitorDialog(shellProvider.getShell()) { @Override protected void configureShell(Shell shell) { super.configureShell(shell); shell.setText(Messages.getString("LOGIN_PROGRESS_DIALOG_TITLE")); } @Override protected void cancelPressed() { wait.release(); // Allow termination of the attached task. stopCodeWaitingJob(redirectUrl); AnalyticsPingManager.getInstance().sendPing(AnalyticsEvents.LOGIN_CANCELED, null, null, getParentShell()); } }; final String[] codeHolder = new String[1]; final IOException[] exceptionHolder = new IOException[1]; dialog.run(true /* fork */, true /* cancelable */, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { AnalyticsPingManager.getInstance().sendPing(AnalyticsEvents.LOGIN_START, null, null, dialog.getShell()); monitor.beginTask( message != null ? message : Messages.getString("LOGIN_PROGRESS_DIALOG_MESSAGE"), IProgressMonitor.UNKNOWN); // Fork another sub-job to circumvent the limitation of LocalServerReceiver. // (See the comments of scheduleCodeWaitingJob().) scheduleCodeWaitingJob(new LocalServerReceiverWrapper(codeReceiver), wait, codeHolder, exceptionHolder); wait.acquireUninterruptibly(); // Block until signaled. } }); if (exceptionHolder[0] != null) { throw exceptionHolder[0]; } return codeHolder[0]; } catch (InvocationTargetException | InterruptedException ex) { // Never thrown from the attached task. return null; } }
From source file:com.google.dart.eclipse.wizards.DartProjectWizard.java
License:Open Source License
private IProject createNewProject() { if (newProject != null) { return newProject; }/*from www . jav a2s . c o m*/ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); final IProjectDescription description = new ProjectDescription(); description.setName(page.getProjectName()); String location = page.getProjectLocation(); if (location != null) { description.setLocation(new Path(location)); } addProjectDescription(description); String name = description.getName(); final IProject project = root.getProject(name); // create the new project operation IRunnableWithProgress op = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException { CreateProjectOperation op = new CreateProjectOperation(description, ResourceMessages.NewProject_windowTitle); try { op.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(getShell())); } catch (ExecutionException e) { throw new InvocationTargetException(e); } } }; // run the new project creation operation try { getContainer().run(true, true, op); } catch (InterruptedException e) { return null; } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); if (t instanceof ExecutionException && t.getCause() instanceof CoreException) { CoreException cause = (CoreException) t.getCause(); StatusAdapter status; if (cause.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) { status = new StatusAdapter(StatusUtil.newStatus(IStatus.WARNING, NLS.bind(ResourceMessages.NewProject_caseVariantExistsError, project.getName()), cause)); } else { status = new StatusAdapter(StatusUtil.newStatus(cause.getStatus().getSeverity(), ResourceMessages.NewProject_errorMessage, cause)); } status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY, ResourceMessages.NewProject_errorMessage); StatusManager.getManager().handle(status, StatusManager.BLOCK); } else { StatusAdapter status = new StatusAdapter( new Status(IStatus.WARNING, IDEWorkbenchPlugin.IDE_WORKBENCH, 0, NLS.bind(ResourceMessages.NewProject_internalError, t.getMessage()), t)); status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY, ResourceMessages.NewProject_errorMessage); StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.BLOCK); } return null; } try { IProjectUtilities.configurePackagesFilter(project); AbstractSample sampleContent = page.getSampleContent(); if (sampleContent != null) { createdSampleFile = sampleContent.generateInto(project, DartIdentifierUtil.createValidIdentifier(name)); } } catch (CoreException e) { DartEclipseUI.logError(e); } newProject = project; return newProject; }
From source file:com.google.dart.eclipse.wizards.ProjectUtils.java
License:Open Source License
public static IProject createNewProject(String projectName, String projectLocation, boolean isImport, final IRunnableContext runnableContext, final Shell shell) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); final IProjectDescription description = IProjectUtilities.newDartProjectDescription(root, projectName, projectLocation != null ? new Path(projectLocation) : null, isImport); final IProject project = root.getProject(description.getName()); // create the new project operation IRunnableWithProgress op = new IRunnableWithProgress() { @Override/* w w w . ja v a 2 s . c o m*/ public void run(IProgressMonitor monitor) throws InvocationTargetException { CreateProjectOperation op = new CreateProjectOperation(description, "Creating project"); try { op.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(shell)); project.setDefaultCharset("UTF-8", null); } catch (ExecutionException e) { throw new InvocationTargetException(e); } catch (CoreException e) { throw new InvocationTargetException(e); } } }; // run the new project creation operation try { runnableContext.run(true, true, op); } catch (InterruptedException e) { return null; } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); if (t instanceof ExecutionException && t.getCause() instanceof CoreException) { CoreException cause = (CoreException) t.getCause(); StatusAdapter status; if (cause.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) { status = new StatusAdapter(StatusUtil.newStatus(IStatus.WARNING, NLS.bind(ResourceMessages.NewProject_caseVariantExistsError, project.getName()), cause)); } else { status = new StatusAdapter(StatusUtil.newStatus(cause.getStatus().getSeverity(), ResourceMessages.NewProject_errorMessage, cause)); } status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY, ResourceMessages.NewProject_errorMessage); StatusManager.getManager().handle(status, StatusManager.BLOCK); } else { StatusAdapter status = new StatusAdapter( new Status(IStatus.WARNING, IDEWorkbenchPlugin.IDE_WORKBENCH, 0, NLS.bind(ResourceMessages.NewProject_internalError, t.getMessage()), t)); status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY, ResourceMessages.NewProject_errorMessage); StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.BLOCK); } return null; } try { IProjectUtilities.configurePackagesFilter(project); } catch (CoreException e) { DartEclipseUI.logError(e); } return project; }
From source file:com.google.dart.eclipse.wizards.SamplesComposite.java
License:Open Source License
private void populateSamplesList() { try {//w ww . ja va2 s .co m page.getWizard().getContainer().run(true, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("", IProgressMonitor.UNKNOWN); final List<AbstractSample> samples = AbstractSample.getAllSamples(); Display.getDefault().asyncExec(new Runnable() { @Override public void run() { samplesViewer.setInput(samples); samplesViewer.setSelection(new StructuredSelection(getDefaultSample(samples))); } }); monitor.done(); } }); } catch (InvocationTargetException e) { DartToolsPlugin.log(e); } catch (InterruptedException e) { DartToolsPlugin.log(e); } }
From source file:com.google.dart.tools.designer.editor.XmlDesignPage.java
License:Open Source License
private void internal_refreshGEF_withProgress() throws Exception { final Display display = Display.getCurrent(); IRunnableWithProgress runnable = new IRunnableWithProgress() { @Override// w w w . j a v a2s . c om public void run(final IProgressMonitor monitor) { monitor.beginTask("Opening Design page.", 6); // try { DesignPageSite.setProgressMonitor(monitor); display.syncExec(new Runnable() { @Override public void run() { try { internal_refreshGEF(monitor); } catch (Throwable e) { ReflectionUtils.propagate(e); } } }); } catch (Throwable e) { ReflectionUtils.propagate(e); } finally { DesignPageSite.setProgressMonitor(null); } // done progress monitor monitor.subTask(null); ExecutionUtils.waitEventLoop(100); monitor.done(); } }; try { new ProgressMonitorDialog(DesignerPlugin.getShell()).run(false, false, runnable); } catch (InvocationTargetException e) { ReflectionUtils.propagate(e.getCause()); } catch (Throwable e) { ReflectionUtils.propagate(e); } }
From source file:com.google.dart.tools.search2.internal.ui.InternalSearchUI.java
License:Open Source License
private IStatus doRunSearchInForeground(final SearchJobRecord rec, IRunnableContext context) { try {/*from w w w . j av a 2 s .c om*/ context.run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { searchJobStarted(rec); try { IStatus status = rec.query.run(monitor); if (status.matches(IStatus.CANCEL)) { throw new InterruptedException(); } if (!status.isOK()) { throw new InvocationTargetException(new CoreException(status)); } } catch (OperationCanceledException e) { throw new InterruptedException(); } finally { searchJobFinished(rec); } } }); } catch (InvocationTargetException e) { Throwable innerException = e.getTargetException(); if (innerException instanceof CoreException) { return ((CoreException) innerException).getStatus(); } return new Status(IStatus.ERROR, SearchPlugin.getID(), 0, SearchMessages.InternalSearchUI_error_unexpected, innerException); } catch (InterruptedException e) { return Status.CANCEL_STATUS; } return Status.OK_STATUS; }
From source file:com.google.dart.tools.ui.actions.AbstractRefactoringAction_NEW.java
License:Open Source License
/** * Waits until the server finishes analysis. * // w w w .ja va 2s. co m * @return {@code true} if waiting was successful, {@code false} if cancelled. */ public static boolean waitReadyForRefactoring() { Control focusControl = Display.getCurrent().getFocusControl(); try { IProgressService progressService = PlatformUI.getWorkbench().getProgressService(); progressService.busyCursorWhile(new IRunnableWithProgress() { @Override public void run(IProgressMonitor pm) throws InterruptedException { pm.beginTask("Waiting for analysis...", IProgressMonitor.UNKNOWN); while (true) { if (pm.isCanceled()) { throw new OperationCanceledException(); } if (!DartCore.getAnalysisServerData().isAnalyzing()) { break; } } } }); return true; } catch (Throwable ie) { return false; } finally { if (focusControl != null) { focusControl.setFocus(); } } }
From source file:com.google.dart.tools.ui.actions.NewAppFromPackageAction.java
License:Open Source License
public void openPackage(final IFileStore packageDir) { try {//from w w w.j a v a2 s. co m window.run(true, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { copyPackage(packageDir, monitor, window); } }); } catch (InvocationTargetException e) { DartToolsPlugin.log(e); } catch (InterruptedException e) { DartToolsPlugin.log(e); } }
From source file:com.google.dart.tools.ui.feedback.FeedbackDialog.java
License:Open Source License
private IStatus submitFeedback() { final IStatus[] status = new IStatus[1]; try {/*from w ww .j a v a2 s. co m*/ run(false, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { status[0] = new FeedbackSubmissionJob(new FeedbackWriter(feedbackReport, sendAdditionData())) .run(monitor); } }); } catch (InvocationTargetException e) { status[0] = DartToolsPlugin.createErrorStatus(e.getMessage()); } catch (InterruptedException e) { status[0] = DartToolsPlugin.createErrorStatus(e.getMessage()); } return status[0]; }