1 11 12 package org.eclipse.ui.ide.undo; 13 14 import java.util.ArrayList ; 15 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.resources.mapping.IResourceChangeDescriptionFactory; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IAdaptable; 20 import org.eclipse.core.runtime.IProgressMonitor; 21 import org.eclipse.core.runtime.IStatus; 22 import org.eclipse.core.runtime.Status; 23 import org.eclipse.core.runtime.jobs.ISchedulingRule; 24 25 36 public class DeleteResourcesOperation extends AbstractResourcesOperation { 37 38 private boolean deleteContent = false; 40 41 51 public DeleteResourcesOperation(IResource[] resources, String label, 52 boolean deleteContent) { 53 super(resources, label); 54 this.deleteContent = deleteContent; 55 } 56 57 65 protected void doExecute(IProgressMonitor monitor, IAdaptable uiInfo) 66 throws CoreException { 67 delete(monitor, uiInfo, deleteContent); 68 } 69 70 78 protected void doUndo(IProgressMonitor monitor, IAdaptable uiInfo) 79 throws CoreException { 80 recreate(monitor, uiInfo); 81 } 82 83 89 protected boolean updateResourceChangeDescriptionFactory( 90 IResourceChangeDescriptionFactory factory, int operation) { 91 boolean modified = false; 92 if (operation == UNDO) { 93 for (int i = 0; i < resourceDescriptions.length; i++) { 94 IResource resource = resourceDescriptions[i] 95 .createResourceHandle(); 96 factory.create(resource); 97 modified = true; 98 } 99 } else { 100 for (int i = 0; i < resources.length; i++) { 101 IResource resource = resources[i]; 102 factory.delete(resource); 103 modified = true; 104 } 105 } 106 return modified; 107 } 108 109 114 protected ISchedulingRule getExecuteSchedulingRule() { 115 return super.computeDeleteSchedulingRule(); 116 } 117 118 123 protected ISchedulingRule getUndoSchedulingRule() { 124 return super.computeCreateSchedulingRule(); 125 } 126 127 135 public IStatus computeExecutionStatus(IProgressMonitor monitor) { 136 IStatus status = super.computeExecutionStatus(monitor); 137 if (status.isOK()) { 138 status = computeDeleteStatus(); 139 } 140 return status; 141 } 142 143 150 public IStatus computeUndoableStatus(IProgressMonitor monitor) { 151 IStatus status = super.computeUndoableStatus(monitor); 152 if (status.isOK()) { 153 status = computeCreateStatus(false); 157 } 158 return status; 159 } 160 161 168 public IStatus computeRedoableStatus(IProgressMonitor monitor) { 169 IStatus status = super.computeRedoableStatus(monitor); 170 if (status.isOK()) { 171 status = computeDeleteStatus(); 172 } 173 return status; 174 } 175 176 181 protected void appendDescriptiveText(StringBuffer text) { 182 super.appendDescriptiveText(text); 183 text.append(" deleteContent: "); text.append(deleteContent); 185 text.append('\''); 186 } 187 188 195 IStatus checkReadOnlyResources(IResource[] resourcesToCheck) { 196 if (!deleteContent) { 202 ArrayList nonProjectResourcesToCheck = new ArrayList (); 203 for (int i=0; i<resourcesToCheck.length; i++) { 204 if (resourcesToCheck[i].getType() != IResource.PROJECT) { 205 nonProjectResourcesToCheck.add(resourcesToCheck[i]); 206 } 207 } 208 if (nonProjectResourcesToCheck.isEmpty()) { 209 return Status.OK_STATUS; 210 } 211 return super.checkReadOnlyResources((IResource[])nonProjectResourcesToCheck 212 .toArray(new IResource [nonProjectResourcesToCheck.size()])); 213 } 214 return super.checkReadOnlyResources(resourcesToCheck); 216 } 217 } 218 | Popular Tags |