Java Code Examples for org.eclipse.core.runtime.jobs.Job#setRule()

The following examples show how to use org.eclipse.core.runtime.jobs.Job#setRule() . 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: M2DocNewProjectWizard.java    From M2Doc with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean performFinish() {
    final String projectName = newProjectPage.getProjectName();
    final String templateName = newTemplatePage.getTemplateName();
    final String variableName = variablePage.getVariableName();
    final EObject variableValue = variablePage.getVariableValue();
    final URI genconfURI = URI.createPlatformResourceURI(generationPage.getGenerationName(), true);
    final URI destinationURI = URI.createPlatformResourceURI(generationPage.getDestinationName(), true);
    final URI validationURI = URI.createPlatformResourceURI(generationPage.getValidationName(), true);
    final boolean launchGeneration = generationPage.getLaunchGeneration();

    final Job job = new FinishJob("Creating M2Doc project: " + projectName, variableValue, variableName,
            launchGeneration, projectName, templateName, genconfURI, destinationURI, validationURI);
    job.setRule(ResourcesPlugin.getWorkspace().getRoot());
    job.schedule();

    return true;
}
 
Example 2
Source File: EclipseContextGeneratorExecutorLookup.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
public void executeGenerator(IFile file) {
	final GeneratorModel model = GenModelLoader.load(file);
	Job generatorJob = new Job("Execute SCT Genmodel " + file.getName()) {
		@Override
		protected IStatus run(IProgressMonitor monitor) {
			try {
				execute(model);
			} catch (Exception ex) {
				return new Status(IStatus.ERROR, BuilderActivator.PLUGIN_ID, "An error occurred during code generation.", ex);
			}
			return Status.OK_STATUS;
		}
	};
	generatorJob.setRule(file.getProject().getWorkspace().getRoot());
	generatorJob.schedule();
}
 
Example 3
Source File: UpdateCloudToolsEclipseProjectHandler.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
  IProject project = ProjectFromSelectionHelper.getFirstProject(event);
  if (!CloudToolsEclipseProjectUpdater.hasOldContainers(project)) {
    throw new ExecutionException(Messages.getString("project.appears.up.to.date")); //$NON-NLS-1$
  }
  String jobName = Messages.getString("updating.project", project.getName()); //$NON-NLS-1$
  Job updateJob = new WorkspaceJob(jobName) {
    @Override
    public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
      return CloudToolsEclipseProjectUpdater.updateProject(project, SubMonitor.convert(monitor));
    }
  };
  updateJob.setRule(project.getWorkspace().getRoot());
  updateJob.setUser(true);
  updateJob.schedule();
  return null;
}
 
Example 4
Source File: CloudToolsEclipseProjectNotifier.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Override
public void earlyStartup() {
  workbench = PlatformUI.getWorkbench();
  workspace = ResourcesPlugin.getWorkspace();

  Job projectUpdater = new WorkspaceJob(Messages.getString("updating.projects.jobname")) { //$NON-NLS-1$
    @Override
    public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
      SubMonitor progress = SubMonitor.convert(monitor, 40);
      progress.subTask(Messages.getString("searching.for.projects")); //$NON-NLS-1$
      Collection<IProject> projects = findCandidates(progress.newChild(10));
      if (projects.isEmpty()) {
        return Status.OK_STATUS;
      }
      projects = promptUser(projects, progress.newChild(5));
      if (projects.isEmpty()) {
        return Status.OK_STATUS;
      }
      progress.subTask(Messages.getString("updating.projects")); //$NON-NLS-1$
      return upgradeProjects(projects, progress.newChild(25));
    }
  };
  projectUpdater.setRule(workspace.getRoot());
  projectUpdater.setUser(true);
  projectUpdater.schedule(500);
}
 
