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

The following examples show how to use org.eclipse.core.resources.IWorkspaceRunnable. 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
Source Project: ADT_Frontend   Source File: TestsPdeAbapGitStagingUtil.java    License: MIT License 6 votes vote down vote up
protected IProject createDummyAbapProject(String projectName) throws CoreException{
	String destinationId = projectName;
	
	IDestinationDataWritable data = AdtDestinationDataFactory.newDestinationData(destinationId);
	data.setUser("TEST_DUMMY_USER"); 
	data.setClient("777"); 
	data.setLanguage("DE"); 
	data.setPassword("TEST_DUMMY_PW"); 
	
	String projectDestinationId = AdtProjectServiceFactory.createProjectService().createDestinationId(projectName);
	final IDestinationData destinationData = data.getReadOnlyClone(projectDestinationId);
	
	final IAbapProjectService abapProjectService = AdtProjectServiceFactory.createProjectService();
	//IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	final AbapProject[] projects = new AbapProject[1];
	workspace.run(new IWorkspaceRunnable() {
		@Override
		public void run(IProgressMonitor monitor) throws CoreException {
			projects[0] = (AbapProject) abapProjectService.createAbapProject(projectName, destinationData, monitor);
		}
	}, new NullProgressMonitor());
	return projects[0].getProject();
}
 
Example 2
Source Project: ADT_Frontend   Source File: TestsPdeAbapGitRepositoriesUtil.java    License: MIT License 6 votes vote down vote up
protected IProject createDummyAbapProject() throws CoreException{
	String projectName = "ABAPGIT_TEST_PROJECT";
	String destinationId = "ABAPGIT_TEST_PROJECT";
	
	IDestinationDataWritable data = AdtDestinationDataFactory.newDestinationData(destinationId);
	data.setUser("TEST_DUMMY_USER"); 
	data.setClient("777"); 
	data.setLanguage("DE"); 
	data.setPassword("TEST_DUMMY_PW"); 
	
	String projectDestinationId = AdtProjectServiceFactory.createProjectService().createDestinationId(projectName);
	final IDestinationData destinationData = data.getReadOnlyClone(projectDestinationId);
	
	final IAbapProjectService abapProjectService = AdtProjectServiceFactory.createProjectService();
	//IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	final AbapProject[] projects = new AbapProject[1];
	workspace.run(new IWorkspaceRunnable() {
		@Override
		public void run(IProgressMonitor monitor) throws CoreException {
			projects[0] = (AbapProject) abapProjectService.createAbapProject(projectName, destinationData, monitor);
		}
	}, new NullProgressMonitor());
	return projects[0].getProject();
}
 
Example 3
Source Project: xtext-eclipse   Source File: SaveHelper.java    License: Eclipse Public License 2.0 6 votes vote down vote up
public void saveEditors(final IRenameElementContext context) {
	new DisplayRunnable() {
		@Override
		protected void run() throws Exception {
			workspace.run(new IWorkspaceRunnable() {
				@Override
				public void run(IProgressMonitor monitor) throws CoreException {
					IWorkbenchPage workbenchPage = getWorkbenchPage(context);
					if (prefs.isSaveAllBeforeRefactoring()) 
						workbenchPage.saveAllEditors(false);
					else
						saveDeclaringEditor(context, workbenchPage);
				}
			}, new NullProgressMonitor());
		}
	}.syncExec();
	syncUtil.waitForBuild(null);
}
 
Example 4
private void doInitializeCache() throws CoreException {
	if(!isInitialized) {
		IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
			@Override
			public void run(IProgressMonitor monitor) throws CoreException {
				if(!isInitialized) {
					for(IProject project: workspace.getRoot().getProjects()) {
						if(project.isAccessible() && JavaProject.hasJavaNature(project)) {
							IJavaProject javaProject = JavaCore.create(project);
							updateCache(javaProject);
						}
					}
					isInitialized = true;
				}
			}
		};
		// while the tree is locked, workspace.run may not be used but we are sure that we do already
		// hold the workspace lock - save to just run the action code
		if (workspace.isTreeLocked()) {
			runnable.run(null);
		} else {
			workspace.run(runnable, null, IWorkspace.AVOID_UPDATE, null);
		}
	}
}
 
