Java Code Examples for org.eclipse.core.resources.WorkspaceJob

The following are top voted examples for showing how to use org.eclipse.core.resources.WorkspaceJob. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: gw4e.project   File: ResourceManager.java   Source Code and License 7 votes vote down vote up
/**
 * @param folder
 * @param filetorefresh
 * @return
 * @throws CoreException
 * @throws InterruptedException
 */
public static IResource resfreshFileInContainer(IContainer folder, String filetorefresh)
		throws CoreException, InterruptedException {
	final IResource buildfile = find(folder, filetorefresh);
	Job job = new WorkspaceJob("Refresh folders") {
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
			if (buildfile != null && buildfile.exists()) {
				try {
					buildfile.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
				} catch (CoreException e) {
					ResourceManager.logException(e);
				}
			}
			return Status.OK_STATUS;
		}
	};
	job.setUser(true);
	job.schedule();

	return buildfile;
}
 
Example 2
Project: gw4e.project   File: ResourceManager.java   Source Code and License 7 votes vote down vote up
/**
 * @param file
 */
public static void updateBuildPolicyFileFor(IFile file) {
	Job job = new WorkspaceJob("Updating Build Policies from " + file.getName()) {
		@Override
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
			ICompilationUnit compilationUnit = JavaCore.createCompilationUnitFrom(file);
			if (compilationUnit != null) {
				if (JDTManager.isGraphWalkerExecutionContextClass(compilationUnit)) {
					updateBuildPolicyFileForCompilatioUnit(compilationUnit);
				}
			}
			return Status.OK_STATUS;
		}
	};
	job.setUser(true);
	job.setRule(file.getProject());
	job.schedule();
}
 
Example 3
Project: neoscada   File: DefinitionContributionItem.java   Source Code and License 6 votes vote down vote up
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 4
Project: gw4e.project   File: TestConvertor.java   Source Code and License 6 votes vote down vote up
public void apply() throws CoreException {
	Job job = new WorkspaceJob("GW4E Conversion Job") {
		@Override
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
			try {
				_apply(monitor);
			} catch (Exception e) {
				DialogManager.displayErrorMessage(MessageUtil.getString("project_conversion"), MessageUtil.getString("an_error_has_occured_while_configuring_the_project"), e);
				ResourceManager.logException(e);
			}
			return Status.OK_STATUS;
		}
	};
	job.setRule(testInterface.getJavaProject().getProject());
	job.setUser(true);
	job.schedule();
}
 
Example 5
Project: gw4e.project   File: BuildPolicyManager.java   Source Code and License 6 votes vote down vote up
/**
 * @param project
 * @param buildPolicyFile
 * @param graphFilePath
 * @param updatedGenerators
 * @throws IOException
 * @throws CoreException
 * @throws InterruptedException
 */
public static void update(IProject project, IFile buildPolicyFile, String graphFilePath,
		List<String> updatedGenerators) throws IOException, CoreException, InterruptedException {
	Job job = new WorkspaceJob("Updating policies") {
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
			try {
				_update(project, buildPolicyFile, graphFilePath, updatedGenerators, monitor);
			} catch (FileNotFoundException e) {
				ResourceManager.logException(e);
			}
			return Status.OK_STATUS;
		}
	};
	job.setRule(buildPolicyFile.getProject());
	job.setUser(true);
	job.schedule();
}
 
Example 6
Project: gemoc-studio   File: AbstractExampleWizard.java   Source Code and License 6 votes vote down vote up
public boolean performFinish() {
	final Collection<ProjectDescriptor> projectDescriptors = getProjectDescriptors();
	
	WorkspaceJob job = new WorkspaceJob("Unzipping Projects") {
		@Override
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
			monitor.beginTask("Unzipping Projects", projectDescriptors.size());
			//System.out.println("Unzipping projects...");
			for ( ProjectDescriptor desc : projectDescriptors ) {
				unzipProject(desc, monitor);
				monitor.worked(1);
			}
			//System.out.println("Projects unzipped");
			return Status.OK_STATUS;
		}
	};
	job.setRule(ResourcesPlugin.getWorkspace().getRoot());
	job.schedule();
	return true;
}
 
