Search in sources :

Example 1 with IWorkspaceRunnable

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

the class JavaProjectHelper method delete.

/**
     * Removes an IJavaElement's resource. Retries if deletion failed (e.g. because the indexer
     * still locks the file).
     *
     * @param elem the element to delete
     * @throws CoreException if operation failed
     * @see #ASSERT_NO_MIXED_LINE_DELIMIERS
     */
public static void delete(final IJavaElement elem) throws CoreException {
    //			MixedLineDelimiterDetector.assertNoMixedLineDelimiters(elem);
    if (elem instanceof JavaProject) {
        ((JavaProject) elem).close();
        JavaModelManager.getJavaModelManager().removePerProjectInfo((JavaProject) elem, true);
    }
    JavaModelManager.getJavaModelManager().resetTemporaryCache();
    IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        public void run(IProgressMonitor monitor) throws CoreException {
            //				performDummySearch();
            if (elem instanceof IJavaProject) {
                IJavaProject jproject = (IJavaProject) elem;
                jproject.setRawClasspath(new IClasspathEntry[0], jproject.getProject().getFullPath(), null);
            }
            delete(elem.getResource());
        }
    };
    ResourcesPlugin.getWorkspace().run(runnable, null);
//		emptyDisplayLoop();
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) JavaProject(org.eclipse.jdt.internal.core.JavaProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IJavaProject(org.eclipse.jdt.core.IJavaProject)

Example 2 with IWorkspaceRunnable

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

the class PerformChangeOperation method executeChange.

/**
	 * Actually executes the change.
	 *
	 * @param pm a progress monitor to report progress
	 *
	 * @throws CoreException if an unexpected error occurs during
	 *  change execution
	 */
protected void executeChange(IProgressMonitor pm) throws CoreException {
    fChangeExecuted = false;
    if (!fChange.isEnabled())
        return;
    IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        public void run(IProgressMonitor monitor) throws CoreException {
            boolean undoInitialized = false;
            try {
                //$NON-NLS-1$
                monitor.beginTask("", 10);
                fValidationStatus = fChange.isValid(new SubProgressMonitor(monitor, 1));
                if (fValidationStatus.hasFatalError())
                    return;
                boolean aboutToPerformChangeCalled = false;
                try {
                    if (fUndoManager != null) {
                        ResourcesPlugin.getWorkspace().checkpoint(false);
                        fUndoManager.aboutToPerformChange(fChange);
                        aboutToPerformChangeCalled = true;
                    }
                    fChangeExecutionFailed = true;
                    fUndoChange = fChange.perform(new SubProgressMonitor(monitor, 9));
                    fChangeExecutionFailed = false;
                    fChangeExecuted = true;
                } finally {
                    if (fUndoManager != null) {
                        ResourcesPlugin.getWorkspace().checkpoint(false);
                        if (aboutToPerformChangeCalled)
                            fUndoManager.changePerformed(fChange, !fChangeExecutionFailed);
                    }
                }
                fChange.dispose();
                if (fUndoChange != null) {
                    fUndoChange.initializeValidationData(new NotCancelableProgressMonitor(new SubProgressMonitor(monitor, 1)));
                    undoInitialized = true;
                }
                if (fUndoManager != null) {
                    if (fUndoChange != null) {
                        fUndoManager.addUndo(fUndoName, fUndoChange);
                    } else {
                        fUndoManager.flush();
                    }
                }
            } catch (CoreException e) {
                if (fUndoManager != null)
                    fUndoManager.flush();
                if (fUndoChange != null && undoInitialized) {
                    Change ch = fUndoChange;
                    fUndoChange = null;
                    ch.dispose();
                }
                fUndoChange = null;
                throw e;
            } catch (RuntimeException e) {
                if (fUndoManager != null)
                    fUndoManager.flush();
                if (fUndoChange != null && undoInitialized) {
                    Change ch = fUndoChange;
                    fUndoChange = null;
                    ch.dispose();
                }
                fUndoChange = null;
                throw e;
            } finally {
                monitor.done();
            }
        }
    };
    ResourcesPlugin.getWorkspace().run(runnable, fSchedulingRule, IWorkspace.AVOID_UPDATE, pm);
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) NotCancelableProgressMonitor(org.eclipse.ltk.internal.core.refactoring.NotCancelableProgressMonitor) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 3 with IWorkspaceRunnable

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

the class DynamicValidationStateChange method perform.

/**
	 * {@inheritDoc}
	 */
@Override
public Change perform(IProgressMonitor pm) throws CoreException {
    final Change[] result = new Change[1];
    IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        public void run(IProgressMonitor monitor) throws CoreException {
            result[0] = DynamicValidationStateChange.super.perform(monitor);
        }
    };
    JavaCore.run(runnable, fSchedulingRule, pm);
    return result[0];
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) Change(org.eclipse.ltk.core.refactoring.Change)

Example 4 with IWorkspaceRunnable

use of org.eclipse.core.resources.IWorkspaceRunnable in project generator by mybatis.

the class WorkspaceUtilities method createProject.

private static IProject createProject(String projectName) throws CoreException {
    final IProject project = getWorkspaceRoot().getProject(projectName);
    IWorkspaceRunnable create = new IWorkspaceRunnable() {

        public void run(IProgressMonitor monitor) throws CoreException {
            project.create(null);
            project.open(null);
        }
    };
    getWorkspace().run(create, null);
    return project;
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IProject(org.eclipse.core.resources.IProject)

Example 5 with IWorkspaceRunnable

use of org.eclipse.core.resources.IWorkspaceRunnable in project tdi-studio-se by Talend.

the class SaveAsBusinessModelWizard method update.

private void update() {
    IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            try {
                assginVlaues(oldProperty, property);
                repositoryFactory.save(oldBusinessProcessItem);
                // assign value
                businessProcessItem = oldBusinessProcessItem;
            } catch (PersistenceException pe) {
                throw new CoreException(new Status(IStatus.ERROR, FrameworkUtil.getBundle(this.getClass()).getSymbolicName(), "persistance error", //$NON-NLS-1$
                pe));
            }
        }
    };
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    try {
        ISchedulingRule schedulingRule = workspace.getRoot();
        // the update the project files need to be done in the workspace runnable to avoid all notification
        // of changes before the end of the modifications.
        workspace.run(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, null);
    } catch (CoreException e) {
        MessageBoxExceptionHandler.process(e.getCause());
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Aggregations

IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)42 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)42 CoreException (org.eclipse.core.runtime.CoreException)35 IWorkspace (org.eclipse.core.resources.IWorkspace)24 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)18 InvocationTargetException (java.lang.reflect.InvocationTargetException)17 PersistenceException (org.talend.commons.exception.PersistenceException)16 IStatus (org.eclipse.core.runtime.IStatus)13 Status (org.eclipse.core.runtime.Status)12 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)11 RepositoryWorkUnit (org.talend.repository.RepositoryWorkUnit)8 IProject (org.eclipse.core.resources.IProject)7 IPath (org.eclipse.core.runtime.IPath)7 HashMap (java.util.HashMap)6 IFile (org.eclipse.core.resources.IFile)6 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)6 HashSet (java.util.HashSet)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 Map (java.util.Map)4 IResource (org.eclipse.core.resources.IResource)4