Example 5
Source Project: eclipse.jdt.ls   Source File: DiagnosticsCommand.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private static void refreshDiagnostics(final ICompilationUnit target) {
	final JavaClientConnection connection = JavaLanguageServerPlugin.getInstance().getClientConnection();
	if (connection == null) {
		JavaLanguageServerPlugin.logError("The client connection doesn't exist.");
		return;
	}

	try {
		ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
			@Override
			public void run(IProgressMonitor monitor) throws CoreException {
				List<ICompilationUnit> units = getNonProjectCompilationUnits(target, monitor);
				for (ICompilationUnit unit : units) {
					publishDiagnostics(connection, unit, monitor);
				}
			}
		}, new NullProgressMonitor());
	} catch (CoreException e) {
		JavaLanguageServerPlugin.logException("Refresh Diagnostics for non-project Java files", e);
	}
}
 
Example 6
protected List<IProject> importProjects(Collection<String> paths, boolean deleteExistingFiles) throws Exception {
	final List<IPath> roots = new ArrayList<>();
	for (String path : paths) {
		File file = copyFiles(path, deleteExistingFiles);
		roots.add(Path.fromOSString(file.getAbsolutePath()));
	}
	IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
		@Override
		public void run(IProgressMonitor monitor) throws CoreException {
			projectsManager.initializeProjects(roots, monitor);
		}
	};
	JavaCore.run(runnable, null, monitor);
	JobHelpers.waitForWorkspaceJobsToComplete(monitor);
	return Arrays.asList(ProjectUtils.getAllProjects());
}
 
Example 7
protected IProject importRootFolder(IPath rootPath, String triggerFile) throws Exception {
	if (StringUtils.isNotBlank(triggerFile)) {
		IPath triggerFilePath = rootPath.append(triggerFile);
		Preferences preferences = preferenceManager.getPreferences();
		preferences.setTriggerFiles(Arrays.asList(triggerFilePath));
	}
	final List<IPath> roots = Arrays.asList(rootPath);
	IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
		@Override
		public void run(IProgressMonitor monitor) throws CoreException {
			projectsManager.initializeProjects(roots, monitor);
		}
	};
	JavaCore.run(runnable, null, monitor);
	waitForBackgroundJobs();
	String invisibleProjectName = ProjectUtils.getWorkspaceInvisibleProjectName(rootPath);
	return ResourcesPlugin.getWorkspace().getRoot().getProject(invisibleProjectName);
}
 
Example 8
protected List<IProject> importProjects(Collection<String> paths, boolean deleteExistingFiles) throws Exception {
	final List<IPath> roots = new ArrayList<>();
	for (String path : paths) {
		File file = copyFiles(path, deleteExistingFiles);
		roots.add(Path.fromOSString(file.getAbsolutePath()));
	}
	IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
		@Override
		public void run(IProgressMonitor monitor) throws CoreException {
			projectsManager.initializeProjects(roots, monitor);
		}
	};
	JavaCore.run(runnable, null, monitor);
	waitForBackgroundJobs();
	return WorkspaceHelper.getAllProjects();
}
 
Example 9
Source Project: gef   Source File: DotGraphView.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private IWorkspaceRunnable updateGraphRunnable(final File f) {
	if (!listenToDotContent
			&& !hasDotFileExtension(f.getAbsolutePath().toString())) {
		return null;
	}
	IWorkspaceRunnable workspaceRunnable = new IWorkspaceRunnable() {
		@Override
		public void run(final IProgressMonitor monitor)
				throws CoreException {
			if (updateGraph(f)) {
				currentFile = f;
			}
		}
	};
	return workspaceRunnable;
}
 
