1 11 package org.eclipse.jface.text.source; 12 13 14 import org.eclipse.jface.text.Position; 15 16 import java.util.HashMap ; 17 import java.util.HashSet ; 18 import java.util.Map ; 19 import java.util.Set ; 20 21 22 34 public class AnnotationModelEvent { 35 36 37 private IAnnotationModel fAnnotationModel; 38 42 private Set fAddedAnnotations= new HashSet (); 43 47 private Map fRemovedAnnotations= new HashMap (); 48 52 private Set fChangedAnnotations= new HashSet (); 53 57 private boolean fIsWorldChange; 58 62 private Object fModificationStamp; 63 64 69 public AnnotationModelEvent(IAnnotationModel model) { 70 this(model, true); 71 } 72 73 80 public AnnotationModelEvent(IAnnotationModel model, boolean isWorldChange) { 81 fAnnotationModel= model; 82 fIsWorldChange= isWorldChange; 83 } 84 85 90 public IAnnotationModel getAnnotationModel() { 91 return fAnnotationModel; 92 } 93 94 102 public void annotationAdded(Annotation annotation) { 103 fAddedAnnotations.add(annotation); 104 fIsWorldChange= false; 105 } 106 107 113 public Annotation[] getAddedAnnotations() { 114 int size= fAddedAnnotations.size(); 115 Annotation[] added= new Annotation[size]; 116 fAddedAnnotations.toArray(added); 117 return added; 118 } 119 120 128 public void annotationRemoved(Annotation annotation) { 129 annotationRemoved(annotation, null); 130 } 131 132 141 public void annotationRemoved(Annotation annotation, Position position) { 142 fRemovedAnnotations.put(annotation, position); 143 fIsWorldChange= false; 144 } 145 146 152 public Annotation[] getRemovedAnnotations() { 153 int size= fRemovedAnnotations.size(); 154 Annotation[] removed= new Annotation[size]; 155 fRemovedAnnotations.keySet().toArray(removed); 156 return removed; 157 } 158 159 167 public Position getPositionOfRemovedAnnotation(Annotation annotation) { 168 return (Position) fRemovedAnnotations.get(annotation); 169 } 170 171 179 public void annotationChanged(Annotation annotation) { 180 fChangedAnnotations.add(annotation); 181 fIsWorldChange= false; 182 } 183 184 190 public Annotation[] getChangedAnnotations() { 191 int size= fChangedAnnotations.size(); 192 Annotation[] changed= new Annotation[size]; 193 fChangedAnnotations.toArray(changed); 194 return changed; 195 } 196 197 206 public boolean isEmpty() { 207 return !fIsWorldChange && fAddedAnnotations.isEmpty() && fRemovedAnnotations.isEmpty() && fChangedAnnotations.isEmpty(); 208 } 209 210 219 public boolean isWorldChange() { 220 return fIsWorldChange; 221 } 222 223 229 void markWorldChange(boolean isWorldChange) { 230 fIsWorldChange= isWorldChange; 231 } 232 233 239 public boolean isValid() { 240 if (fModificationStamp != null && fAnnotationModel instanceof IAnnotationModelExtension) { 241 IAnnotationModelExtension extension= (IAnnotationModelExtension) fAnnotationModel; 242 return fModificationStamp == extension.getModificationStamp(); 243 } 244 return true; 245 } 246 247 253 public void markSealed() { 254 if (fAnnotationModel instanceof IAnnotationModelExtension) { 255 IAnnotationModelExtension extension= (IAnnotationModelExtension) fAnnotationModel; 256 fModificationStamp= extension.getModificationStamp(); 257 } 258 } 259 } 260 | Popular Tags |