Example 7
Project: gemoc-studio   File: AbstractExampleWizard.java   Source Code and License 6 votes vote down vote up
public boolean performFinish() {
	final Collection<ProjectDescriptor> projectDescriptors = getProjectDescriptors();
	
	WorkspaceJob job = new WorkspaceJob("Unzipping Projects") {
		@Override
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
			monitor.beginTask("Unzipping Projects", projectDescriptors.size());
			//System.out.println("Unzipping projects...");
			for ( ProjectDescriptor desc : projectDescriptors ) {
				unzipProject(desc, monitor);
				monitor.worked(1);
			}
			//System.out.println("Projects unzipped");
			return Status.OK_STATUS;
		}
	};
	job.setRule(ResourcesPlugin.getWorkspace().getRoot());
	job.schedule();
	return true;
}
 
Example 8
Project: google-cloud-eclipse   File: UpdateCloudToolsEclipseProjectHandler.java   Source Code and License 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
  final IProject project = ProjectFromSelectionHelper.getFirstProject(event);
  if (!CloudToolsEclipseProjectUpdater.hasOldContainers(project)) {
    throw new ExecutionException(Messages.getString("project.appears.up.to.date")); //$NON-NLS-1$
  }
  Job updateJob = new WorkspaceJob(MessageFormat.format(Messages.getString("updating.project"), project.getName())) { //$NON-NLS-1$
    @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 9
Project: google-cloud-eclipse   File: CloudToolsEclipseProjectNotifier.java   Source Code and License 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 10
Project: eclipse.jdt.ls   File: DocumentLifeCycleHandler.java   Source Code and License 6 votes vote down vote up
public DocumentLifeCycleHandler(JavaClientConnection connection, PreferenceManager preferenceManager, ProjectsManager projectsManager, boolean delayValidation) {
	this.connection = connection;
	this.preferenceManager = preferenceManager;
	this.projectsManager = projectsManager;
	this.sharedASTProvider = SharedASTProvider.getInstance();
	if (delayValidation) {
		this.validationTimer = new WorkspaceJob("Validate documents") {
			@Override
			public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
				return performValidation(monitor);
			}

			/* (non-Javadoc)
			 * @see org.eclipse.core.runtime.jobs.Job#belongsTo(java.lang.Object)
			 */
			@Override
			public boolean belongsTo(Object family) {
				return DOCUMENT_LIFE_CYCLE_JOBS.equals(family);
			}
		};
		this.validationTimer.setRule(ResourcesPlugin.getWorkspace().getRoot());
	}
}
 
Example 11
Project: uefi_edk2_wizards_plugin   File: ProjectStructureUpdater.java   Source Code and License 6 votes vote down vote up
public static void setResourceChangeListeners(IProject newProjectHandle) {
	Edk2ModuleObservablesManager.getProjectModuleModificationObservable()
	.filter(event -> event.getProject() == newProjectHandle)
	.map(ev -> {
		return new WorkspaceJob("Updating project"){
			@Override 
			public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
				Edk2Module module = ev.getNewModule();

				updateIncludePaths(ev.getProject(), module);
				UpdateProjectStructureFromModuleDiff(ev.getProject(), ev.getOldModule(), module);
				ev.getProject().refreshLocal(IResource.DEPTH_INFINITE,monitor);

				return Status.OK_STATUS;
			}
		};
	})
	.subscribe(job -> job.schedule());
}
 