Example 10
/**
 * Removes all files in the project and sets the given classpath
 *
 * @param jproject
 *            The project to clear
 * @param entries
 *            The default class path to set
 * @throws CoreException
 *             Clearing the project failed
 */
public static void clear(final IJavaProject jproject, final IClasspathEntry[] entries) throws CoreException {
    performDummySearch();

    IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            jproject.setRawClasspath(entries, null);

            IResource[] resources = jproject.getProject().members();
            for (int i = 0; i < resources.length; i++) {
                if (!resources[i].getName().startsWith(".")) {
                    resources[i].delete(true, null);
                }
            }
        }
    };
    ResourcesPlugin.getWorkspace().run(runnable, null);
}
 
Example 11
Source Project: tlaplus   Source File: FileProcessOutputSink.java    License: MIT License 6 votes vote down vote up
public synchronized void appendText(final String text)
{
    try
    {
        ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
            public void run(IProgressMonitor monitor) throws CoreException
            {
                // System.out.print(Thread.currentThread().getId() + " : " + message);
                outFile.appendContents(new ByteArrayInputStream(text.getBytes()), IResource.FORCE, monitor);
            }
        }, rule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());

        // if the console output is active, print to it
    } catch (CoreException e)
    {
        TLCActivator.logError("Error writing the TLC process output file for " + model.getName(), e);
    }

}
 
Example 12
/**
   * Set the selection and focus to the list of elements
   * @param elements the object to be selected and displayed
   */
  public void setSelection(final List<?> elements) {
      if (elements == null || elements.size() == 0)
          return;
try {
       ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
       	public void run(IProgressMonitor monitor) throws CoreException {
       		fPackageViewer.refresh();
               IStructuredSelection selection= new StructuredSelection(elements);
               fPackageViewer.setSelection(selection, true);
               fPackageViewer.getTree().setFocus();

               if (elements.size() == 1 && elements.get(0) instanceof IJavaProject)
                   fPackageViewer.expandToLevel(elements.get(0), 1);
           }
       }, ResourcesPlugin.getWorkspace().getRoot(), IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
      } catch (CoreException e) {
       JavaPlugin.log(e);
      }
  }
 
Example 13
Source Project: thym   Source File: HybridMobileEngineTests.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testRemoveEngineUsingName() throws CoreException {
	final HybridMobileEngine[] engines = new HybridMobileEngine[2];
	engines[0] = new HybridMobileEngine("android", "6.0.0", null);
	engines[1] = new HybridMobileEngine("ios", "4.4.0", null);
	manager.updateEngines(engines);
	JobUtils.waitForIdle();

	// Run on a IWorkspaceRunnable because it needs to sync with the udpateEngines
	// call.
	IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

		@Override
		public void run(IProgressMonitor monitor) throws CoreException {
			manager.removeEngine(engines[0].getName(), monitor, true);
			Widget w = WidgetModel.getModel(testproject.hybridProject()).getWidgetForRead();
			assertEquals(1, w.getEngines().size());
			assertEquals(1, manager.getEngines().length);
			checkEnginesPersistedCorrectly(new HybridMobileEngine[] { engines[1] });
		}
	};
	IWorkspace ws = ResourcesPlugin.getWorkspace();
	ISchedulingRule rule = ws.getRuleFactory().modifyRule(testproject.getProject());
	ws.run(runnable, rule, 0, new NullProgressMonitor());
}
 
Example 14
Source Project: thym   Source File: HybridMobileEngineTests.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testRemoveEngine() throws CoreException {
	final HybridMobileEngine[] engines = new HybridMobileEngine[2];
	engines[0] = new HybridMobileEngine("android", "6.0.0", null);
	engines[1] = new HybridMobileEngine("ios", "4.4.0", null);
	manager.updateEngines(engines);
	JobUtils.waitForIdle();

	// Run on a IWorkspaceRunnable because it needs to sync with the udpateEngines
	// call.
	IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

		@Override
		public void run(IProgressMonitor monitor) throws CoreException {
			manager.removeEngine(engines[0], monitor, true);
			Widget w = WidgetModel.getModel(testproject.hybridProject()).getWidgetForRead();
			assertEquals(1, w.getEngines().size());
			checkEnginesPersistedCorrectly(new HybridMobileEngine[] { engines[1] });
		}
	};
	IWorkspace ws = ResourcesPlugin.getWorkspace();
	ISchedulingRule rule = ws.getRuleFactory().modifyRule(testproject.getProject());
	ws.run(runnable, rule, 0, new NullProgressMonitor());
}
 