Example 5
Source File: Activator.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
private void visit(IJavaElementDelta delta) {
  switch (delta.getElement().getElementType()) {
    case IJavaElement.JAVA_PROJECT:
      if ((delta.getFlags() & IJavaElementDelta.F_CLASSPATH_CHANGED) != 0) {
        final IJavaProject javaProject = (IJavaProject) delta.getElement();
        Job updateContainerStateJob = new WorkspaceJob("Updating Google Cloud libraries") {
          @Override
          public IStatus runInWorkspace(IProgressMonitor monitor) {
            BuildPath.checkLibraryList(javaProject, null);
            return Status.OK_STATUS;
          }
        };
        IWorkspace workspace = javaProject.getProject().getWorkspace();
        ISchedulingRule buildRule = workspace.getRuleFactory().buildRule();
        updateContainerStateJob.setRule(buildRule);
        updateContainerStateJob.setSystem(true);
        updateContainerStateJob.schedule();
      }
      break;
    case IJavaElement.JAVA_MODEL:
      visitChildren(delta);
      break;
    default:
      break;
  }
}
 
Example 6
Source File: SCTPerspectiveManager.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
protected void schedulePerspectiveSwitchJob(final String perspectiveID) {
	Job switchJob = new UIJob(DebugUIPlugin.getStandardDisplay(), "Perspective Switch Job") { //$NON-NLS-1$
		public IStatus runInUIThread(IProgressMonitor monitor) {
			IWorkbenchWindow window = DebugUIPlugin.getActiveWorkbenchWindow();
			if (window != null && !(isCurrentPerspective(window, perspectiveID))) {
				switchToPerspective(window, perspectiveID);
			}
			// Force the debug view to open
			if (window != null) {
				try {
					window.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(SIMULATION_VIEW_ID);
				} catch (PartInitException e) {
					e.printStackTrace();
				}
			}
			return Status.OK_STATUS;
		}
	};
	switchJob.setSystem(true);
	switchJob.setPriority(Job.INTERACTIVE);
	switchJob.setRule(AsynchronousSchedulingRuleFactory.getDefault().newSerialPerObjectRule(this));
	switchJob.schedule();
}
 
Example 7
Source File: TraceExplorerComposite.java    From tlaplus with MIT License 5 votes vote down vote up
private void saveModel() {
      view.getModel().setTraceExplorerExpression(FormHelper.getSerializedInput(tableViewer));
      
  	final Job job = new WorkspaceJob("Saving updated model...") {
	public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
		view.getModel().save(monitor);
		return Status.OK_STATUS;
	}
};
job.setRule(ResourcesPlugin.getWorkspace().getRoot());
job.setUser(true);
job.schedule();
  }
 
Example 8
Source File: Activator.java    From tlaplus with MIT License 5 votes vote down vote up
public void stop(BundleContext context) throws Exception
    {
        // unregister the listeners
    	if (specManager != null)
    		specManager.terminate();
        
		// do not null specManager and plugin to let backend jobs finish cleanly
        //
        // remember: Nulling specManager might cause the initialization of a new
        // specManager object during shutdown if this method nulls it and subsequent
        // calls to getSpecManager() occur. This might potentially leave an inconsistent 
        // spec manager on which terminate() might never be called.

//        specManager = null;
//        plugin = null;

    	// In case of a clean shutdown explicitly do a *full* workspace save. If omitted,
    	// the Eclipse foundation's default is to just trigger a *snapshot* save.
    	// The default snapshot save is apparently insufficient when the Eclipse foundation
    	// itself gets updated to a newer version (from 3.x to 4.x in the current case)
    	// (The assumption being that the on-disk format of the *.snap files changed causing 
    	// a subsequent startup to crash the whole Toolbox). 
    	final IWorkspace workspace = ResourcesPlugin.getWorkspace();
        final Job saveJob = new WorkspaceJob("Saving workspace...") {
			/* (non-Javadoc)
			 * @see org.eclipse.core.resources.WorkspaceJob#runInWorkspace(org.eclipse.core.runtime.IProgressMonitor)
			 */
			public IStatus runInWorkspace(final IProgressMonitor monitor)
					throws CoreException {
		        return workspace.save(true, monitor);
			}
        };
        saveJob.setRule(workspace.getRuleFactory().buildRule());
        saveJob.schedule();
    	
        super.stop(context);
    }
 
