@Override public void run( final boolean fork, final boolean cancelable, final IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException { final IRunnableContext runnableContext = (IProgressService) RDataTableComposite.this .callbacks .getServiceLocator() .getService(IProgressService.class); runnableContext.run( fork, cancelable, new IRunnableWithProgress() { @Override public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { RDataTableComposite.this.dataProvider.beginOperation(this); try { runnable.run(monitor); } finally { RDataTableComposite.this.dataProvider.endOperation(this); } } }); }
/** * Runs task in Eclipse progress dialog. NOTE: this call can't be canceled if it will block in IO */ public static void runInProgressDialog(final DBRRunnableWithProgress runnable) throws InvocationTargetException { try { IRunnableContext runnableContext; IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); if (workbenchWindow != null) { runnableContext = new ProgressMonitorDialog(workbench.getActiveWorkbenchWindow().getShell()); } else { runnableContext = workbench.getProgressService(); } runnableContext.run( true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { runnable.run(RuntimeUtils.makeMonitor(monitor)); } }); } catch (InterruptedException e) { // do nothing } }
private void ensureConsistency() throws InvocationTargetException, InterruptedException { // we only have to ensure history consistency here since the search engine // takes care of working copies. class ConsistencyRunnable implements IRunnableWithProgress { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { if (fgFirstTime) { // Join the initialize after load job. IJobManager manager = Job.getJobManager(); manager.join(JavaScriptUI.ID_PLUGIN, monitor); } OpenTypeHistory history = OpenTypeHistory.getInstance(); if (fgFirstTime || history.isEmpty()) { monitor.beginTask(JavaUIMessages.TypeSelectionDialog_progress_consistency, 100); if (history.needConsistencyCheck()) { refreshSearchIndices(new SubProgressMonitor(monitor, 90)); history.checkConsistency(new SubProgressMonitor(monitor, 10)); } else { refreshSearchIndices(monitor); } monitor.done(); fgFirstTime = false; } else { history.checkConsistency(monitor); } } public boolean needsExecution() { OpenTypeHistory history = OpenTypeHistory.getInstance(); return fgFirstTime || history.isEmpty() || history.needConsistencyCheck(); } private void refreshSearchIndices(IProgressMonitor monitor) throws InvocationTargetException { try { new SearchEngine() .searchAllTypeNames( null, 0, // make sure we search a concrete name. This is faster according to Kent "_______________".toCharArray(), // $NON-NLS-1$ SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE, IJavaScriptSearchConstants.ENUM, SearchEngine.createWorkspaceScope(), new TypeNameRequestor() {}, IJavaScriptSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor); } catch (JavaScriptModelException e) { throw new InvocationTargetException(e); } } } ConsistencyRunnable runnable = new ConsistencyRunnable(); if (!runnable.needsExecution()) return; IRunnableContext context = fRunnableContext != null ? fRunnableContext : PlatformUI.getWorkbench().getProgressService(); context.run(true, true, runnable); }
protected void changeToExistingLibrary( Shell shell, IPath path, boolean isNew, final IJavaProject project) { try { IClasspathEntry[] entries = project.getRawClasspath(); int idx = indexOfClasspath(entries, path); if (idx == -1) { return; } IClasspathEntry[] res; if (isNew) { res = BuildPathDialogAccess.chooseContainerEntries(shell, project, entries); if (res == null) { return; } } else { IClasspathEntry resEntry = BuildPathDialogAccess.configureContainerEntry(shell, entries[idx], project, entries); if (resEntry == null) { return; } res = new IClasspathEntry[] {resEntry}; } final IClasspathEntry[] newEntries = new IClasspathEntry[entries.length - 1 + res.length]; System.arraycopy(entries, 0, newEntries, 0, idx); System.arraycopy(res, 0, newEntries, idx, res.length); System.arraycopy(entries, idx + 1, newEntries, idx + res.length, entries.length - idx - 1); IRunnableContext context = JavaPlugin.getActiveWorkbenchWindow(); if (context == null) { context = PlatformUI.getWorkbench().getProgressService(); } context.run( true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { project.setRawClasspath(newEntries, project.getOutputLocation(), monitor); } catch (CoreException e) { throw new InvocationTargetException(e); } } }); } catch (JavaModelException e) { String title = NewWizardMessages.UserLibraryMarkerResolutionGenerator_error_title; String message = NewWizardMessages.UserLibraryMarkerResolutionGenerator_error_creationfailed_message; ExceptionHandler.handle(e, shell, title, message); } catch (InvocationTargetException e) { String title = NewWizardMessages.UserLibraryMarkerResolutionGenerator_error_title; String message = NewWizardMessages.UserLibraryMarkerResolutionGenerator_error_applyingfailed_message; ExceptionHandler.handle(e, shell, title, message); } catch (InterruptedException e) { // user cancelled } }
/** * Copy/move make targets to a given container. Displays progress bar. * * @param makeTargets - array of make targets to copy. * @param container - container to copy/move to. * @param operation - copying operation. Should be one of {@link org.eclipse.swt.dnd.DND} * operations. * @param shell - shell to display a progress bar. * @see DND#DROP_NONE * @see DND#DROP_COPY * @see DND#DROP_MOVE * @see DND#DROP_LINK * @see DND#DROP_DEFAULT */ private static void copyTargetsWithProgressIndicator( final IMakeTarget[] makeTargets, final IContainer container, final int operation, final Shell shell) { IRunnableWithProgress runnable = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { boolean isMove = operation == DND.DROP_MOVE; String textHeader = isMove ? MakeUIPlugin.getResourceString("MakeTargetDnD.moving") // $NON-NLS-1$ : MakeUIPlugin.getResourceString("MakeTargetDnD.copying"); // $NON-NLS-1$ String textAction = isMove ? MakeUIPlugin.getResourceString("MakeTargetDnD.moving.one") // $NON-NLS-1$ : MakeUIPlugin.getResourceString("MakeTargetDnD.copying.one"); // $NON-NLS-1$ monitor.beginTask(textHeader + ' ' + container.getName(), makeTargets.length - 1); for (IMakeTarget makeTarget : makeTargets) { if (makeTarget != null) { monitor.subTask(textAction + ' ' + makeTarget.getName()); try { copyOneTarget(makeTarget, container, operation, shell, true); } catch (CoreException e) { // log failures but ignore all targets which failed MakeUIPlugin.log(e); } if (lastUserAnswer == IDialogConstants.CANCEL_ID) { break; } } monitor.worked(1); if (monitor.isCanceled()) { break; } } monitor.done(); lastUserAnswer = IDialogConstants.YES_ID; } }; IRunnableContext context = new ProgressMonitorDialog(shell); try { context.run(false, true, runnable); } catch (InvocationTargetException e) { MakeUIPlugin.log(e); } catch (InterruptedException e) { MakeUIPlugin.log(e); } }
/* * @return <code>true</code> if compare result is OK to show, <code>false</code> otherwise */ public boolean compareResultOK(CompareEditorInput input, IRunnableContext context) { final Shell shell = getShell(); try { // run operation in separate thread and make it cancelable if (context == null) context = PlatformUI.getWorkbench().getProgressService(); context.run(true, true, input); String message = input.getMessage(); if (message != null) { MessageDialog.openError( shell, Utilities.getString("CompareUIPlugin.compareFailed"), message); // $NON-NLS-1$ return false; } if (input.getCompareResult() == null) { MessageDialog.openInformation( shell, Utilities.getString("CompareUIPlugin.dialogTitle"), Utilities.getString("CompareUIPlugin.noDifferences")); // $NON-NLS-2$ //$NON-NLS-1$ return false; } return true; } catch (InterruptedException x) { // canceled by user } catch (InvocationTargetException x) { MessageDialog.openError( shell, Utilities.getString("CompareUIPlugin.compareFailed"), x.getTargetException().getMessage()); // $NON-NLS-1$ } return false; }
public static void run(boolean fork, IRunnableContext context, final IProject[] projects) { try { context.run( fork, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { IWorkspaceRunnable runnable = new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { doProjectUpdate(monitor, projects); } }; MakeUIPlugin.getWorkspace().run(runnable, monitor); } catch (CoreException e) { throw new InvocationTargetException(e); } catch (OperationCanceledException e) { throw new InterruptedException(e.getMessage()); } } }); } catch (InterruptedException e) { return; } catch (InvocationTargetException e) { MakeUIPlugin.logException( e, MakeUIPlugin.getResourceString("UpdateMakeProjectAction.exception.error"), MakeUIPlugin.getResourceString( "UpdateMakeProjectAction.eception.message")); //$NON-NLS-1$ //$NON-NLS-2$ } }
@Override public IType[] findTypes(Object[] elements, IRunnableContext context) throws InterruptedException, CoreException { // For spring boot app, instead of searching for a main type in the entire project and all its // libraries... try to look inside the project's pom for the corresponding property. for (Object e : elements) { if (e instanceof IProject) { try { e = JavaCore.create((IProject) e); } catch (Throwable ignore) { } } { IType type = isMainMethod(elements[0]); if (type != null) { return new IType[] {type}; } } if (e instanceof IJavaElement) { if (e instanceof IType) { if (hasMainMethod((IType) e)) { return new IType[] {(IType) e}; } } if (e instanceof ICompilationUnit) { for (IType t : ((ICompilationUnit) e).getAllTypes()) { if (hasMainMethod(t)) { return new IType[] {t}; } } } final IJavaProject jp = ((IJavaElement) e).getJavaProject(); final IType[][] result = new IType[][] {null}; try { context.run( /*fork*/ false, /*true*/ false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { result[0] = MainTypeFinder.guessMainTypes(jp, monitor); } catch (CoreException e) { throw new InvocationTargetException(e); } } }); } catch (InvocationTargetException exception) { throw ExceptionUtil.coreException(exception); } return result[0]; } } // This isn't the best thing to to do as it searches also in all the library jars for main // types. But it is // only a fallback option if the above code failed. (Or should we rather signal an error // instead?) return super.findTypes(elements, context); }
public static boolean runAndHandle( IRunnableContext runnableContext, IRunnableWithProgress op, boolean isCancellable, String errorTitle) { try { runnableContext.run(true, isCancellable, op); return true; } catch (InvocationTargetException e) { Throwable targetException = e.getTargetException(); if (targetException instanceof OperationCanceledException) { return false; } CoreException ce; if (targetException instanceof CoreException) { ce = (CoreException) e.getTargetException(); } else { ce = LangCore.createCoreException("Internal error: ", targetException); } UIOperationExceptionHandler.handleOperationStatus(errorTitle, ce); return false; } catch (InterruptedException e) { return false; } }
public void ensureRefreshedTypeHierarchy(final IRubyElement element, IRunnableContext context) throws InvocationTargetException, InterruptedException { if (element == null || !element.exists()) { freeHierarchy(); return; } boolean hierachyCreationNeeded = (fHierarchy == null || !element.equals(fInputElement)); if (hierachyCreationNeeded || fHierarchyRefreshNeeded) { IRunnableWithProgress op = new IRunnableWithProgress() { public void run(IProgressMonitor pm) throws InvocationTargetException, InterruptedException { try { doHierarchyRefresh(element, pm); } catch (RubyModelException e) { throw new InvocationTargetException(e); } catch (OperationCanceledException e) { throw new InterruptedException(); } } }; fHierarchyRefreshNeeded = true; context.run(true, true, op); fHierarchyRefreshNeeded = false; } }
protected Object[] fetchChildren(MethodWrapper methodWrapper) { IRunnableContext context = RubyPlugin.getActiveWorkbenchWindow(); MethodWrapperRunnable runnable = new MethodWrapperRunnable(methodWrapper); try { context.run(true, true, runnable); } catch (InvocationTargetException e) { ExceptionHandler.handle( e, CallHierarchyMessages.CallHierarchyContentProvider_searchError_title, CallHierarchyMessages.CallHierarchyContentProvider_searchError_message); return EMPTY_ARRAY; } catch (InterruptedException e) { return new Object[] {TreeTermination.SEARCH_CANCELED}; } return runnable.getCalls(); }
public ScannedFilesContentProvider(final String fileSuffixes) { final Set<IFile> files = new LinkedHashSet<IFile>(); IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { ProjectScanningBeansConfigLocator locator = new ProjectScanningBeansConfigLocator(fileSuffixes); files.addAll(locator.locateBeansConfigs(project.getProject(), monitor)); } }; try { IRunnableContext context = new ProgressMonitorDialog(SpringUIUtils.getStandardDisplay().getActiveShell()); context.run(true, true, runnable); } catch (InvocationTargetException e) { } catch (InterruptedException e) { } scannedFiles = files.toArray(); }
public int open() { final List list = new ArrayList(); IRunnableContext context = PlatformUI.getWorkbench().getProgressService(); IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { if (monitor == null) { monitor = new NullProgressMonitor(); } monitor.beginTask("Searching for known elements", 1); // $NON-NLS-1$ try { if (monitor.isCanceled()) { throw new InterruptedException(); } CMNamedNodeMap map = HTMLCMDocumentFactory.getCMDocument(CMDocType.HTML5_DOC_TYPE).getElements(); Iterator it = map.iterator(); while (it.hasNext()) { CMNode node = (CMNode) it.next(); if (!node.getNodeName().startsWith("SSI:")) { // $NON-NLS-1$ list.add(node.getNodeName().toLowerCase(Locale.US)); } monitor.worked(1); } } finally { monitor.done(); } } }; try { context.run(true, true, runnable); } catch (InvocationTargetException e) { return CANCEL; } catch (InterruptedException e) { return CANCEL; } setElements(list.toArray()); return super.open(); }
/** * This method inserts our jar library into the corresponding classpath. * * @param shell The corresponding shell of the plug-in. * @param project The project where the proposal should work. * @param entry The classpath entry of our library. * @param context The context of the selection. * @return The result of this process, if the library has been successful added. * @throws JavaModelException */ private static boolean addToClasspath( final Shell shell, final IJavaProject project, final IClasspathEntry entry, final IRunnableContext context) throws JavaModelException { boolean returnValue = false; boolean goAhead = true; final IClasspathEntry[] oldEntries = project.getRawClasspath(); final ArrayList<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(oldEntries.length + 1); final boolean added = false; for (int i = 0; i < oldEntries.length; i++) { IClasspathEntry current = oldEntries[i]; if (current.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { final IPath path = current.getPath(); if (path.equals(entry.getPath())) { returnValue = true; goAhead = false; } else if (path.matchingFirstSegments(entry.getPath()) > 0) { if (added) { final IClasspathEntry newEntry = null; current = newEntry; } else { current = entry; } } } else if (current.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { final IPath path = current.getPath(); if (path.segmentCount() > 0 && PerclipseActivator.PERFIDIX_HOME.equals(path.segment(0))) { if (added) { final IClasspathEntry newEntry = null; current = newEntry; } else { current = entry; } } } if (current != null && goAhead) { newEntries.add(current); } } if (goAhead) { if (!added) { newEntries.add(entry); } final IClasspathEntry[] newCPEntries = newEntries.toArray(new IClasspathEntry[newEntries.size()]); try { context.run( true, false, new IRunnableWithProgress() { public void run(final IProgressMonitor monitor) { try { project.setRawClasspath(newCPEntries, monitor); } catch (JavaModelException e) { PerclipseActivator.log(e); } } }); returnValue = true; } catch (InvocationTargetException e) { PerclipseActivator.log(e); final Throwable thowi = e.getTargetException(); if (thowi instanceof CoreException) { ErrorDialog.openError( shell, "Add Perfidix library to the build path", "Cannot Add", ((CoreException) thowi).getStatus()); } } catch (InterruptedException e) { PerclipseActivator.log(e); } } return returnValue; }
/** * Creates a new project resource. * * @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; } try { IProjectUtilities.configurePackagesFilter(newProjectHandle); } catch (CoreException e) { DartCore.logError("Could not set package filter on folder " + newProjectHandle.getName(), e); } return newProjectHandle; }