1 11 package org.eclipse.jdt.internal.corext.refactoring.changes; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IProgressMonitor; 15 import org.eclipse.core.runtime.OperationCanceledException; 16 import org.eclipse.core.runtime.SubProgressMonitor; 17 18 import org.eclipse.core.resources.IFile; 19 import org.eclipse.core.resources.IFolder; 20 import org.eclipse.core.resources.IResource; 21 22 import org.eclipse.ui.ide.undo.ResourceDescription; 23 24 import org.eclipse.ltk.core.refactoring.Change; 25 import org.eclipse.ltk.core.refactoring.RefactoringStatus; 26 27 import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages; 28 import org.eclipse.jdt.internal.corext.util.Messages; 29 30 31 public class UndoDeleteResourceChange extends Change { 32 33 private final ResourceDescription fResourceDescription; 34 35 public UndoDeleteResourceChange(ResourceDescription resourceDescription) { 36 fResourceDescription= resourceDescription; 37 } 38 39 public void initializeValidationData(IProgressMonitor pm) { 40 41 } 42 43 public Object getModifiedElement() { 44 return null; 45 } 46 47 public String getName() { 48 return Messages.format(RefactoringCoreMessages.UndoDeleteResourceChange_change_name, fResourceDescription.getName()); 49 } 50 51 public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException { 52 if (! fResourceDescription.isValid()) { 53 return RefactoringStatus.createFatalErrorStatus( 54 Messages.format( 55 RefactoringCoreMessages.UndoDeleteResourceChange_cannot_restore, 56 fResourceDescription.getName())); 57 } 58 59 if (fResourceDescription.verifyExistence(true)) { 60 return RefactoringStatus.createFatalErrorStatus( 61 Messages.format( 62 RefactoringCoreMessages.UndoDeleteResourceChange_already_exists, 63 fResourceDescription.getName())); 64 } 65 66 return new RefactoringStatus(); 67 } 68 69 public Change perform(IProgressMonitor pm) throws CoreException { 70 IResource created= fResourceDescription.createResource(pm); 71 created.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(pm, 1)); 72 if (created instanceof IFile) { 73 return new DeleteFileChange((IFile) created, false); 74 } else if (created instanceof IFolder) { 75 return new DeleteFolderChange((IFolder) created, false); 76 } else { 77 return null; } 79 } 80 81 public String toString() { 82 return "Remove " + fResourceDescription.getName(); } 84 } 85 | Popular Tags |