Example 9
Source File: HelloWorldValidatorConfigurationBlock.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Job getBuildJob(IProject project) {
	Job buildJob = new OptionsConfigurationBlock.BuildJob("Validation Settings Changed", project);
	buildJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule());
	buildJob.setUser(true);
	return buildJob;
}
 
Example 10
Source File: ResourceUtils.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public static void scheduleJob(final IBaseClosure<Void, CoreException> jobRunnable, ISchedulingRule rule, String jobCaption, boolean user) {
	Job job = new Job(jobCaption) {
		public IStatus run(IProgressMonitor monitor) {
			try {
				jobRunnable.execute(null);
			} catch (CoreException e) {
				LogHelper.logError(e);
			}
			return Status.OK_STATUS;
		}
	};
	job.setRule(rule);
	job.setUser(user);
	job.schedule();
}
 
Example 11
Source File: SVNTeamProviderType.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
    * Create and schedule an auto-add job
    */

private static synchronized void createAutoAddJob(IProject project) {
	Job j = new AutoAddJob(project);
       j.setSystem(true);
       j.setPriority(Job.SHORT);
       j.setRule(ResourcesPlugin.getWorkspace().getRoot());
	j.schedule();
}
 
Example 12
Source File: SyntaxInitHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void triggerInitialization(Collection<IPath> roots) {

	Job job = new WorkspaceJob("Initialize Workspace") {
		@Override
		public IStatus runInWorkspace(IProgressMonitor monitor) {
			long start = System.currentTimeMillis();
			try {
				projectsManager.initializeProjects(roots, monitor);
				JavaLanguageServerPlugin.logInfo("Workspace initialized in " + (System.currentTimeMillis() - start) + "ms");
			} catch (Exception e) {
				JavaLanguageServerPlugin.logException("Initialization failed ", e);
			}

			return Status.OK_STATUS;
		}

		/* (non-Javadoc)
		 * @see org.eclipse.core.runtime.jobs.Job#belongsTo(java.lang.Object)
		 */
		@SuppressWarnings("unchecked")
		@Override
		public boolean belongsTo(Object family) {
			Collection<IPath> rootPathsSet = roots.stream().collect(Collectors.toSet());
			boolean equalToRootPaths = false;
			if (family instanceof Collection<?>) {
				equalToRootPaths = rootPathsSet.equals(((Collection<IPath>) family).stream().collect(Collectors.toSet()));
			}

			return JAVA_LS_INITIALIZATION_JOBS.equals(family) || equalToRootPaths;
		}
	};
	job.setPriority(Job.BUILD);
	job.setRule(ResourcesPlugin.getWorkspace().getRoot());
	job.schedule();
}
 
Example 13
Source File: BuilderConfigurationBlock.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Job getBuildJob(IProject project) {
	Job buildJob = new OptionsConfigurationBlock.BuildJob(Messages.BuilderConfigurationBlock_BuildJob_Title0, project);
	buildJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule());
	buildJob.setUser(true);
	return buildJob;
}
 
Example 14
Source File: CoreUtility.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns a build job
 * @param project The project to build or <code>null</code> to build the workspace.
 * @return the build job
 */
public static Job getBuildJob(final IProject project) {
	Job buildJob= new BuildJob(JavaUIMessages.CoreUtility_job_title, project);
	buildJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule());
	buildJob.setUser(true);
	return buildJob;
}
 
Example 15
Source File: AbstractValidatorConfigurationBlock.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.15
 */
@Override
protected Job getBuildJob(IProject project) {
	Job buildJob = new OptionsConfigurationBlock.BuildJob(
			Messages.ValidationConfigurationBlock_build_job_title, project);
	buildJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule());
	buildJob.setUser(true);
	return buildJob;

}
 
Example 16
Source File: XtextValidatorConfigurationBlock.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Job getBuildJob(IProject project) {
	Job buildJob = new OptionsConfigurationBlock.BuildJob(Messages.XtextValidatorConfigurationBlock_11, project);
	buildJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule());
	buildJob.setUser(true);
	return buildJob;

}
 
