Search in sources :

Example 1 with ResourceDescription

use of org.eclipse.ui.ide.undo.ResourceDescription in project che by eclipse.

the class DeletePackageFragmentRootChange method doDelete.

@Override
protected Change doDelete(IProgressMonitor pm) throws CoreException {
    if (!confirmDeleteIfReferenced())
        return new NullChange();
    int resourceUpdateFlags = IResource.KEEP_HISTORY;
    int jCoreUpdateFlags = IPackageFragmentRoot.ORIGINATING_PROJECT_CLASSPATH | IPackageFragmentRoot.OTHER_REFERRING_PROJECTS_CLASSPATH;
    //$NON-NLS-1$
    pm.beginTask("", 2);
    IPackageFragmentRoot root = getRoot();
    IResource rootResource = root.getResource();
    CompositeChange result = new CompositeChange(getName());
    ResourceDescription rootDescription = ResourceDescription.fromResource(rootResource);
    IJavaProject[] referencingProjects = JavaElementUtil.getReferencingProjects(root);
    HashMap<IFile, String> classpathFilesContents = new HashMap<IFile, String>();
    for (int i = 0; i < referencingProjects.length; i++) {
        IJavaProject javaProject = referencingProjects[i];
        //$NON-NLS-1$
        IFile classpathFile = javaProject.getProject().getFile(".classpath");
        if (classpathFile.exists()) {
            classpathFilesContents.put(classpathFile, getFileContents(classpathFile));
        }
    }
    root.delete(resourceUpdateFlags, jCoreUpdateFlags, new SubProgressMonitor(pm, 1));
    rootDescription.recordStateFromHistory(rootResource, new SubProgressMonitor(pm, 1));
    for (Iterator<Entry<IFile, String>> iterator = classpathFilesContents.entrySet().iterator(); iterator.hasNext(); ) {
        Entry<IFile, String> entry = iterator.next();
        IFile file = entry.getKey();
        String contents = entry.getValue();
        //Restore time stamps? This should probably be some sort of UndoTextFileChange.
        TextFileChange classpathUndo = new TextFileChange(Messages.format(RefactoringCoreMessages.DeletePackageFragmentRootChange_restore_file, BasicElementLabels.getPathLabel(file.getFullPath(), true)), file);
        classpathUndo.setEdit(new ReplaceEdit(0, getFileLength(file), contents));
        result.add(classpathUndo);
    }
    result.add(new UndoDeleteResourceChange(rootDescription));
    pm.done();
    return result;
}
Also used : IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Entry(java.util.Map.Entry) IJavaProject(org.eclipse.jdt.core.IJavaProject) NullChange(org.eclipse.ltk.core.refactoring.NullChange) ResourceDescription(org.eclipse.ui.ide.undo.ResourceDescription) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) IResource(org.eclipse.core.resources.IResource)

Example 2 with ResourceDescription

use of org.eclipse.ui.ide.undo.ResourceDescription in project che by eclipse.

the class DeleteSourceManipulationChange method doDelete.

/*
	 * @see DeleteChange#doDelete(IProgressMonitor)
	 */
@Override
protected Change doDelete(IProgressMonitor pm) throws CoreException {
    ISourceManipulation element = getSourceManipulation();
    // since the primary working copy still exists.
    if (element instanceof ICompilationUnit) {
        //$NON-NLS-1$
        pm.beginTask("", 2);
        ICompilationUnit unit = (ICompilationUnit) element;
        saveCUnitIfNeeded(unit, new SubProgressMonitor(pm, 1));
        IResource resource = unit.getResource();
        ResourceDescription resourceDescription = ResourceDescription.fromResource(resource);
        element.delete(false, new SubProgressMonitor(pm, 1));
        resourceDescription.recordStateFromHistory(resource, new SubProgressMonitor(pm, 1));
        return new UndoDeleteResourceChange(resourceDescription);
    } else if (element instanceof IPackageFragment) {
        ICompilationUnit[] units = ((IPackageFragment) element).getCompilationUnits();
        //$NON-NLS-1$
        pm.beginTask("", units.length + 1);
        for (int i = 0; i < units.length; i++) {
            // fix https://bugs.eclipse.org/bugs/show_bug.cgi?id=66835
            saveCUnitIfNeeded(units[i], new SubProgressMonitor(pm, 1));
        }
        element.delete(false, new SubProgressMonitor(pm, 1));
        // caveat: real undo implemented by UndoablePackageDeleteChange
        return new NullChange();
    } else {
        element.delete(false, pm);
        //should not happen
        return null;
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) NullChange(org.eclipse.ltk.core.refactoring.NullChange) ResourceDescription(org.eclipse.ui.ide.undo.ResourceDescription) ISourceManipulation(org.eclipse.jdt.core.ISourceManipulation) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IResource(org.eclipse.core.resources.IResource)

Example 3 with ResourceDescription

use of org.eclipse.ui.ide.undo.ResourceDescription in project che by eclipse.

the class UndoablePackageDeleteChange method perform.

@Override
public Change perform(IProgressMonitor pm) throws CoreException {
    int count = fPackageDeletes.size();
    //$NON-NLS-1$
    pm.beginTask("", count * 3);
    ResourceDescription[] packageDeleteDescriptions = new ResourceDescription[fPackageDeletes.size()];
    for (int i = 0; i < fPackageDeletes.size(); i++) {
        IResource resource = fPackageDeletes.get(i);
        packageDeleteDescriptions[i] = ResourceDescription.fromResource(resource);
        pm.worked(1);
    }
    DynamicValidationStateChange result = (DynamicValidationStateChange) super.perform(new SubProgressMonitor(pm, count));
    for (int i = 0; i < fPackageDeletes.size(); i++) {
        IResource resource = fPackageDeletes.get(i);
        ResourceDescription resourceDescription = packageDeleteDescriptions[i];
        resourceDescription.recordStateFromHistory(resource, new SubProgressMonitor(pm, 1));
        result.add(new UndoDeleteResourceChange(resourceDescription));
    }
    return result;
}
Also used : ResourceDescription(org.eclipse.ui.ide.undo.ResourceDescription) IResource(org.eclipse.core.resources.IResource) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Aggregations

IResource (org.eclipse.core.resources.IResource)3 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)3 ResourceDescription (org.eclipse.ui.ide.undo.ResourceDescription)3 NullChange (org.eclipse.ltk.core.refactoring.NullChange)2 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 IFile (org.eclipse.core.resources.IFile)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)1 ISourceManipulation (org.eclipse.jdt.core.ISourceManipulation)1 CompositeChange (org.eclipse.ltk.core.refactoring.CompositeChange)1 TextFileChange (org.eclipse.ltk.core.refactoring.TextFileChange)1 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)1