Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKai Maetzel2004-04-07 19:54:02 +0000
committerKai Maetzel2004-04-07 19:54:02 +0000
commit4aedd21deab76862f8706ddee22c2122b94d8cd9 (patch)
treebe983d92597ef3257d879d11871916aa79abf1e2
parentc2901205758246854242187ec0c6a3ec91de3c60 (diff)
downloadeclipse.platform.text-4aedd21deab76862f8706ddee22c2122b94d8cd9.tar.gz
eclipse.platform.text-4aedd21deab76862f8706ddee22c2122b94d8cd9.tar.xz
eclipse.platform.text-4aedd21deab76862f8706ddee22c2122b94d8cd9.zip
positions for removed annotations
introduced validation concept
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationModel.java56
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationModelEvent.java63
2 files changed, 102 insertions, 17 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationModel.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationModel.java
index f193f3a05..7870d860e 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationModel.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationModel.java
@@ -86,9 +86,11 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
* @since 3.0
*/
private AnnotationModelEvent fModelEvent;
-
-
-
+ /**
+ * The modification stamp.
+ * @since 3.0
+ */
+ private Object fModificationStamp= new Object();
/**
* Creates a new annotation model. The annotation is empty, i.e. does not
@@ -113,6 +115,7 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
* Returns the annotation map internally used by this annotation model.
*
* @return the annotation map internally used by this annotation model
+ * @since 3.0
*/
protected IAnnotationMap getAnnotationMap() {
return (IAnnotationMap) fAnnotations;
@@ -120,6 +123,7 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
/*
* @see org.eclipse.jface.text.ISynchronizable#getLockObject()
+ * @since 3.0
*/
public Object getLockObject() {
return getAnnotationMap().getLockObject();
@@ -132,10 +136,18 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
getAnnotationMap().setLockObject(lockObject);
}
- private AnnotationModelEvent getAnnotationModelEvent() {
+ /**
+ * Returns the current annotation model event. This is the event that will be sent out
+ * when calling <code>fireModelChanged</code>.
+ *
+ * @return the current annotation model event
+ * @since 3.0
+ */
+ protected AnnotationModelEvent getAnnotationModelEvent() {
if (fModelEvent == null) {
fModelEvent= createAnnotationModelEvent();
fModelEvent.markWorldChange(false);
+ fModificationStamp= fModelEvent;
}
return fModelEvent;
}
@@ -224,9 +236,12 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
public void addAnnotationModelListener(IAnnotationModelListener listener) {
if (!fAnnotationModelListeners.contains(listener)) {
fAnnotationModelListeners.add(listener);
- if (listener instanceof IAnnotationModelListenerExtension)
- ((IAnnotationModelListenerExtension)listener).modelChanged(createAnnotationModelEvent());
- else
+ if (listener instanceof IAnnotationModelListenerExtension) {
+ IAnnotationModelListenerExtension extension= (IAnnotationModelListenerExtension) listener;
+ AnnotationModelEvent event= createAnnotationModelEvent();
+ event.markSealed();
+ extension.modelChanged(event);
+ } else
listener.modelChanged(this);
}
}
@@ -367,9 +382,11 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
*/
protected void fireModelChanged(AnnotationModelEvent event) {
+ event.markSealed();
+
if (event.isEmpty())
return;
-
+
ArrayList v= new ArrayList(fAnnotationModelListeners);
Iterator e= v.iterator();
while (e.hasNext()) {
@@ -515,9 +532,9 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
return position;
}
- /**
- * Removes all annotations from the annotation model and
- * informs all model listeners about this change.
+ /*
+ * @see org.eclipse.jface.text.source.IAnnotationModelExtension#removeAllAnnotations()
+ * @since 3.0
*/
public void removeAllAnnotations() {
removeAllAnnotations(true);
@@ -537,7 +554,8 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
Annotation a= (Annotation) e.next();
Position p= (Position) fAnnotations.get(a);
removePosition(fDocument, p);
- getAnnotationModelEvent().annotationRemoved(a);
+ p.delete();
+ getAnnotationModelEvent().annotationRemoved(a, p);
}
}
@@ -564,13 +582,15 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
protected void removeAnnotation(Annotation annotation, boolean fireModelChanged) {
if (fAnnotations.containsKey(annotation)) {
+ Position p= null;
if (fDocument != null) {
- Position p= (Position) fAnnotations.get(annotation);
+ p= (Position) fAnnotations.get(annotation);
removePosition(fDocument, p);
+ p.delete();
}
fAnnotations.remove(annotation);
- getAnnotationModelEvent().annotationRemoved(annotation);
+ getAnnotationModelEvent().annotationRemoved(annotation, p);
if (fireModelChanged)
fireModelChanged();
@@ -686,4 +706,12 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
}
return ret;
}
+
+ /*
+ * @see org.eclipse.jface.text.source.IAnnotationModelExtension#getModificationStamp()
+ * @since 3.0
+ */
+ public Object getModificationStamp() {
+ return fModificationStamp;
+ }
}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationModelEvent.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationModelEvent.java
index fd94d86d2..5a5208f41 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationModelEvent.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationModelEvent.java
@@ -11,7 +11,11 @@
package org.eclipse.jface.text.source;
+import org.eclipse.jface.text.Position;
+
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
/**
@@ -35,7 +39,7 @@ public class AnnotationModelEvent {
* The removed annotations.
* @since 3.0
*/
- private Set fRemovedAnnotations= new HashSet();
+ private Map fRemovedAnnotations= new HashMap();
/**
* The changed annotations.
* @since 3.0
@@ -46,6 +50,11 @@ public class AnnotationModelEvent {
* @since 3.0
*/
private boolean fIsWorldChange;
+ /**
+ * The modification stamp.
+ * @since 3.0
+ */
+ private Object fModificationStamp;
/**
* Creates a new annotation model event for the given model.
@@ -112,7 +121,20 @@ public class AnnotationModelEvent {
* @since 3.0
*/
public void annotationRemoved(Annotation annotation) {
- fRemovedAnnotations.add(annotation);
+ annotationRemoved(annotation, null);
+ }
+
+ /**
+ * Adds the given annotation to the set of annotations that are reported as
+ * being removed from the model. If this event is considered a world
+ * change, it is no longer so after this method has successfully finished.
+ *
+ * @param annotation the removed annotation
+ * @param position the position of the removed annotation
+ * @since 3.0
+ */
+ public void annotationRemoved(Annotation annotation, Position position) {
+ fRemovedAnnotations.put(annotation, position);
fIsWorldChange= false;
}
@@ -125,11 +147,22 @@ public class AnnotationModelEvent {
public Annotation[] getRemovedAnnotations() {
int size= fRemovedAnnotations.size();
Annotation[] removed= new Annotation[size];
- fRemovedAnnotations.toArray(removed);
+ fRemovedAnnotations.keySet().toArray(removed);
return removed;
}
/**
+ * Returns the position of the removed annotation at that point in time
+ * when the annotation has been removed.
+ *
+ * @param annotation the removed annotation
+ * @return the position of the removed annotation or <code>null</code>
+ */
+ public Position getPositionOfRemovedAnnotation(Annotation annotation) {
+ return (Position) fRemovedAnnotations.get(annotation);
+ }
+
+ /**
* Adds the given annotation to the set of annotations that are reported as
* being changed from the model. If this event is considered a world
* change, it is no longer so after this method has successfully finished.
@@ -189,4 +222,28 @@ public class AnnotationModelEvent {
void markWorldChange(boolean isWorldChange) {
fIsWorldChange= isWorldChange;
}
+
+ /**
+ * Returns whether this annotation model event is still valid.
+ *
+ * @return <code>true</code> if this event is still valid, <code>false</code> otherwise
+ */
+ public boolean isValid() {
+ if (fModificationStamp != null && fAnnotationModel instanceof IAnnotationModelExtension) {
+ IAnnotationModelExtension extension= (IAnnotationModelExtension) fAnnotationModel;
+ return fModificationStamp == extension.getModificationStamp();
+ }
+ return true;
+ }
+
+ /**
+ * Seals this event. Any direct modification to the annotation model after the event has been sealed
+ * invalidates this event.
+ */
+ public void markSealed() {
+ if (fAnnotationModel instanceof IAnnotationModelExtension) {
+ IAnnotationModelExtension extension= (IAnnotationModelExtension) fAnnotationModel;
+ fModificationStamp= extension.getModificationStamp();
+ }
+ }
}

Back to the top