org.eclipse.core.runtime.ICoreRunnable Java Examples
The following examples show how to use
org.eclipse.core.runtime.ICoreRunnable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClaferPage.java From CogniCrypt with Eclipse Public License 2.0 | 6 votes |
public boolean checkModel() { final Job compileJob = Job.create("Compile Clafer model", (ICoreRunnable) monitor -> { // UI updates can only be run in the display thread, // so do them via Display.getDefault() Display.getDefault().asyncExec(() -> { ClaferPage.this.feedbackComposite.setFeedback(" (compiling...)"); // do the tedious work final File cfrFile = new File(Utils.getResourceFromWithin(Constants.CFR_FILE_DIRECTORY_PATH), "temporaryModel" + Constants.CFR_EXTENSION); ClaferPage.this.compositeToHoldGranularUIElements.getClaferModel().toFile(cfrFile.getAbsolutePath()); if (ClaferModel.compile(cfrFile.getAbsolutePath())) { ClaferPage.this.feedbackComposite.setFeedback("Compilation successful"); } else { ClaferPage.this.feedbackComposite.setFeedback("Compilation error"); } }); }); // start the asynchronous task compileJob.schedule(); return false; }
Example #2
Source File: ModelRefreshTests.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
/** Record and return the set of files altered when running the provided block. */ private static Set<IFile> recordChangedFilesDuring(IWorkspace workspace, ICoreRunnable block) throws CoreException { Set<IFile> changed = new LinkedHashSet<>(); IResourceChangeListener listener = event -> { try { changed.addAll(ResourceUtils.getAffectedFiles(event.getDelta()).values()); } catch (CoreException ex) { throw new RuntimeException(ex); } }; workspace.addResourceChangeListener(listener); try { block.run(new NullProgressMonitor()); } finally { workspace.removeResourceChangeListener(listener); } return changed; }
Example #3
Source File: TmfProjectModelElement.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
/** * Returns the trace specific supplementary folder under the project's * supplementary folder. Its parent folders will be created if they don't exist. * If createFolder is true, the returned folder will be created, otherwise it * may not exist. * * @param supplFolderPath * folder path relative to the project's supplementary folder * @param createFolder * if true, the returned folder will be created * @param progressMonitor * the progress monitor * @return the trace specific supplementary folder * @since 4.0 */ public IFolder prepareTraceSupplementaryFolder(String supplFolderPath, boolean createFolder, IProgressMonitor progressMonitor) { SubMonitor subMonitor = SubMonitor.convert(progressMonitor); IFolder folder = getTraceSupplementaryFolder(supplFolderPath); IFolder propertiesFolder = folder.getFolder(TmfCommonConstants.TRACE_PROPERTIES_FOLDER); if ((createFolder && propertiesFolder.exists() && propertiesFolder.isHidden()) || (!createFolder && folder.getParent().exists())) { return folder; } try { ICoreRunnable runnable = monitor -> { if (createFolder) { TraceUtils.createFolder(propertiesFolder, monitor); propertiesFolder.setHidden(true); } else { TraceUtils.createFolder((IFolder) folder.getParent(), monitor); } }; ResourcesPlugin.getWorkspace().run(runnable, folder.getProject(), IWorkspace.AVOID_UPDATE, subMonitor); } catch (CoreException e) { Activator.getDefault().logError("Error creating supplementary folder " + folder.getFullPath(), e); //$NON-NLS-1$ } return folder; }
Example #4
Source File: LazyCommonViewerContentProvider.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
protected void asyncReload(){ Job job = Job.create(getJobName(), new ICoreRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException{ loadedElements = getElements(null); Display.getDefault().asyncExec(() -> { // virtual table ... AbstractTableViewer viewer = (AbstractTableViewer) commonViewer.getViewerWidget(); if (viewer != null && !viewer.getControl().isDisposed()) { viewer.setItemCount(loadedElements.length); } // trigger viewer refresh commonViewer.notify(Message.update); }); } }); job.setPriority(Job.SHORT); job.schedule(); }
Example #5
Source File: ProjectCacheInvalidationPluginTest.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Runs the given {@link ICoreRunnable} as an atomic workspace operation with a lock on the whole workspace. * * All resource changes performed by the given {@code operation} will be collected and a single * {@link IResourceChangeEvent} will be issued for all changes. */ private void runAtomicWorkspaceOperation(ICoreRunnable operation) throws CoreException { final IWorkspace workspace = ResourcesPlugin.getWorkspace(); workspace.run(operation, workspace.getRoot(), IWorkspace.AVOID_UPDATE, // issue one resource change event at the end of the operation new NullProgressMonitor()); }
Example #6
Source File: DotnetTestTab.java From aCute with Eclipse Public License 2.0 | 5 votes |
private void searchForTestClass() { if (!pathText.getText().equals(loadedTestsParentProject) || testMethods == null) { loadedTestsParentProject = pathText.getText(); testMethods = null; Job.create(Messages.DotnetTestTab_retrieveClasses, (ICoreRunnable) monitor -> { testMethods = DotnetTestAccessor.getTestMethods(projectPath.toFile()); Display.getDefault().asyncExec(() -> { displayClassSelectorDialog(); }); }).schedule(); } else { displayClassSelectorDialog(); } }
Example #7
Source File: DotnetTestTab.java From aCute with Eclipse Public License 2.0 | 5 votes |
private void searchForTestMethods() { if (!pathText.getText().equals(loadedTestsParentProject) || testMethods == null) { loadedTestsParentProject = pathText.getText(); testMethods = null; Job.create(Messages.DotnetTestTab_retrieveClasses, (ICoreRunnable) monitor -> { testMethods = DotnetTestAccessor.getTestMethods(projectPath.toFile()); Display.getDefault().asyncExec(() -> { displayMethodSelectorDialog(); }); }).schedule(); } else { displayMethodSelectorDialog(); } }
Example #8
Source File: DotnetNewWizardPage.java From aCute with Eclipse Public License 2.0 | 5 votes |
private void updateTemplateList() { if(templateViewer.getList().isDisposed()) { return; } setTemplateViewToText(Messages.DotnetNewWizardPage_loadingTemplates); try { AcutePlugin.getDotnetCommand(); } catch (IllegalStateException e) { setTemplateViewToText(Messages.DotnetNewWizardPage_dotnetError); return; } Job.create(Messages.DotnetNewWizardPage_retriveTemplates, (ICoreRunnable) monitor -> { final java.util.List<Template> templates = DotnetNewAccessor.getTemplates(); Display.getDefault().asyncExec(() -> { templateViewer.getList().removeAll(); if (!templates.isEmpty()) { ((GridData) templateViewer.getList().getLayoutData()).heightHint = 100; Shell shell = templateViewer.getControl().getShell(); shell.setSize(shell.getSize().x, shell.getSize().y + 100); templateViewer.setInput(templates); if (templateViewer.getSelection().isEmpty()) { templateViewer.getList().setSelection(0); } templateViewer.getList().setEnabled(true); setPageComplete(isPageComplete()); } else { templateViewer.add(Messages.DotnetNewWizardPage_noTemplatesError); } templateViewer.getControl().getParent().layout(); }); }).schedule(); }
Example #9
Source File: CorrosionPlugin.java From corrosion with Eclipse Public License 2.0 | 5 votes |
@Override public void start(BundleContext context) throws Exception { super.start(context); setSharedInstance(this); Job.create("Import .cargo in workspace", //$NON-NLS-1$ (ICoreRunnable) (monitor -> CargoTools.ensureDotCargoImportedAsProject(monitor))).schedule(); }
Example #10
Source File: ResourceUtil.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
private static @Nullable IResource copySymlink(IResource resource, IPath destinationPath, SubMonitor monitor, IWorkspaceRoot workspaceRoot) throws CoreException { AtomicReference<IResource> newResourceRef = new AtomicReference<>(); Path originalLinkedFile = Paths.get(resource.getProject().getLocation().append(resource.getProjectRelativePath()).toOSString()); IPath newLocation = workspaceRoot.findMember(destinationPath.segment(0)).getLocation().append(destinationPath.removeFirstSegments(1)); Path newLinkedFile = Paths.get(newLocation.toOSString()); IResource parent = workspaceRoot.findMember(destinationPath.removeLastSegments(1)); if (parent == null) { throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Parent resource does not exist: " + destinationPath.removeLastSegments(1))); //$NON-NLS-1$ ) } ResourcesPlugin.getWorkspace().run((ICoreRunnable) (mon -> { try { SubMonitor subMon = SubMonitor.convert(mon, 2); Files.copy(originalLinkedFile, newLinkedFile, LinkOption.NOFOLLOW_LINKS); parent.refreshLocal(IResource.DEPTH_ONE, subMon.split(1)); IResource newResource = workspaceRoot.findMember(destinationPath); if (newResource == null) { return; } newResource.refreshLocal(IResource.DEPTH_INFINITE, subMon.split(1)); @SuppressWarnings("null") Map<QualifiedName, String> persistentProperties = resource.getPersistentProperties(); if (persistentProperties != null) { for (Map.Entry<QualifiedName, String> entry : persistentProperties.entrySet()) { newResource.setPersistentProperty(entry.getKey(), entry.getValue()); } } newResourceRef.set(newResource); } catch (IOException e) { throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error copying symbolic link", e)); //$NON-NLS-1$ ) } }), parent.getParent(), IWorkspace.AVOID_UPDATE, monitor); return newResourceRef.get(); }
Example #11
Source File: TmfProjectRegistry.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
private static void deleteSupplementaryResources(TmfTraceElement trace) { /* * Delete supplementary resources as an atomic workspace operation. To ensure no * dialog is shown to the user, run it in a job outside of the UI thread. */ Job.createSystem("TmfProjectRegistry.deleteSupplementaryResources Job", monitor -> { //$NON-NLS-1$ try { ResourcesPlugin.getWorkspace().run((ICoreRunnable) (mon -> { trace.deleteSupplementaryResources(); }), trace.getProject().getResource(), IWorkspace.AVOID_UPDATE, monitor); } catch (CoreException e) { Activator.getDefault().logError("Error deleting supplementary resources for " + trace.getName(), e); //$NON-NLS-1$ } }).schedule(); }