Example 17
Source File: WidgetModel.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void modelDirtyStateChanged(IStructuredModel model, boolean isDirty) {
	if (!isDirty) {
		synchronized (this) {
			final HybridProject project = getProject();

			final IDOMModel domModel = (IDOMModel) model;

			Job updatePlugins = new Job(
					"Synchronize project " + project.getProject().getName() + " with config.xml") {

				@Override
				protected IStatus run(IProgressMonitor monitor) {
					if (project.getProject().exists()) {
						reloadEditableWidget();
						Widget newWidget = load(domModel.getDocument());
						syncEngines(project, newWidget, monitor);
						syncPlugins(project, newWidget, monitor);
					}
					return Status.OK_STATUS;
				}
			};

			updatePlugins.addJobChangeListener(new JobChangeAdapter() {

				@Override
				public void done(IJobChangeEvent event) {
					lastWidget.reload(domModel.getDocument().getDocumentElement());
					reloadEditableWidget();
					readonlyWidget = null;
					readonlyTimestamp = -1;
				}
			});
			ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRuleFactory().modifyRule(project.getProject());
			updatePlugins.setRule(rule);
			updatePlugins.schedule();
		}
	}
}
 
Example 18
Source File: M2DocNewTemplateWizard.java    From M2Doc with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean performFinish() {
    final String templateName = newTemplatePage.getTemplateName();
    final String variableName = variablePage.getVariableName();
    final EObject variableValue = variablePage.getVariableValue();

    final Job job = new FinishJob(templateName, variableValue, variableName);
    job.setRule(ResourcesPlugin.getWorkspace().getRoot());
    job.schedule();

    return true;
}
 
Example 19
Source File: ValidateHandler.java    From M2Doc with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void execute(ExecutionEvent event, final Generation generation) {
    final Shell shell = HandlerUtil.getActiveShell(event);

    final Job job = new ValidateJob(generation, shell);
    job.setRule(ResourcesPlugin.getWorkspace().getRoot());
    job.schedule();

}
 
Example 20
Source File: TraceExplorerComposite.java    From tlaplus with MIT License 4 votes vote down vote up
@Override
public void run() {
	final Spec currentSpec = ToolboxHandle.getCurrentSpec();
	if (currentSpec != null && view.getModel() != null) {
		// From the set of all modules remove those already included in the scope. The
		// remaining unused modules are the ones a user might potentially be additional
		// includes.
		final Set<String> availableModules = currentSpec.getModules().stream().map(m -> m.getModuleName())
				.collect(Collectors.toSet());
		final FilenameToStream resolver = currentSpec.getValidRootModule().getResolver();
		if (resolver instanceof RCPNameToFileIStream) {
			final RCPNameToFileIStream rcpResolver = (RCPNameToFileIStream) resolver;
			// Strip off ".tla" file extension.
			availableModules.addAll(rcpResolver.getAllModules().stream()
					.map(m -> m.replaceFirst((TLAConstants.Files.TLA_EXTENSION + "$"), ""))
					.collect(Collectors.toSet()));
		}
		final Set<String> includedModules = currentSpec.getValidRootModule().getModuleNames();
		
		final Set<String> unusedModules = availableModules.stream()
				.filter(m -> !includedModules.contains(m)).collect(Collectors.toSet());
		
		// Don't offer to extend  those modules which are already extended (implicitly).
		unusedModules.remove("Toolbox");
		unusedModules.remove("TLC");
		
		final ExtraModulesDialog extraModulesDialog = new ExtraModulesDialog(
				PlatformUI.getWorkbench().getDisplay().getActiveShell(), unusedModules,
				view.getModel().getTraceExplorerExtends());
		if (Window.OK == extraModulesDialog.open()) { 
			final Set<String> selectedModules = extraModulesDialog.getSelection();
			
			// Decouple I/O from UI thread.
	    	final Job job = new WorkspaceJob("Saving updated model...") {
				public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
					view.getModel().setTraceExplorerExtends(selectedModules);
					view.getModel().save(monitor);
					return Status.OK_STATUS;
				}
			};
			job.setRule(ResourcesPlugin.getWorkspace().getRoot());
			job.setUser(true);
			job.schedule();
		}
	}
}