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

The following examples show how to use org.eclipse.core.resources.WorkspaceJob. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
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
@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 3
@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 4
Source Project: google-cloud-eclipse   Source File: Activator.java    License: 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 5
protected void testCleanUpDerivedResourcesWithDeleteDerived(IContainer output) {
	File outputDirectory = output.getLocation().toFile();
	final int expectedSize;
	if (outputDirectory.exists()) {
		expectedSize = outputDirectory.list().length;
	} else {
		expectedSize = 0;
	}
	createFile(project.getFile(("src/Foo" + F_EXT)).getFullPath(), "object Foo");
	build();
	Assert.assertNotEquals(expectedSize, outputDirectory.list().length);
	disableAutobuild(() -> {
		IFile file = output.getFile(new Path("Foo.txt"));
		new WorkspaceJob("file.delete") {
			@Override
			public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
				Assert.assertTrue(file.getLocation().toFile().delete());
				Assert.assertFalse(isSynchronized(file));
				return Status.OK_STATUS;
			}
		}.run(monitor());
		cleanBuild();
		Assert.assertEquals(expectedSize, outputDirectory.list().length);
	});
}
 
Example 6
/**
 * 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 7
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 8
Source Project: gama   Source File: WorkspaceModelsManager.java    License: GNU General Public License v3.0 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) {
				// 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 9
Source Project: gama   Source File: RefreshAction.java    License: GNU General Public License v3.0 6 votes vote down vote up
@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 10
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 11
@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 12
@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 13
@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 14
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
  List<IProject> projects = ProjectFromSelectionHelper.getProjects(event);
  Preconditions.checkArgument(!projects.isEmpty());
  Job updateJob = new WorkspaceJob(Messages.getString("reconfiguringToJava8")) { // $NON-NLS-1$
        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
          SubMonitor progress = SubMonitor.convert(monitor, projects.size());
          for (IProject project : projects) {
            progress.subTask(
                Messages.getString("reconfiguringProject", project.getName())); // $NON-NLS-1$
            IFile appEngineWebXml =
                AppEngineConfigurationUtil.findConfigurationFile(project, APPENGINE_DESCRIPTOR);
            if (appEngineWebXml != null) {
              // add the <runtime> and the rest should be handled for us
              AppEngineDescriptorTransform.addJava8Runtime(appEngineWebXml);
            }
            progress.worked(1);
          }
          return Status.OK_STATUS;
        }

        @Override
        public boolean belongsTo(Object family) {
          return super.belongsTo(family)
              || J2EEElementChangedListener.PROJECT_COMPONENT_UPDATE_JOB_FAMILY.equals(family);
        }
      };
  updateJob.setRule(getWorkspaceRoot());
  updateJob.setUser(true);
  updateJob.schedule();
  return null;
}
 
Example 15
protected void testCleanUpDerivedResourcesWithUpdateDerived(IContainer output) {
	File outputDirectory = output.getLocation().toFile();
	final int expectedSize;
	if (outputDirectory.exists()) {
		expectedSize = outputDirectory.list().length;
	} else {
		expectedSize = 0;
	}
	createFile(project.getFile(("src/Foo" + F_EXT)).getFullPath(), "object Foo");
	build();
	Assert.assertNotEquals(expectedSize, outputDirectory.list().length);
	disableAutobuild(() -> {
		try {
			IFile file = output.getFile(new Path("Foo.txt"));
			file.setLocalTimeStamp(1L);
			new WorkspaceJob("file.setContent") {
				@Override
				public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
					setContent(file.getLocation().toFile(), "Lalala");
					Assert.assertFalse(isSynchronized(file));
					return Status.OK_STATUS;
				}
			}.run(monitor());
			cleanBuild();
			Assert.assertEquals(expectedSize, outputDirectory.list().length);
		} catch (CoreException e) {
			throw Exceptions.sneakyThrow(e);
		}
	});
}
 
Example 16
protected void testDeleteUpdatedDerivedResource(IContainer output) {
	try {
		File outputDirectory = output.getLocation().toFile();
		final int expectedSize;
		if (outputDirectory.exists()) {
			expectedSize = outputDirectory.list().length;
		} else {
			expectedSize = 0;
		}
		IFile sourceFile = createFile(project.getFile(("src/Foo" + F_EXT)).getFullPath(), "object Foo");
		build();
		Assert.assertNotEquals(expectedSize, outputDirectory.list().length);
		IFile file = output.getFile(new Path("Foo.txt"));
		file.setLocalTimeStamp(1L);
		new WorkspaceJob("file.setContent") {
			@Override
			public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
				setContent(file.getLocation().toFile(), "Lalala");
				Assert.assertFalse(isSynchronized(file));
				return Status.OK_STATUS;
			}
		}.run(monitor());
		sourceFile.delete(false, monitor());
		build();
		Assert.assertEquals(expectedSize, outputDirectory.list().length);
	} catch (CoreException e) {
		throw Exceptions.sneakyThrow(e);
	}
}
 
Example 17
protected void testDeleteDeletedDerivedResource(IContainer output) {
	try {
		File outputDirectory = output.getLocation().toFile();
		int expectedSize = 0;
		if (outputDirectory.exists()) {
			expectedSize = outputDirectory.list().length;
		}
		IFile sourceFile = createFile(project.getFile(("src/Foo" + F_EXT)).getFullPath(), "object Foo");
		build();
		Assert.assertNotEquals(expectedSize, outputDirectory.list().length);
		IFile file = output.getFile(new Path("Foo.txt"));
		file.refreshLocal(0, null);
		Assert.assertTrue(isSynchronized(file));
		new WorkspaceJob("file.delete") {
			@Override
			public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
				Assert.assertTrue(file.getLocation().toFile().delete());
				Assert.assertFalse(isSynchronized(file));
				return Status.OK_STATUS;
			}
		}.run(monitor());
		sourceFile.delete(false, monitor());
		build();
		Assert.assertEquals(expectedSize, outputDirectory.list().length);
	} catch (CoreException e) {
		throw Exceptions.sneakyThrow(e);
	}
}
 
Example 18
Source Project: xtext-eclipse   Source File: ListenerRegistrar.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void initialize() {
	workspace.addResourceChangeListener(listener);
	
	// If there are no open projects in a workspace after a restart, a newly opened Xtext project will
	// trigger the infrastructure's initialization procedure. Since the listeners are than registered
	// after the fact, the project-open event is already done. Thus no build is triggered for the newly
	// opened project and the index state is corrupt.
	// thus we trigger a recovery build here
	class RecoveryBuildTrigger extends WorkspaceJob {

		public RecoveryBuildTrigger() {
			super("Schedule Xtext recovery build on start-up");
		}

		@Override
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
			if (monitor.isCanceled()) {
				return Status.CANCEL_STATUS;
			}
			if (builderState.isEmpty()) {
				buildManager.scheduleBuildIfNecessary(Arrays.asList(workspace.getRoot().getProjects()), IBuildFlag.RECOVERY_BUILD);
			}
			return Status.OK_STATUS;
		}
	}
	RecoveryBuildTrigger recoveryBuildTrigger = new RecoveryBuildTrigger();
	recoveryBuildTrigger.schedule();
}
 
Example 19
Source Project: eclipse.jdt.ls   Source File: ProjectsManager.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@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 20
Source Project: eclipse.jdt.ls   Source File: JobHelpers.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public static void waitForWorkspaceJobsToComplete(IProgressMonitor monitor) throws InterruptedException {
	IJobManager jobManager = Job.getJobManager();
	jobManager.suspend();
	try {
		Job[] jobs = jobManager.find(null);
		for(int i = 0; i < jobs.length; i++ ) {
			if(jobs[i] instanceof WorkspaceJob || jobs[i].getClass().getName().endsWith("JREUpdateJob")) {
				jobs[i].join();
			}
		}
	} finally {
		jobManager.resume();
	}
}
 
Example 21
Source Project: eclipse.jdt.ls   Source File: SyntaxInitHandler.java    License: 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 22
Source Project: xds-ide   Source File: MarkerUtils.java    License: Eclipse Public License 1.0 5 votes vote down vote up
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 23
Source Project: spotbugs   Source File: MarkerUtil.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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 24
Source Project: tlaplus   Source File: NewTLAModuleCreationOperation.java    License: MIT License 5 votes vote down vote up
/**
 * Job factory
 * @param module
 * @return
 */