Example 12
Project: gwt-eclipse-plugin   File: BuilderUtilities.java   Source Code and License 6 votes vote down vote up
/**
 * 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 13
Project: gwt-eclipse-plugin   File: WebAppProjectCreator.java   Source Code and License 6 votes vote down vote up
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 14
Project: pep-tools   File: RefactoringSupport.java   Source Code and License 6 votes vote down vote up
public static void renameProduct(final IProductModel productModel, final String newId) {
	Job job = new WorkspaceJob("Renaming Product") {
		@Override
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
			productModel.getProduct().setId(newId);
			((IEditableModel) productModel).save();

			IResource productFile = productModel.getUnderlyingResource();
			productFile.move(getNewLocation(productFile, newId + ".product"), false, monitor);

			return Status.OK_STATUS;
		}
	};
	job.setRule(ResourcesPlugin.getWorkspace().getRoot());
	job.schedule();
}
 
Example 15
Project: pep-tools   File: RefactoringSupport.java   Source Code and License 6 votes vote down vote up
public static void internalRenamePlugin(final IPluginModelBase pluginModel, final String newName) {
	Job renamePluginJob = new WorkspaceJob("Renaming Plugin") {
		@Override
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
			// rename plugin
			setPluginId(pluginModel, newName);

			// update references
			String oldName = pluginModel.getPluginBase().getId();
			updatePluginReferences(oldName, newName);

			return Status.OK_STATUS;
		}
	};
	renamePluginJob.setRule(ResourcesPlugin.getWorkspace().getRoot());
	renamePluginJob.schedule();
}
 
Example 16
Project: pep-tools   File: RefactoringSupport.java   Source Code and License 6 votes vote down vote up
public static void internalRenameFeature(final IFeatureModel featureModel, final String newName) {
	Job renameFeatureJob = new WorkspaceJob("Renaming Feature") {
		@Override
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
			// update references
			String oldName = featureModel.getFeature().getId();
			updateFeatureReferences(oldName, newName);

			// rename feature
			featureModel.getFeature().setId(newName);
			((IEditableModel) featureModel).save();

			return Status.OK_STATUS;
		}
	};
	renameFeatureJob.setRule(ResourcesPlugin.getWorkspace().getRoot());
	renameFeatureJob.schedule();
}
 
Example 17
Project: pep-tools   File: RefactoringSupport.java   Source Code and License 6 votes vote down vote up
private static void renameProject(final IProject project, final String newName) {
	Job renameProjectJob = new WorkspaceJob("Renaming Project") {
		@Override
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
			IPath newLocation = getNewLocation(project, newName);

			// update linked resources
			updateLinkedResources(project, newName);

			// rename/move project
			IProjectDescription description = project.getDescription();
			description.setName(newName);

			if (newLocation != null) {
				description.setLocation(newLocation);
			}

			project.move(description, IResource.FORCE | IResource.SHALLOW, monitor);

			return Status.OK_STATUS;
		}
	};
	renameProjectJob.setRule(ResourcesPlugin.getWorkspace().getRoot());
	renameProjectJob.schedule();
}
 
Example 18
Project: gama   File: WorkspaceModelsManager.java   Source Code and License 6 votes vote down vote up
public static void linkSampleModelsToWorkspace() {

		final WorkspaceJob job = new WorkspaceJob("Updating the Built-in Models Library") {

			@Override
			public IStatus runInWorkspace(final IProgressMonitor monitor) {
				System.out.println("Asynchronous link of models library...");
				GAMA.getGui().refreshNavigator();
				return GamaBundleLoader.ERRORED ? Status.CANCEL_STATUS : Status.OK_STATUS;
			}

		};
		job.setUser(true);
		job.schedule();

	}
 
Example 19
Project: APICloud-Studio   File: SyncApplicationDialog.java   Source Code and License 6 votes vote down vote up
public void run(final CountDownLatch threadSignal) {
	for(Control c :composite.getChildren()) {
		if(c instanceof SyncApplicationComposite) {
			final SyncApplicationComposite sac = (SyncApplicationComposite)c;
			Job job = new WorkspaceJob("")
			{
				@Override
				public IStatus runInWorkspace(IProgressMonitor monitor)
						throws CoreException {
					try {
						sac.run(threadSignal);
					} catch (Exception e) {
						return Status.CANCEL_STATUS;
					}
					return Status.OK_STATUS;
				}
			};
			job.schedule();
		}
	}
	
}
 
Example 20
Project: APICloud-Studio   File: SyncSVNPathActionDelegate.java   Source Code and License 6 votes vote down vote up
@Override
public void run(IAction action) {
	Job job = new WorkspaceJob("refresh svn view")
	{
		@Override
		public IStatus runInWorkspace(IProgressMonitor monitor)
				throws CoreException {
			monitor.beginTask("refresh", 2);
			initData();
			monitor.worked(1);
			addSvnToView();
			monitor.worked(2);
			monitor.done();
			return Status.OK_STATUS;
		}
	};
	job.setPriority(Job.SHORT);
	job.setSystem(true);
	job.schedule(200L);
}
 
Example 21
Project: APICloud-Studio   File: AddSvnAndRefreshStartUp.java   Source Code and License 6 votes vote down vote up
@Override
public void earlyStartup() {
	Job job = new WorkspaceJob("refresh svn view")
	{
		@Override
		public IStatus runInWorkspace(IProgressMonitor monitor)
				throws CoreException {
			monitor.beginTask("refresh", 4);
			initData();
			monitor.worked(1);
			saveFeatureInfo(ip, userName, cookie);
			monitor.worked(1);
			addSvnToView(ip, userName, cookie);
			monitor.worked(1);
			monitor.done();
			return Status.OK_STATUS;
		}
	};
	job.setPriority(Job.SHORT);
	job.setSystem(true);
	job.schedule(200L);
}
 
Example 22
Project: cmake-eclipse-helper   File: CMakeLauncher.java   Source Code and License 6 votes vote down vote up
public void setupProject(final IProject project) {
	WorkspaceJob job = new WorkspaceJob("Setup CMakeProject " + project) {
		@Override
		public IStatus runInWorkspace(IProgressMonitor monitor)
				throws CoreException {
			try {
				doSetupProject(project, monitor);
				return Status.OK_STATUS;
			} catch (IOException e) {
				e.printStackTrace();
				return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unable to setup Project " + e.getLocalizedMessage());
			}
		}
	};
	job.schedule();
}
 
Example 23
Project: cmake-eclipse-helper   File: CMakeLauncher.java   Source Code and License 6 votes vote down vote up
public void changeArchitecture(final IProject project, final String architecture) throws CoreException {
	WorkspaceJob job = new WorkspaceJob("Change Architecture of CMakeProject " + project) {
		@Override
		public IStatus runInWorkspace(IProgressMonitor monitor)
				throws CoreException {
			try {
				doChangeArchitecture(project, architecture, monitor);
				return Status.OK_STATUS;
			} catch (IOException e) {
				e.printStackTrace();
				return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unable to change architecture of Project " + e.getLocalizedMessage());
			}
		}
	};
	job.schedule();
}
 
Example 24
Project: cmake-eclipse-helper   File: CMakeLauncher.java   Source Code and License 6 votes vote down vote up
public void changeBuildType(final IProject project, final String buildType) throws CoreException {
	WorkspaceJob job = new WorkspaceJob("Change Build-Type of CMakeProject " + project) {
		@Override
		public IStatus runInWorkspace(IProgressMonitor monitor)
				throws CoreException {
			try {
				doChangeBuildType(project, buildType, monitor);
				return Status.OK_STATUS;
			} catch (IOException e) {
				e.printStackTrace();
				return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unable to change build type of Project " + e.getLocalizedMessage());
			}
		}
	};
	job.schedule();
}
 
Example 25
Project: cmake-eclipse-helper   File: CMakeTouchDeltaVisitor.java   Source Code and License 6 votes vote down vote up
public void postProcess() {
	WorkspaceJob job = new WorkspaceJob("Update derived sub-files") {
		
		@Override
		public IStatus runInWorkspace(IProgressMonitor monitor)
				throws CoreException {
			
			for(IFile file : toTouch) {
				// FIXME: Check if there is a more lightweight method to achieve good touching
				Activator.logInfo("touch " + file);
				try {
					CharSequence sequence = FileContentIO.readFileContent(file);
					FileContentIO.writeFileContent(file, sequence, monitor);
				} catch(Exception ce) {
					ce.printStackTrace();
				}
			}
			return Status.OK_STATUS;
		}
	};
	job.schedule();
}
 
Example 26
Project: cmake-eclipse-helper   File: CMakeWizard.java   Source Code and License 6 votes vote down vote up
@Override
public boolean performFinish() {
	final IProject project = createNewProject();
	if (mainPage != null) {
		final DirectoryEntry choice = mainPage.getChoice();

		WorkspaceJob job = new WorkspaceJob("Extract template for " + project) {
			@Override
			public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
				extract(project, choice);
				if (!project.hasNature(CMakeNature.ID)) {
					new CMakeLauncher().setupProject(project);
				}
				return Status.OK_STATUS;
			}
		};
		job.schedule();
	}
	return true;
}
 
Example 27
Project: thym   File: ConvertToHybridProjectHandler.java   Source Code and License 6 votes vote down vote up
@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 28
Project: Environment   File: CloudScaleProjectWizard.java   Source Code and License 6 votes vote down vote up
@Override
public boolean performFinish() {

	final boolean b = super.performFinish();

	WorkspaceJob job = new WorkspaceJob("Configuring Cloudscale project") {
		
		@Override
		public IStatus runInWorkspace(IProgressMonitor arg0) throws CoreException {
			if (b && getNewProject() != null) {
				IProject p = getNewProject();
				CloudScaleProjectSupport.createDefaultProject(p);
			}
			
			return Status.OK_STATUS;
		}
	};
	
	job.setUser(true);
	job.schedule();

	return b;
}
 
Example 29
Project: Environment   File: ToolchainAddon.java   Source Code and License 6 votes vote down vote up
@PostConstruct
public void postConstruct(IEclipseContext context){
	//put dummy object at initialization
	
	context.declareModifiable(IActiveResources.class);
	context.modify(IActiveResources.class, new ActiveResources());
	
	//initialize project resources
	WorkspaceJob resourceInitJob = new WorkspaceJob("Cloudscale resources initialization") {
		
		@Override
		public IStatus runInWorkspace(IProgressMonitor arg0) throws CoreException {
			try{
				ResourceRegistry.getInstance().initialize();
			}
			catch(Exception e){
				e.printStackTrace();
				return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage());
			}
			return Status.OK_STATUS;
		}
	};
	
	resourceInitJob.schedule(3000);
}
 
Example 30
Project: jkind-xtext   File: RunJRealizabilityHandler.java   Source Code and License 6 votes vote down vote up
private void activateTerminateHandler(final IProgressMonitor monitor, final WorkspaceJob job) {
	final IHandlerService handlerService = (IHandlerService) window
			.getService(IHandlerService.class);
	window.getShell().getDisplay().syncExec(new Runnable() {
		@Override
		public void run() {
			final IHandlerActivation activation = handlerService.activateHandler(TERMINATE_ID,
					new TerminateHandler(monitor));
			job.addJobChangeListener(new JobChangeAdapter() {
				@Override
				public void done(IJobChangeEvent event) {
					window.getShell().getDisplay().syncExec(new Runnable() {
						@Override
						public void run() {
							handlerService.deactivateHandler(activation);
						}
					});
				}
			});
		}
	});
}
 
Example 31
Project: jkind-xtext   File: RunJKindHandler.java   Source Code and License 6 votes vote down vote up
private void activateTerminateHandler(final IProgressMonitor monitor, final WorkspaceJob job) {
	final IHandlerService handlerService = (IHandlerService) window
			.getService(IHandlerService.class);
	window.getShell().getDisplay().syncExec(new Runnable() {
		@Override
		public void run() {
			final IHandlerActivation activation = handlerService.activateHandler(TERMINATE_ID,
					new TerminateHandler(monitor));
			job.addJobChangeListener(new JobChangeAdapter() {
				@Override
				public void done(IJobChangeEvent event) {
					window.getShell().getDisplay().syncExec(new Runnable() {
						@Override
						public void run() {
							handlerService.deactivateHandler(activation);
						}
					});
				}
			});
		}
	});
}
 
Example 32
Project: q7.quality.mockups   File: NestedDialog.java   Source Code and License 6 votes vote down vote up
Builder workspaceJob() {
	final Runnable temp = this;
	return new Builder() {
		@Override
		public void run() {
			new WorkspaceJob("meh") {
				
				@Override
				public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
					temp.run();
					return Status.OK_STATUS;
				}
			}.schedule();
		}
	};
}
 
Example 33
Project: k3   File: AbstractExampleWizard.java   Source Code and License 6 votes vote down vote up
public boolean performFinish() {
	final Collection<ProjectDescriptor> projectDescriptors = getProjectDescriptors();
	
	WorkspaceJob job = new WorkspaceJob("Unzipping Projects") {
		@Override
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
			monitor.beginTask("Unzipping Projects", projectDescriptors.size());
			//System.out.println("Unzipping projects...");
			for ( ProjectDescriptor desc : projectDescriptors ) {
				unzipProject(desc, monitor);
				monitor.worked(1);
			}
			//System.out.println("Projects unzipped");
			return Status.OK_STATUS;
		}
	};
	job.setRule(ResourcesPlugin.getWorkspace().getRoot());
	job.schedule();
	return true;
}
 
Example 34
Project: kompren   File: AbstractExampleWizard.java   Source Code and License 6 votes vote down vote up
public boolean performFinish() {
	final Collection<ProjectDescriptor> projectDescriptors = getProjectDescriptors();
	
	WorkspaceJob job = new WorkspaceJob("Unzipping Projects") {
		@Override
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
			monitor.beginTask("Unzipping Projects", projectDescriptors.size());
			//System.out.println("Unzipping projects...");
			for ( ProjectDescriptor desc : projectDescriptors ) {
				unzipProject(desc, monitor);
				monitor.worked(1);
			}
			//System.out.println("Projects unzipped");
			return Status.OK_STATUS;
		}
	};
	job.setRule(ResourcesPlugin.getWorkspace().getRoot());
	job.schedule();
	return true;
}
 
Example 35
Project: smaccm   File: NoElementHandler.java   Source Code and License 6 votes vote down vote up
public Object executeURI() {
	// 3/30/2016 MWW: This check is unnecessary for NoElement handlers.
	/*		
	 final XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor();
	if (xtextEditor == null) {
		return null;
	}
	*/
	
	if (!saveChanges(window.getActivePage().getDirtyEditors())) {
		return null;
	}

	WorkspaceJob job = new WorkspaceJob(getJobName()) {
		@Override
		public IStatus runInWorkspace(final IProgressMonitor monitor) {
			return runJob(monitor);
		}
	};

	job.setRule(ResourcesPlugin.getWorkspace().getRoot());
	job.schedule();
	return null;
}
 
