List of usage examples for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress
IRunnableWithProgress
From source file:com.google.dart.tools.ui.feedback.FeedbackDialog2.java
License:Open Source License
@Override protected void okPressed() { // Create feedback final FeedbackSubmissionJob2 job = newFeedbackJob(); // Save settings getDialogSettings().put(INCLUDE_DATA_KEY, includeDataCheckbox.getSelection()); getDialogSettings().put(USER_EMAIL_KEY, emailText.getText().trim()); getDialogSettings().put(PUBLIC_KEY, dartbugCheckbox.getSelection()); // Send feedback okButton.setEnabled(false);/* ww w .j a v a2s .c o m*/ cancelButton.setEnabled(false); final IStatus[] result = new IStatus[1]; try { ModalContext.run(new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { result[0] = job.run(monitor); } }, true, progressBar, getShell().getDisplay()); } catch (Throwable e) { DartCore.logError("Failed to send feedback", e); result[0] = new Status(IStatus.ERROR, DartCore.PLUGIN_ID, e.toString(), e); } // Report result to the user if (result[0].isOK()) { super.okPressed(); MessageDialog.openInformation(getParentShell(), FeedbackMessages.FeedbackDialog_feedback_sent_label, FeedbackMessages.FeedbackDialog_feedback_sent_details); } else { setReturnCode(CANCEL); MessageDialog.openError(getParentShell(), FeedbackMessages.FeedbackDialog_error_submitting_label, FeedbackMessages.FeedbackDialog_error_submitting_detail); okButton.setEnabled(true); cancelButton.setEnabled(true); } }
From source file:com.google.dart.tools.ui.internal.intro.IntroEditor.java
License:Open Source License
protected void openSample(final SampleDescription description) { try {/*w w w .j av a 2 s .c o m*/ getSite().getWorkbenchWindow().run(true, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { openSample(new File(description.directory, description.file), monitor); } }); } catch (InvocationTargetException e) { DartToolsPlugin.log(e); } catch (InterruptedException e) { DartToolsPlugin.log(e); } }
From source file:com.google.dart.tools.ui.internal.intro.SampleHelper.java
License:Open Source License
/** * Open the given sample./*from w w w.j ava2 s . com*/ * * @param description the sample description * @param window the current active workbench window */ public static void openSample(final SampleDescription description, final IWorkbenchWindow window) { try { window.run(true, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { openSample(new File(description.directory, description.file), monitor, window); } }); } catch (InvocationTargetException e) { DartToolsPlugin.log(e); } catch (InterruptedException e) { DartToolsPlugin.log(e); } }
From source file:com.google.dart.tools.ui.internal.projects.CreateApplicationWizard.java
License:Open Source License
private void createFolder(IPath path) { final ProjectType projectType = page.getProjectType(); final boolean hasPubSupport = page.hasPubSupport(); IPath containerPath = path.removeLastSegments(1); IResource container = ResourceUtil.getResource(containerPath.toFile()); IPath newFolderPath = container.getFullPath().append(path.lastSegment()); final IFolder newFolderHandle = IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getFolder(newFolderPath); IRunnableWithProgress op = new IRunnableWithProgress() { @Override/*from w ww.jav a2s . c om*/ public void run(IProgressMonitor monitor) throws InvocationTargetException { AbstractOperation op; op = new CreateFolderOperation(newFolderHandle, null, IDEWorkbenchMessages.WizardNewFolderCreationPage_title); try { IStatus status = op.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(getShell())); if (status.isOK() && projectType != ProjectType.NONE) { createdFile = createProjectContent(newProject, newFolderHandle.getLocation().toOSString(), newFolderHandle.getName(), projectType, hasPubSupport); } } catch (ExecutionException e) { throw new InvocationTargetException(e); } catch (CoreException e) { throw new InvocationTargetException(e); } } }; try { getContainer().run(true, true, op); } catch (InterruptedException e) { } catch (InvocationTargetException e) { // ExecutionExceptions are handled above, but unexpected runtime // exceptions and errors may still occur. IDEWorkbenchPlugin.log(getClass(), "createNewFolder()", e.getTargetException()); //$NON-NLS-1$ MessageDialog.open(MessageDialog.ERROR, getContainer().getShell(), IDEWorkbenchMessages.WizardNewFolderCreationPage_internalErrorTitle, NLS.bind(IDEWorkbenchMessages.WizardNewFolder_internalError, e.getTargetException().getMessage()), SWT.SHEET); } newProject = newFolderHandle.getProject(); }
From source file:com.google.dart.tools.ui.internal.projects.CreateApplicationWizard.java
License:Open Source License
/** * Creates a new project resource with the selected name. * <p>/*from ww w . jav a 2s . c o m*/ * In normal usage, this method is invoked after the user has pressed Finish on the wizard; the * enablement of the Finish button implies that all controls on the pages currently contain valid * values. * </p> * <p> * Note that this wizard caches the new project once it has been successfully created; subsequent * invocations of this method will answer the same project resource without attempting to create * it again. * </p> * * @return the created project resource, or <code>null</code> if the project was not created */ private IProject createNewProject() { if (newProject != null) { return newProject; } // get a project handle final IProject newProjectHandle = page.getProjectHandle(); final ProjectType projectType = page.getProjectType(); final boolean hasPubSupport = page.hasPubSupport(); // get a project descriptor URI location = page.getLocationURI(); final IProjectDescription description = createProjectDescription(newProjectHandle, location); // 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 { IStatus status = op.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(getShell())); if (status.isOK() && projectType != ProjectType.NONE) { createdFile = createProjectContent(newProjectHandle, newProjectHandle.getLocation().toOSString(), newProjectHandle.getName(), projectType, hasPubSupport); } } catch (ExecutionException e) { throw new InvocationTargetException(e); } catch (CoreException e) { throw new InvocationTargetException(e); } } }; 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, newProjectHandle.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; } newProject = newProjectHandle; return newProject; }
From source file:com.google.dart.tools.ui.internal.projects.ProjectUtils.java
License:Open Source License
/** * Creates a new project resource./* ww w . j a va2 s .c o m*/ * * @param name the project name * @param newProjectHandle the project handle * @param projectType the type of project * @param location the location * @param runnableContext a context for executing the creation operation * @param shell the shell (for UI context) * @return the created project resource, or <code>null</code> if the project was not created */ public static IProject createNewProject(String name, final IProject newProjectHandle, final ProjectType projectType, URI location, final IRunnableContext runnableContext, final Shell shell) { final IProjectDescription description = createProjectDescription(newProjectHandle, location); // 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 { IStatus status = op.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(shell)); if (status.isOK() && projectType != ProjectType.NONE) { createProjectContent(newProjectHandle, projectType); } } catch (ExecutionException e) { throw new InvocationTargetException(e); } catch (CoreException e) { throw new InvocationTargetException(e); } } }; 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, newProjectHandle.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; } return newProjectHandle; }
From source file:com.google.dart.tools.ui.internal.pub.AddPackageAction.java
License:Open Source License
@Override protected void doRun(Event event, UIInstrumentationBuilder instrumentation) { // create project String dirName = packageName + "-" + version; File potentialDir = new File(DartCore.getUserDefaultDartFolder(), dirName); final File newProjectDir = ProjectUtils.generateUniqueSampleDirFrom(dirName + "_copy", potentialDir); Control focusControl = Display.getCurrent().getFocusControl(); try {/*from w ww. j av a2 s. co m*/ IProgressService progressService = PlatformUI.getWorkbench().getProgressService(); progressService.busyCursorWhile(new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { installAndCopyPackage(newProjectDir, monitor); } }); } catch (Throwable ie) { } finally { if (focusControl != null) { focusControl.setFocus(); } } }
From source file:com.google.dart.tools.ui.internal.refactoring.RefactoringUtils.java
License:Open Source License
/** * Waits until all background tasks affecting refactoring are finished. * //from w ww .j a v a 2 s . c om * @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 InvocationTargetException, InterruptedException { waitReadyForRefactoring(pm); } }); return true; } catch (Throwable ie) { return false; } finally { if (focusControl != null) { focusControl.setFocus(); } } }
From source file:com.google.dart.tools.ui.internal.refactoring.reorg.RenameLinkedMode.java
License:Open Source License
private RenameSupport undoAndCreateRenameSupport(String newName) throws CoreException { // Assumption: the linked mode model should be shut down by now. final ISourceViewer viewer = fEditor.getViewer(); try {//from w w w . java 2s .c om if (!fOriginalName.equals(newName)) { fEditor.getSite().getWorkbenchWindow().run(false, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { if (viewer instanceof ITextViewerExtension6) { IUndoManager undoManager = ((ITextViewerExtension6) viewer).getUndoManager(); if (undoManager instanceof IUndoManagerExtension) { IUndoManagerExtension undoManagerExtension = (IUndoManagerExtension) undoManager; IUndoContext undoContext = undoManagerExtension.getUndoContext(); IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory(); while (undoManager.undoable()) { if (fStartingUndoOperation != null && fStartingUndoOperation .equals(operationHistory.getUndoOperation(undoContext))) { return; } undoManager.undo(); } } } } }); } } catch (InvocationTargetException e) { throw new CoreException(new Status(IStatus.ERROR, DartToolsPlugin.getPluginId(), ReorgMessages.RenameLinkedMode_error_saving_editor, e)); } catch (InterruptedException e) { // canceling is OK return null; } finally { DartModelUtil.reconcile(getCompilationUnit()); } viewer.setSelectedRange(fOriginalSelection.x, fOriginalSelection.y); if (newName.length() == 0) { return null; } return RefactoringExecutionStarter.createRenameSupport(fDartElement, newName, 0); }
From source file:com.google.dart.tools.ui.internal.refactoring.reorg.RenameLinkedMode_OLD.java
License:Open Source License
private RenameSupport_OLD undoAndCreateRenameSupport(String newName) throws CoreException { // Assumption: the linked mode model should be shut down by now. final ISourceViewer viewer = fEditor.getViewer(); try {/*from ww w . j av a2 s .co m*/ if (!fOriginalName.equals(newName)) { fEditor.getSite().getWorkbenchWindow().run(false, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { if (viewer instanceof ITextViewerExtension6) { IUndoManager undoManager = ((ITextViewerExtension6) viewer).getUndoManager(); if (undoManager instanceof IUndoManagerExtension) { IUndoManagerExtension undoManagerExtension = (IUndoManagerExtension) undoManager; IUndoContext undoContext = undoManagerExtension.getUndoContext(); IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory(); while (undoManager.undoable()) { if (fStartingUndoOperation != null && fStartingUndoOperation .equals(operationHistory.getUndoOperation(undoContext))) { return; } undoManager.undo(); } } } } }); } } catch (InvocationTargetException e) { throw new CoreException(new Status(IStatus.ERROR, DartToolsPlugin.getPluginId(), ReorgMessages.RenameLinkedMode_error_saving_editor, e)); } catch (InterruptedException e) { // canceling is OK return null; } finally { DartModelUtil.reconcile(getCompilationUnit()); } viewer.setSelectedRange(fOriginalSelection.x, fOriginalSelection.y); if (newName.length() == 0) { return null; } return RefactoringExecutionStarter_OLD.createRenameSupport(fDartElement, newName, 0); }