Search in sources :

Example 1 with ResourceUndoState

use of org.eclipse.ltk.internal.core.refactoring.resource.undostates.ResourceUndoState in project che by eclipse.

the class DeleteResourceChange method perform.

/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor)
	 */
public Change perform(IProgressMonitor pm) throws CoreException {
    if (pm == null)
        pm = new NullProgressMonitor();
    //$NON-NLS-1$
    pm.beginTask("", 10);
    pm.setTaskName(RefactoringCoreMessages.DeleteResourceChange_deleting);
    try {
        IResource resource = getResource();
        if (resource == null || !resource.exists()) {
            if (fDeleteContent)
                // see https://bugs.eclipse.org/343584
                return null;
            String message = Messages.format(RefactoringCoreMessages.DeleteResourceChange_error_resource_not_exists, BasicElementLabels.getPathLabel(fResourcePath.makeRelative(), false));
            throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), message));
        }
        // make sure all files inside the resource are saved so restoring works
        if (resource.isAccessible()) {
            resource.accept(new IResourceVisitor() {

                public boolean visit(IResource curr) throws CoreException {
                    try {
                        if (curr instanceof IFile) {
                            // progress is covered outside.
                            saveFileIfNeeded((IFile) curr, new NullProgressMonitor());
                        }
                    } catch (CoreException e) {
                    // ignore
                    }
                    return true;
                }
            }, IResource.DEPTH_INFINITE, false);
        }
        ResourceUndoState desc = ResourceUndoState.fromResource(resource);
        if (resource instanceof IProject) {
            ((IProject) resource).delete(fDeleteContent, fForceOutOfSync, new SubProgressMonitor(pm, 10));
        } else {
            int updateFlags;
            if (fForceOutOfSync) {
                updateFlags = IResource.KEEP_HISTORY | IResource.FORCE;
            } else {
                updateFlags = IResource.KEEP_HISTORY;
            }
            resource.delete(updateFlags, new SubProgressMonitor(pm, 5));
            desc.recordStateFromHistory(resource, new SubProgressMonitor(pm, 5));
        }
        return new UndoDeleteResourceChange(desc);
    } finally {
        pm.done();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) UndoDeleteResourceChange(org.eclipse.ltk.internal.core.refactoring.resource.UndoDeleteResourceChange) ResourceUndoState(org.eclipse.ltk.internal.core.refactoring.resource.undostates.ResourceUndoState) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Aggregations

IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 IResourceVisitor (org.eclipse.core.resources.IResourceVisitor)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Status (org.eclipse.core.runtime.Status)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1 UndoDeleteResourceChange (org.eclipse.ltk.internal.core.refactoring.resource.UndoDeleteResourceChange)1 ResourceUndoState (org.eclipse.ltk.internal.core.refactoring.resource.undostates.ResourceUndoState)1