public static WorkspaceJob NEW_JOB(final IPath module)
{
    return new WorkspaceJob("Creating TLA+ file")
    {
        NewTLAModuleCreationOperation op = new NewTLAModuleCreationOperation(module);

        public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException
        {
            op.run(monitor);
            return Status.OK_STATUS;
        }
    };
    
}
 
Example 25
Source Project: tlaplus   Source File: Activator.java    License: 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 26
Source Project: tlaplus   Source File: TraceExplorerComposite.java    License: 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 27
Source Project: tlaplus   Source File: ModelEditor.java    License: MIT License 5 votes vote down vote up
/**
   * Invoke this to save the model via a workspace job.
   */
  public void saveModel() {
  	final Job job = new WorkspaceJob("Saving updated model...") {
	public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
		getModel().save(monitor);
		return Status.OK_STATUS;
	}
};
job.setRule(ResourcesPlugin.getWorkspace().getRoot());
job.setUser(true);
job.schedule();
  }
 
Example 28
/**
 * 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 29
protected void buttonPressed(int buttonId) {
	if (buttonId == 0) {
		StructuredSelection ss = (StructuredSelection)this.list.getSelection();
		IProject project = (IProject)ss.getFirstElement();
		Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
		if(validate(getID(project),project)){
			
		
		final SyncApplicationDialog sad = new SyncApplicationDialog(shell, aMobiles,iMobiles, project);
		final CountDownLatch threadSignal = new CountDownLatch(aMobiles.size()+iMobiles.size());
		sad.open();
		sad.run(threadSignal);
		Job job = new WorkspaceJob("")
		{
			@Override
			public IStatus runInWorkspace(IProgressMonitor monitor)
					throws CoreException {
				try {
					threadSignal.await();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				sad.finish();
				return Status.OK_STATUS;
			}
		};
		job.schedule();
		close();
	}else if (buttonId == 1) {
		close();
	}else{
		close();
	}
	} else{
		close();
	}
}
 
Example 30
Source Project: sarl   Source File: NewMavenSarlProjectWizard.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean performFinish() {
	if (!super.performFinish()) {
		return false;
	}
	final Job job = new WorkspaceJob("Force the SARL nature") { //$NON-NLS-1$
		@SuppressWarnings({ "deprecation", "synthetic-access" })
		@Override
		public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
			final Model model = NewMavenSarlProjectWizard.this.lastModel;
			if (model != null) {
				final Plugin plugin = Iterables.find(model.getBuild().getPlugins(), it -> PLUGIN_ARTIFACT_ID.equals(it.getArtifactId()));
				plugin.setExtensions(true);
				final IWorkspace workspace = ResourcesPlugin.getWorkspace();
				final IWorkspaceRoot root = workspace.getRoot();
				final IProject project = NewMavenSarlProjectWizard.this.importConfiguration.getProject(root, model);
				// Fixing the "extensions" within the pom file
				final IFile pomFile = project.getFile(IMavenConstants.POM_FILE_NAME);
				pomFile.delete(true, new NullProgressMonitor());
				MavenPlugin.getMavenModelManager().createMavenModel(pomFile, model);
				// Update the project
				final SubMonitor submon = SubMonitor.convert(monitor);
				MavenPlugin.getProjectConfigurationManager().updateProjectConfiguration(project, submon.newChild(1));
				project.refreshLocal(IResource.DEPTH_ONE, submon.newChild(1));
			}
			return Status.OK_STATUS;
		}
	};
	job.setRule(MavenPlugin.getProjectConfigurationManager().getRule());
	job.schedule();
	return true;
}