1 11 package org.eclipse.jdt.internal.corext.refactoring.changes; 12 import org.eclipse.core.runtime.Assert; 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IPath; 15 import org.eclipse.core.runtime.IProgressMonitor; 16 import org.eclipse.core.runtime.SubProgressMonitor; 17 18 import org.eclipse.core.resources.IFile; 19 20 import org.eclipse.ui.ide.undo.ResourceDescription; 21 22 import org.eclipse.ltk.core.refactoring.Change; 23 import org.eclipse.ltk.core.refactoring.RefactoringStatus; 24 25 import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages; 26 import org.eclipse.jdt.internal.corext.util.Messages; 27 28 public class DeleteFileChange extends AbstractDeleteChange { 29 30 private final IPath fPath; 31 private final boolean fIsExecuteChange; 32 33 public DeleteFileChange(IFile file, boolean executeChange) { 34 Assert.isNotNull(file, "file"); fPath= Utils.getResourcePath(file); 36 fIsExecuteChange= executeChange; 37 } 38 39 private IFile getFile(){ 40 return Utils.getFile(fPath); 41 } 42 43 46 public String getName() { 47 return Messages.format(RefactoringCoreMessages.DeleteFileChange_1, fPath.lastSegment()); 48 } 49 50 public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException { 51 if (fIsExecuteChange) { 52 return super.isValid(pm, NONE); 55 } else { 56 return super.isValid(pm, READ_ONLY | DIRTY); 57 } 58 } 59 60 63 public Object getModifiedElement() { 64 return getFile(); 65 } 66 67 70 protected Change doDelete(IProgressMonitor pm) throws CoreException { 71 IFile file= getFile(); 72 Assert.isNotNull(file); 73 Assert.isTrue(file.exists()); 74 pm.beginTask("", 3); saveFileIfNeeded(file, new SubProgressMonitor(pm, 1)); 76 77 ResourceDescription resourceDescription = ResourceDescription.fromResource(file); 78 file.delete(false, true, new SubProgressMonitor(pm, 1)); 79 resourceDescription.recordStateFromHistory(file, new SubProgressMonitor(pm, 1)); 80 pm.done(); 81 82 return new UndoDeleteResourceChange(resourceDescription); 83 } 84 } 85 86 | Popular Tags |