1 11 12 package org.eclipse.ui.internal.ide.undo; 13 14 import org.eclipse.core.resources.IContainer; 15 import org.eclipse.core.resources.IMarker; 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.resources.IWorkspace; 18 import org.eclipse.core.resources.ResourceAttributes; 19 import org.eclipse.core.resources.ResourcesPlugin; 20 import org.eclipse.core.runtime.CoreException; 21 import org.eclipse.core.runtime.IProgressMonitor; 22 import org.eclipse.ui.ide.undo.ResourceDescription; 23 24 33 abstract class AbstractResourceDescription extends ResourceDescription { 34 IContainer parent; 35 36 long modificationStamp = IResource.NULL_STAMP; 37 38 long localTimeStamp = IResource.NULL_STAMP; 39 40 ResourceAttributes resourceAttributes; 41 42 MarkerDescription[] markerDescriptions; 43 44 47 protected AbstractResourceDescription() { 48 super(); 49 } 50 51 57 protected AbstractResourceDescription(IResource resource) { 58 super(); 59 parent = resource.getParent(); 60 if (resource.isAccessible()) { 61 modificationStamp = resource.getModificationStamp(); 62 localTimeStamp = resource.getLocalTimeStamp(); 63 resourceAttributes = resource.getResourceAttributes(); 64 try { 65 IMarker[] markers = resource.findMarkers(null, true, 66 IResource.DEPTH_INFINITE); 67 markerDescriptions = new MarkerDescription[markers.length]; 68 for (int i = 0; i < markers.length; i++) { 69 markerDescriptions[i] = new MarkerDescription(markers[i]); 70 } 71 } catch (CoreException e) { 72 } 77 } 78 } 79 80 81 84 public IResource createResource(IProgressMonitor monitor) 85 throws CoreException { 86 IResource resource = createResourceHandle(); 87 createExistentResourceFromHandle(resource, monitor); 88 restoreResourceAttributes(resource); 89 return resource; 90 } 91 92 95 public boolean isValid() { 96 return parent == null || parent.exists(); 97 } 98 99 108 protected void restoreResourceAttributes(IResource resource) throws CoreException { 109 if (modificationStamp != IResource.NULL_STAMP) { 110 resource.revertModificationStamp(modificationStamp); 111 } 112 if (localTimeStamp != IResource.NULL_STAMP) { 113 resource.setLocalTimeStamp(localTimeStamp); 114 } 115 if (resourceAttributes != null) { 116 resource.setResourceAttributes(resourceAttributes); 117 } 118 if (markerDescriptions != null) { 119 for (int i = 0; i < markerDescriptions.length; i++) { 120 markerDescriptions[i].resource = resource; 121 markerDescriptions[i].createMarker(); 122 } 123 } 124 } 125 126 129 IWorkspace getWorkspace() { 130 return ResourcesPlugin.getWorkspace(); 131 } 132 133 136 public boolean verifyExistence(boolean checkMembers) { 137 IContainer p = parent; 138 if (p == null) { 139 p = getWorkspace().getRoot(); 140 } 141 IResource handle = p.findMember(getName()); 142 return handle != null; 143 } 144 } 145 | Popular Tags |