Example 15
Source Project: Pydev   Source File: PythonBreakpointPage.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Store the breakpoint properties.
 * @see org.eclipse.jface.preference.IPreferencePage#performOk()
 */
@Override
public boolean performOk() {
    IWorkspaceRunnable wr = new IWorkspaceRunnable() {
        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            PyBreakpoint breakpoint = getBreakpoint();
            boolean delOnCancel = breakpoint.getMarker().getAttribute(ATTR_DELETE_ON_CANCEL) != null;
            if (delOnCancel) {
                // if this breakpoint is being created, remove the "delete on cancel" attribute
                // and register with the breakpoint manager
                breakpoint.getMarker().setAttribute(ATTR_DELETE_ON_CANCEL, (String) null);
                breakpoint.setRegistered(true);
            }
            doStore();
        }
    };
    try {
        ResourcesPlugin.getWorkspace().run(wr, null, 0, null);
    } catch (CoreException e) {
        PydevDebugPlugin.errorDialog("An exception occurred while saving breakpoint properties.", e); //$NON-NLS-1$
        PydevDebugPlugin.log(IStatus.ERROR, e.getLocalizedMessage(), e);
    }
    return super.performOk();
}
 
Example 16
Source Project: goclipse   Source File: LangProjectWizardTest.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@After
public void tearDown() throws Exception {
	// Should undo all wizard actions
	ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
		@Override
		public void run(IProgressMonitor monitor) throws CoreException {
			IProject project = EclipseUtils.getWorkspaceRoot().getProject(NEWPROJNAME);
			if(project.exists()) {
				project.delete(true, monitor);
			}
		}
	}, null);
	
	if(wizDialog != null) {
		wizDialog.close();
	}
}
 
Example 17
Source Project: goclipse   Source File: ToolMarkersHelper.java    License: Eclipse Public License 1.0 6 votes vote down vote up
public void doAddErrorMarkers(Iterable<ToolSourceMessage> buildErrors, Location rootPath, IProgressMonitor pm)
		throws CoreException {
	documents.clear();
	
	ResourceUtils.getWorkspace().run(new IWorkspaceRunnable() {
		@Override
		public void run(IProgressMonitor monitor) throws CoreException {
			for(ToolSourceMessage buildError : buildErrors) {
				if(pm.isCanceled()) {
					return;
				}
				addErrorMarkers(buildError, rootPath);
			}
		}
	}, ResourceUtils.getWorkspaceRoot(), IWorkspace.AVOID_UPDATE, pm);
}
 
Example 18
Source Project: goclipse   Source File: ProblemMarkerUpdater.java    License: Eclipse Public License 1.0 6 votes vote down vote up
protected void updateProblemMarkers() throws CoreException {
	// Review if this can run outside lock
	IFile[] files = ResourceUtils.getWorkspaceRoot().findFilesForLocationURI(location.toUri());
	if(files.length == 0) {
		return;
	}
	
	final IFile file = files[0];
	
	ResourceUtils.getWorkspace().run(new IWorkspaceRunnable() {
		@Override
		public void run(IProgressMonitor monitor) throws CoreException {
			try {
				doCreateProblemMarkers(file);
			} catch(OperationCancellation e) {
				return;
			}
		}
	}, file, IWorkspace.AVOID_UPDATE, null);
}
 
