Search in sources :

Example 51 with IWorkspaceRunnable

use of org.eclipse.core.resources.IWorkspaceRunnable in project eclipse.platform.text by eclipse.

the class ResourceTextFileBufferManager method validateState.

@Override
public void validateState(final IFileBuffer[] fileBuffers, IProgressMonitor monitor, final Object computationContext) throws CoreException {
    IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor progressMonitor) throws CoreException {
            IFileBuffer[] toValidate = findFileBuffersToValidate(fileBuffers);
            validationStateAboutToBeChanged(toValidate);
            try {
                IStatus status = validateEdit(toValidate, computationContext);
                validationStateChanged(toValidate, true, status);
            } catch (RuntimeException x) {
                validationStateChangedFailed(toValidate);
            }
        }
    };
    ResourcesPlugin.getWorkspace().run(runnable, computeValidateStateRule(fileBuffers), IWorkspace.AVOID_UPDATE, monitor);
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IFileBuffer(org.eclipse.core.filebuffers.IFileBuffer)

Example 52 with IWorkspaceRunnable

use of org.eclipse.core.resources.IWorkspaceRunnable in project linuxtools by eclipse.

the class CProjectHelper method createCProject.

/**
 * Creates a ICProject.
 */
private static ICProject createCProject(final String projectName, String binFolderName, final String indexerID) throws CoreException {
    final IWorkspace ws = ResourcesPlugin.getWorkspace();
    final ICProject[] newProject = new ICProject[1];
    ws.run((IWorkspaceRunnable) monitor -> {
        IWorkspaceRoot root = ws.getRoot();
        IProject project = root.getProject(projectName);
        if (indexerID != null) {
            IndexerPreferences.set(project, IndexerPreferences.KEY_INDEX_UNUSED_HEADERS_WITH_DEFAULT_LANG, "true");
            IndexerPreferences.set(project, IndexerPreferences.KEY_INDEXER_ID, indexerID);
        }
        if (!project.exists()) {
            project.create(null);
        } else {
            project.refreshLocal(IResource.DEPTH_INFINITE, null);
        }
        if (!project.isOpen()) {
            project.open(null);
        }
        if (!project.hasNature(CProjectNature.C_NATURE_ID)) {
            String projectId = PLUGIN_ID + ".TestProject";
            addNatureToProject(project, CProjectNature.C_NATURE_ID, null);
            CCorePlugin.getDefault().mapCProjectOwner(project, projectId, false);
        }
        addDefaultBinaryParser(project);
        newProject[0] = CCorePlugin.getDefault().getCoreModel().create(project);
    }, null);
    return newProject[0];
}
Also used : CProjectNature(org.eclipse.cdt.core.CProjectNature) IndexerPreferences(org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences) ICConfigExtensionReference(org.eclipse.cdt.core.settings.model.ICConfigExtensionReference) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) CoreException(org.eclipse.core.runtime.CoreException) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CCProjectNature(org.eclipse.cdt.core.CCProjectNature) CCorePlugin(org.eclipse.cdt.core.CCorePlugin) IProject(org.eclipse.core.resources.IProject) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IResource(org.eclipse.core.resources.IResource) ICProject(org.eclipse.cdt.core.model.ICProject) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ICProject(org.eclipse.cdt.core.model.ICProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkspace(org.eclipse.core.resources.IWorkspace) IProject(org.eclipse.core.resources.IProject)

Example 53 with IWorkspaceRunnable

use of org.eclipse.core.resources.IWorkspaceRunnable in project linuxtools by eclipse.

the class CProjectHelper method createCCProject.

private static ICProject createCCProject(final String projectName, final String binFolderName) throws CoreException {
    final IWorkspace ws = ResourcesPlugin.getWorkspace();
    final ICProject[] newProject = new ICProject[1];
    ws.run((IWorkspaceRunnable) monitor -> {
        ICProject cproject = createCProject2(projectName, binFolderName);
        if (!cproject.getProject().hasNature(CCProjectNature.CC_NATURE_ID)) {
            addNatureToProject(cproject.getProject(), CCProjectNature.CC_NATURE_ID, null);
        }
        newProject[0] = cproject;
    }, null);
    return newProject[0];
}
Also used : CProjectNature(org.eclipse.cdt.core.CProjectNature) ICConfigExtensionReference(org.eclipse.cdt.core.settings.model.ICConfigExtensionReference) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) CoreException(org.eclipse.core.runtime.CoreException) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CCProjectNature(org.eclipse.cdt.core.CCProjectNature) IStatus(org.eclipse.core.runtime.IStatus) CCorePlugin(org.eclipse.cdt.core.CCorePlugin) IProject(org.eclipse.core.resources.IProject) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IResource(org.eclipse.core.resources.IResource) Assert.fail(org.junit.Assert.fail) ICProject(org.eclipse.cdt.core.model.ICProject) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ICProject(org.eclipse.cdt.core.model.ICProject) IWorkspace(org.eclipse.core.resources.IWorkspace)

Aggregations

IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)53 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)53 CoreException (org.eclipse.core.runtime.CoreException)43 IWorkspace (org.eclipse.core.resources.IWorkspace)29 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)19 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 IStatus (org.eclipse.core.runtime.IStatus)18 PersistenceException (org.talend.commons.exception.PersistenceException)16 Status (org.eclipse.core.runtime.Status)14 IProject (org.eclipse.core.resources.IProject)13 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)11 IResource (org.eclipse.core.resources.IResource)10 IPath (org.eclipse.core.runtime.IPath)9 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)7 HashMap (java.util.HashMap)6 IFile (org.eclipse.core.resources.IFile)6 IProjectDescription (org.eclipse.core.resources.IProjectDescription)6 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)6 RepositoryWorkUnit (org.talend.repository.RepositoryWorkUnit)6 HashSet (java.util.HashSet)5