Example 36
Project: gw4e.project   File: ResourceManager.java   Source Code and License 5 votes vote down vote up
/**
 * Touch the files located in the folder of the passed file
 * 
 * @param file
 */
public static void touchFolderForRebuild(final IFile file) {
	Job job = new WorkspaceJob("Touch folders") {
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
			ResourceManager.touchFolderResources(file);
			return Status.OK_STATUS;
		}
	};
	job.schedule();
}
 
Example 37
Project: gw4e.project   File: SettingsManager.java   Source Code and License 5 votes vote down vote up
/**
 * Return the the preference values for the passed project and key
 * 
 * @param project
 * @param key
 * @return
 */
public static String[] getValues(IProject project, String key, boolean projectScoped) {

	IEclipsePreferences projectPreferences = null;
	if (projectScoped) {
		projectPreferences = getProjectPreference(project);
	} else {
		projectPreferences = getGlobalPreference();
	}
	String values = projectPreferences.get(key, "");
	if ((values == null) || (values.trim().length() == 0) && projectScoped) {
		IEclipsePreferences globalPreferences = getGlobalPreference();
		values = globalPreferences.get(key, "");
		final String gloablValues = values;

		Job job = new WorkspaceJob("GW4E Configure Project Preference Job") {
			@Override
			public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
				SubMonitor subMonitor = SubMonitor.convert(monitor, 60);
				try {
					putValues(project, key, fromString(gloablValues), projectScoped);
					return Status.OK_STATUS;
				} catch (Exception e) {
					ResourceManager.logException(e);
					return Status.CANCEL_STATUS;
				} finally {
					subMonitor.done();
				}
			}
		};
		job.setRule(project);
		job.setUser(true);
		job.schedule();
	}
	String[] ret = fromString(values);
	return ret;
}
 