Example 19
Source Project: goclipse   Source File: ResourceUtils.java    License: Eclipse Public License 1.0 6 votes vote down vote up
public static void connectResourceListener(IResourceChangeListener listener, 
		RunnableX<CoreException> initialUpdate, ISchedulingRule opRule, IOwner owner) {
	try {
		getWorkspace().run(new IWorkspaceRunnable() {
			@Override
			public void run(IProgressMonitor monitor) throws CoreException {
				getWorkspace().addResourceChangeListener(listener, IResourceChangeEvent.POST_CHANGE);
				initialUpdate.run();
			}
		}, opRule, IWorkspace.AVOID_UPDATE, null);
		
	} catch (CoreException ce) {
		EclipseCore.logStatus(ce);
		// This really should not happen, but still try to recover by registering the listener.
		getWorkspace().addResourceChangeListener(listener, IResourceChangeEvent.POST_CHANGE);
	}
	owner.bind(() -> ResourcesPlugin.getWorkspace().removeResourceChangeListener(listener));
}
 
Example 20
protected IWorkspaceRunnable handlePoolRemoved(final ProcessConfigurationRepositoryStore processConfStore,
        final DiagramRepositoryStore diagramStore) {
    return new IWorkspaceRunnable() {

        @Override
        public void run(final IProgressMonitor arg0) throws CoreException {
            final Set<String> poolIds = diagramStore.getAllProcessIds();
            for (final IRepositoryFileStore file : processConfStore.getChildren()) {
                String id = file.getName();
                id = id.substring(0, id.lastIndexOf("."));
                if (!poolIds.contains(id)) {
                    file.delete();
                }
            }
        }
    };

}
 
Example 21
public void load() {
	if (!isLoaded) {
		IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
			@Override
			public void run(IProgressMonitor monitor) throws CoreException {
				if (!isLoaded) {
					resourceDescriptionData = new ResourceDescriptionsData(persister.load());
					if(storage2UriMapper instanceof IStorage2UriMapperExtension)
						((IStorage2UriMapperExtension) storage2UriMapper).initializeCache();
					isLoaded = true;
				}
			}
		};
		try {
			switch(workspaceLockAccess.isWorkspaceLockedByCurrentThread(workspace)) {
				case YES: {
					runnable.run(null);
					break;
				}
				case NO: {
					workspace.run(runnable, null, IWorkspace.AVOID_UPDATE, null);
					break;
				}
				case SHUTDOWN: {
					// do not initialize anything if we are about to shutdown.
					return;
				}
			}
		} catch(CoreException e) {
			log.error(e.getMessage(), e);
		}
	}
}
 
Example 22
Source Project: eclipse.jdt.ls   Source File: ProjectCommand.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Gets the classpaths and modulepaths.
 *
 * @param uri
 *                    Uri of the source/class file that needs to be queried.
 * @param options
 *                    Query options.
 * @return <code>ClasspathResult</code> containing both classpaths and
 *         modulepaths.
 * @throws CoreException
 * @throws URISyntaxException
 */
public static ClasspathResult getClasspaths(String uri, ClasspathOptions options) throws CoreException, URISyntaxException {
	IJavaProject javaProject = getJavaProjectFromUri(uri);
	Optional<IBuildSupport> bs = JavaLanguageServerPlugin.getProjectsManager().getBuildSupport(javaProject.getProject());
	if (!bs.isPresent()) {
		throw new CoreException(new Status(IStatus.ERROR, IConstants.PLUGIN_ID, "No BuildSupport for the project: " + javaProject.getElementName()));
	}
	ILaunchConfiguration launchConfig = bs.get().getLaunchConfiguration(javaProject, options.scope);
	JavaLaunchDelegate delegate = new JavaLaunchDelegate();
	ClasspathResult[] result = new ClasspathResult[1];

	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	ISchedulingRule currentRule = Job.getJobManager().currentRule();
	ISchedulingRule schedulingRule;
	if (currentRule != null && currentRule.contains(javaProject.getSchedulingRule())) {
		schedulingRule = null;
	} else {
		schedulingRule = javaProject.getSchedulingRule();
	}
	workspace.run(new IWorkspaceRunnable() {
		@Override
		public void run(IProgressMonitor monitor) throws CoreException {
			String[][] paths = delegate.getClasspathAndModulepath(launchConfig);
			result[0] = new ClasspathResult(javaProject.getProject().getLocationURI(), paths[0], paths[1]);
		}
	}, schedulingRule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());

	if (result[0] != null) {
		return result[0];
	}

	throw new CoreException(new Status(IStatus.ERROR, IConstants.PLUGIN_ID, "Failed to get the classpaths."));
}
 
