Java Code Examples for org.eclipse.core.resources.WorkspaceJob#schedule()
The following examples show how to use
org.eclipse.core.resources.WorkspaceJob#schedule() .
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: DefinitionContributionItem.java From neoscada with Eclipse Public License 1.0 | 6 votes |
protected void run ( final String name ) throws URISyntaxException { final WorkspaceJob job = new WorkspaceJob ( String.format ( "Run recipe: %s", name ) ) { @Override public IStatus runInWorkspace ( final IProgressMonitor monitor ) throws CoreException { try { RecipeHelper.processFile ( DefinitionContributionItem.this.parent, DefinitionContributionItem.this.definition, getProfile (), monitor ); } catch ( final Exception e ) { logger.warn ( "Failed to process", e ); return StatusHelper.convertStatus ( Activator.PLUGIN_ID, e ); } return Status.OK_STATUS; } }; job.setUser ( true ); job.setSystem ( false ); job.schedule (); }
Example 2
Source File: BuilderUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Schedules a full rebuild on a project. * * @param project the project to rebuild */ public static void scheduleRebuild(final IProject project) { WorkspaceJob buildJob = new WorkspaceJob("Building " + project.getName()) { @Override public boolean belongsTo(Object family) { return ResourcesPlugin.FAMILY_MANUAL_BUILD.equals(family); } @Override public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { project.build(IncrementalProjectBuilder.FULL_BUILD, monitor); return Status.OK_STATUS; } }; buildJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule()); buildJob.setUser(true); buildJob.schedule(); }
Example 3
Source File: WebAppProjectCreator.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
private void jobSetupFacets(final IProject project) { // Facet setup is done in a workspace job since this can be long running, // hence shouldn't be from the UI thread. WorkspaceJob setupFacetsJob = new WorkspaceJob("Setting up facets") { @Override public IStatus runInWorkspace(IProgressMonitor monitor) { try { // Create faceted project IFacetedProject facetedProject = ProjectFacetsManager.create(project, true, monitor); // Add Java facet by default IProjectFacet javaFacet = ProjectFacetsManager.getProjectFacet(FACET_JST_JAVA); facetedProject.installProjectFacet(javaFacet.getDefaultVersion(), null, monitor); return Status.OK_STATUS; } catch (CoreException e) { // Log and continue GdtPlugin.getLogger().logError(e); return new Status(IStatus.ERROR, GdtPlugin.PLUGIN_ID, e.toString(), e); } } }; setupFacetsJob.schedule(); }
Example 4
Source File: WorkspaceModelsManager.java From gama with GNU General Public License v3.0 | 6 votes |
public static void linkSampleModelsToWorkspace() { final WorkspaceJob job = new WorkspaceJob("Updating the Built-in Models Library") { @Override public IStatus runInWorkspace(final IProgressMonitor monitor) { // DEBUG.OUT("Asynchronous link of models library..."); GAMA.getGui().refreshNavigator(); return GamaBundleLoader.ERRORED ? Status.CANCEL_STATUS : Status.OK_STATUS; } }; job.setUser(true); job.schedule(); }
Example 5
Source File: RefreshAction.java From gama with GNU General Public License v3.0 | 6 votes |
@Override public void run() { if (super.getSelectedResources().isEmpty()) { final WorkspaceJob job = new WorkspaceJob("Refreshing the GAMA Workspace") { @Override public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException { final IRefreshHandler refresh = WorkbenchHelper.getService(IRefreshHandler.class); if (refresh != null) { refresh.completeRefresh(resources); } return OK_STATUS; }; }; job.setUser(true); job.schedule(); } else { super.run(); } }
Example 6
Source File: ConvertToHybridProjectHandler.java From thym with Eclipse Public License 1.0 | 6 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException { IProject project = getProject(event); if(project != null ){ final IProject theProject = project;//to pass to Job WorkspaceJob job = new WorkspaceJob(NLS.bind("Convert {0} to Hybrid Mobile project", project.getName())) { @Override public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { HybridProjectCreator creator = new HybridProjectCreator(); creator.convertProject(theProject, new NullProgressMonitor()); return Status.OK_STATUS; } }; job.schedule(); } return null; }
Example 7
Source File: ProjectsManager.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override public Job updateProject(IProject project, boolean force) { if (project == null || (!ProjectUtils.isMavenProject(project) && !ProjectUtils.isGradleProject(project))) { return null; } JavaLanguageServerPlugin.sendStatus(ServiceStatus.Message, "Updating " + project.getName() + " configuration"); WorkspaceJob job = new WorkspaceJob("Update project " + project.getName()) { @Override public boolean belongsTo(Object family) { return IConstants.UPDATE_PROJECT_FAMILY.equals(family) || (IConstants.JOBS_FAMILY + "." + project.getName()).equals(family) || IConstants.JOBS_FAMILY.equals(family); } @Override public IStatus runInWorkspace(IProgressMonitor monitor) { IStatus status = Status.OK_STATUS; String projectName = project.getName(); SubMonitor progress = SubMonitor.convert(monitor, 100).checkCanceled(); try { long start = System.currentTimeMillis(); project.refreshLocal(IResource.DEPTH_INFINITE, progress.split(5)); Optional<IBuildSupport> buildSupport = getBuildSupport(project); if (buildSupport.isPresent()) { buildSupport.get().update(project, force, progress.split(95)); registerWatchers(true); } long elapsed = System.currentTimeMillis() - start; JavaLanguageServerPlugin.logInfo("Updated " + projectName + " in " + elapsed + " ms"); } catch (CoreException e) { String msg = "Error updating " + projectName; JavaLanguageServerPlugin.logError(msg); status = StatusFactory.newErrorStatus(msg, e); } return status; } }; job.schedule(); return job; }
Example 8
Source File: MarkerUtils.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
public static void scheduleDeleteMarkers(IProject p){ WorkspaceJob deleteMarkersJob = new WorkspaceJob(Messages.BuilderUtils_DeleteMarkers) { @Override public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { MarkerUtils.deleteBuildProblemMarkers(p, true, IResource.DEPTH_INFINITE); return Status.OK_STATUS; } }; //TODO : is this a correct scheduling rule? Perhaps we should include every individual IFile from project... deleteMarkersJob.setRule(ResourceUtils.createRule(Arrays.asList(p))); deleteMarkersJob.schedule(); }
Example 9
Source File: MarkerUtil.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
/** * Create an Eclipse marker for given BugInstance. * * @param javaProject * the project * @param monitor */ public static void createMarkers(final IJavaProject javaProject, final SortedBugCollection theCollection, final ISchedulingRule rule, IProgressMonitor monitor) { if (monitor.isCanceled()) { return; } final List<MarkerParameter> bugParameters = createBugParameters(javaProject, theCollection, monitor); if (monitor.isCanceled()) { return; } WorkspaceJob wsJob = new WorkspaceJob("Creating SpotBugs markers") { @Override public IStatus runInWorkspace(IProgressMonitor monitor1) throws CoreException { IProject project = javaProject.getProject(); try { new MarkerReporter(bugParameters, theCollection, project).run(monitor1); } catch (CoreException e) { FindbugsPlugin.getDefault().logException(e, "Core exception on add marker"); return e.getStatus(); } return monitor1.isCanceled() ? Status.CANCEL_STATUS : Status.OK_STATUS; } }; wsJob.setRule(rule); wsJob.setSystem(true); wsJob.setUser(false); wsJob.schedule(); }
Example 10
Source File: BuilderUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * Schedules a full rebuild on all projects in the workspace that have any of * the specified natures. */ public static void scheduleRebuildAll(final String... natureIds) { final IWorkspace workspace = ResourcesPlugin.getWorkspace(); WorkspaceJob buildJob = new WorkspaceJob("Building workspace projects") { @Override public boolean belongsTo(Object family) { return ResourcesPlugin.FAMILY_MANUAL_BUILD.equals(family); } @Override public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { for (IProject project : workspace.getRoot().getProjects()) { for (String natureId : natureIds) { if (NatureUtils.hasNature(project, natureId)) { project.build(IncrementalProjectBuilder.FULL_BUILD, monitor); break; } } } return Status.OK_STATUS; } }; buildJob.setRule(workspace.getRuleFactory().buildRule()); buildJob.setUser(true); buildJob.schedule(); }
Example 11
Source File: MarkerManager.java From xds-ide with Eclipse Public License 1.0 | 4 votes |
/** * Creates a bunch of markers in the workspace as the single atomic operation - thus resulting in a single delta * @param fileToMarkerInfo * @param progressMonitor */ public static void commitParserMarkers(final Map<IFileStore, FileMarkerInfo> fileToMarkerInfo, IProgressMonitor progressMonitor) { int i = 0; final IFileStore[] files = new IFileStore[fileToMarkerInfo.size()]; IFile[] ifiles = new IFile[fileToMarkerInfo.size()]; for (Entry<IFileStore, FileMarkerInfo> keyValue : fileToMarkerInfo.entrySet()) { files[i] = keyValue.getKey(); ifiles[i] = keyValue.getValue().getIFile(); i++; } ISchedulingRule rule = ResourceUtils.createRule(Arrays.asList(ifiles)); WorkspaceJob job = new WorkspaceJob("Update markers job") { //$NON-NLS-1$ @Override public IStatus runInWorkspace(IProgressMonitor monitor){ for (int j = 0; j < files.length; j++) { FileMarkerInfo fileMarkerInfo = fileToMarkerInfo.get(files[j]); if (fileMarkerInfo != null) { IFile iFile = fileMarkerInfo.getIFile(); try { if (iFile.exists()) { Map<Integer, IMarker> offset2BuildMarker = createOffset2BuildMarkerMap(iFile); MarkerUtils.deleteParserProblemMarkers(iFile, IResource.DEPTH_INFINITE); Set<MarkerInfo> parserMarkers = fileMarkerInfo.getParserMarkers(); for (MarkerInfo parserMarker : parserMarkers) { if (offset2BuildMarker.containsKey(parserMarker.getCharStart())) { continue; } IMarker marker = iFile.createMarker(parserMarker.getType()); marker.setAttributes(parserMarker.getAttributes()); } } } catch (CoreException e) { LogHelper.logError(e); } } } return Status.OK_STATUS; } }; job.setRule(rule); job.schedule(); }
Example 12
Source File: BuilderUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 4 votes |
/** * Forces re-validation of a set of compilation units by the JDT Java Builder. * * @param cus the compilation units to re-validate * @param description a brief description of the external job that forcing the * re-validation. This shows up in the Eclipse status bar while * re-validation is taking place. */ public static void revalidateCompilationUnits( final Set<ICompilationUnit> cus, String description) { WorkspaceJob revalidateJob = new WorkspaceJob(description) { @Override public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { final IWorkingCopyManager wcManager = JavaPlugin.getDefault().getWorkingCopyManager(); for (ICompilationUnit cu : cus) { if (!cu.getResource().exists()) { CorePluginLog.logWarning(MessageFormat.format( "Cannot revalidate non-existent compilation unit {0}", cu.getElementName())); continue; } final IEditorPart editorPart = getOpenEditor(cu); /* * If the .java file is open in an editor (without unsaved changes), * make a "null" edit by inserting an empty string at the top of the * file and then tell the editor to save. If incremental building is * enabled, this will trigger a re-validation of the file. */ if (editorPart != null && !editorPart.isDirty()) { // Need to do the editor stuff from the UI thread Display.getDefault().asyncExec(new Runnable() { public void run() { try { // Get the working copy open in the editor ICompilationUnit wc = wcManager.getWorkingCopy(editorPart.getEditorInput()); wc.getBuffer().replace(0, 0, ""); editorPart.doSave(new NullProgressMonitor()); } catch (JavaModelException e) { CorePluginLog.logError(e); } } }); } else { /* * If the .java file is not currently open, or if it's open with * unsaved changes, trigger re-validation by touching the underlying * resource. */ cu.getResource().touch(null); } } return StatusUtilities.OK_STATUS; } }; revalidateJob.schedule(); }