Example 38
Project: gw4e.project   File: BuildPoliciesCache.java   Source Code and License 5 votes vote down vote up
/**
 * @param graphFile
 * @throws CoreException
 * @throws IOException
 * @throws InterruptedException
 */
public void update(List<BuildPolicy> policies) throws CoreException, IOException, InterruptedException {
	Job job = new WorkspaceJob("Updating cache") {
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
			try {
				IFile fileCache = getCache();
				Properties p = ResourceManager.loadIFileAsProperties(fileCache,
						getFileCacheName(resource.getProject().getName()));
				String serialized = serialize(policies);
				if (serialized == null) {
					log("BuildPoliciesCache.update " + fileCache + " failed to updated for resource " + resource
							+ " " + policies.toString());
					return Status.OK_STATUS;
				}
				p.put(resource.getName(), System.currentTimeMillis() + ":" + serialized);
				log("BuildPoliciesCache.update " + fileCache + " updated for resource " + resource + " "
						+ p.toString());
				save(p, monitor);
				return Status.OK_STATUS;
			} catch (Exception e) {
				ResourceManager.logException(e);
				return Status.CANCEL_STATUS;
			}
		}
	};
	job.setRule(resource.getProject());
	job.setUser(true);
	job.schedule();
}
 
Example 39
Project: gw4e.project   File: SetSyncPoliciesForFileMarkerResolution.java   Source Code and License 5 votes vote down vote up
@Override
public void run(IMarker marker) {
	Job job = new WorkspaceJob("GW4E QuickFix Job") {
		@Override
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
			fix(marker, monitor);
			return Status.OK_STATUS;
		}
	};

	job.setRule(marker.getResource().getProject());
	job.setUser(true);
	job.schedule();
}
 
Example 40
Project: gw4e.project   File: AbstractBuildPoliciesMarkerResolution.java   Source Code and License 5 votes vote down vote up
@Override
public void run(IMarker marker) {
	Job job = new WorkspaceJob("GW4E Fix Job") {
		@Override
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
			fix(marker, monitor);
			return Status.OK_STATUS;
		}
	};
	job.setRule(marker.getResource().getProject());
	job.setUser(true);
	job.schedule();
}