Example 23
@Override
public Change perform(IProgressMonitor pm) throws CoreException {
	final Change[] result = new Change[1];
	IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
		@Override
		public void run(IProgressMonitor monitor) throws CoreException {
			result[0] = DynamicValidationStateChange.super.perform(monitor);
		}
	};
	JavaCore.run(runnable, fSchedulingRule, pm);
	return result[0];
}
 
Example 24
public void didChangeWatchedFiles(DidChangeWatchedFilesParams param) {
	List<FileEvent> changes = param.getChanges().stream().distinct().collect(Collectors.toList());
	for (FileEvent fileEvent : changes) {
		CHANGE_TYPE changeType = toChangeType(fileEvent.getType());
		if (changeType == CHANGE_TYPE.DELETED) {
			cleanUpDiagnostics(fileEvent.getUri());
			handler.didClose(new DidCloseTextDocumentParams(new TextDocumentIdentifier(fileEvent.getUri())));
			discardWorkingCopies(fileEvent.getUri());
		}
		ICompilationUnit unit = JDTUtils.resolveCompilationUnit(fileEvent.getUri());
		if (unit != null && changeType == CHANGE_TYPE.CREATED && !unit.exists()) {
			final ICompilationUnit[] units = new ICompilationUnit[1];
			units[0] = unit;
			try {
				ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
					@Override
					public void run(IProgressMonitor monitor) throws CoreException {
						units[0] = createCompilationUnit(units[0]);
					}
				}, new NullProgressMonitor());
			} catch (CoreException e) {
				JavaLanguageServerPlugin.logException(e.getMessage(), e);
			}
			unit = units[0];
		}
		if (unit != null) {
			if (unit.isWorkingCopy()) {
				continue;
			}
			if (changeType == CHANGE_TYPE.DELETED || changeType == CHANGE_TYPE.CHANGED) {
				if (unit.equals(CoreASTProvider.getInstance().getActiveJavaElement())) {
					CoreASTProvider.getInstance().disposeAST();
				}
			}
		}
		pm.fileChanged(fileEvent.getUri(), changeType);
	}
}
 
Example 25
public void didClose(DidCloseTextDocumentParams params) {
	ISchedulingRule rule = JDTUtils.getRule(params.getTextDocument().getUri());
	try {
		ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
			@Override
			public void run(IProgressMonitor monitor) throws CoreException {
				handleClosed(params);
			}
		}, rule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
	} catch (CoreException e) {
		JavaLanguageServerPlugin.logException("Handle document close ", e);
	}
}
 
Example 26
public void didOpen(DidOpenTextDocumentParams params) {
	ISchedulingRule rule = JDTUtils.getRule(params.getTextDocument().getUri());
	try {
		ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
			@Override
			public void run(IProgressMonitor monitor) throws CoreException {
				handleOpen(params);
			}
		}, rule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
	} catch (CoreException e) {
		JavaLanguageServerPlugin.logException("Handle document open ", e);
	}
}
 
Example 27
public void didChange(DidChangeTextDocumentParams params) {
	ISchedulingRule rule = JDTUtils.getRule(params.getTextDocument().getUri());
	try {
		ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
			@Override
			public void run(IProgressMonitor monitor) throws CoreException {
				handleChanged(params);
			}
		}, rule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
	} catch (CoreException e) {
		JavaLanguageServerPlugin.logException("Handle document change ", e);
	}
}
 
Example 28
public void didSave(DidSaveTextDocumentParams params) {
	ISchedulingRule rule = JDTUtils.getRule(params.getTextDocument().getUri());
	try {
		JobHelpers.waitForJobs(DocumentLifeCycleHandler.DOCUMENT_LIFE_CYCLE_JOBS, new NullProgressMonitor());
		ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
			@Override
			public void run(IProgressMonitor monitor) throws CoreException {
				handleSaved(params);
			}
		}, rule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
	} catch (CoreException e) {
		JavaLanguageServerPlugin.logException("Handle document save ", e);
	}
}
 
Example 29
Source Project: xds-ide   Source File: NewProjectCreator.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public IProject createFromScratch(NewProjectSettings settings, Bundle resourceBundle, IUserInteraction userInteraction) {
  	
  	FromScratchMaker fsm = new FromScratchMaker(settings, resourceBundle, userInteraction); 
  	
  	String err = fsm.createProjectFiles();
  	if (err != null) {
  		if (!err.isEmpty()) {
  			userInteraction.showOkNotification(Messages.NewProjectCreator_CreatePrjFromScratch, err);
  		}
  		return null;
  	}
  	
      final IProject project = createProject(settings.getProjectName(), settings.getProjectRoot());
      openProject(project);
      
      ExternalResourceManager.recreateExternalsFolder(project, new NullProgressMonitor());

      final XdsProjectSettings xdsProjectSettings = XdsProjectSettingsManager.getXdsProjectSettings(project);

      if (XdsProjectType.PROJECT_FILE.equals(fsm.projectType)) {
      	xdsProjectSettings.setXdsProjectFile(ResourceUtils.getRelativePath(project, fsm.prjFile));
          xdsProjectSettings.setProjectType(XdsProjectType.PROJECT_FILE);
      } else {
      	xdsProjectSettings.setMainModule(ResourceUtils.getRelativePath(project, fsm.mainModule));
          xdsProjectSettings.setProjectType(XdsProjectType.MAIN_MODULE);
      }
      mainModule = fsm.mainModule;
      
   xdsProjectSettings.setProjectSdk(settings.getProjectSdk());

      NatureUtils.addNature(project, NatureIdRegistry.MODULA2_SOURCE_PROJECT_NATURE_ID);
      ResourceUtils.scheduleWorkspaceRunnable(new IWorkspaceRunnable() {
    @Override
    public void run(IProgressMonitor monitor) throws CoreException {
        xdsProjectSettings.flush();
    }
}, project, Messages.NewProjectCreator_BuildingProject, false);
      
      return project;
  }
 
Example 30
Source Project: xds-ide   Source File: NewProjectCreator.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public static IProject createFromSources (NewProjectSettings settings) {
      final IProject project = createProject(settings.getProjectName(), settings.getProjectRoot());
      openProject(project);
      ExternalResourceManager.recreateExternalsFolder(project, new NullProgressMonitor());
      
      final XdsProjectSettings xdsProjectSettings = XdsProjectSettingsManager.getXdsProjectSettings(project);

      if (settings.getXdsProjectFile() != null) {
      	xdsProjectSettings.setProjectType(XdsProjectType.PROJECT_FILE);
      	xdsProjectSettings.setXdsProjectFile(ResourceUtils.getRelativePath(project, settings.getXdsProjectFile()));
      } else {
      	xdsProjectSettings.setProjectType(XdsProjectType.MAIN_MODULE);
      	xdsProjectSettings.setMainModule(ResourceUtils.getRelativePath(project, settings.getMainModule()));
      }

   xdsProjectSettings.setProjectSdk(settings.getProjectSdk());

      NatureUtils.addNature(project, NatureIdRegistry.MODULA2_SOURCE_PROJECT_NATURE_ID);
      
      ResourceUtils.scheduleWorkspaceRunnable(new IWorkspaceRunnable() {
    @Override
    public void run(IProgressMonitor monitor) throws CoreException {
        xdsProjectSettings.flush();
    }
}, project, Messages.NewProjectCreator_BuildingProject, false);
      
      return project;
  }