Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKai Maetzel2003-12-09 17:52:28 +0000
committerKai Maetzel2003-12-09 17:52:28 +0000
commitacbc0cf96f03c5e398170db644c619339166aad6 (patch)
treef9e2422a3b10d8b0461edd296d8fc4c29759f256 /org.eclipse.jface.text
parenta99a29812d4816e33a48d52c755e7aaea3769da2 (diff)
downloadeclipse.platform.text-acbc0cf96f03c5e398170db644c619339166aad6.tar.gz
eclipse.platform.text-acbc0cf96f03c5e398170db644c619339166aad6.tar.xz
eclipse.platform.text-acbc0cf96f03c5e398170db644c619339166aad6.zip
Diffstat (limited to 'org.eclipse.jface.text')
-rw-r--r--org.eclipse.jface.text/projection/org/eclipse/jface/text/source/ProjectionAnnotation.java2
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/Annotation.java135
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationModel.java165
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationModelEvent.java104
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationPainter.java167
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationRulerColumn.java59
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/ChangeRulerColumn.java6
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccess.java2
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccessExtension.java19
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationPresentation.java40
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/ILineDiffInfo.java2
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineChangeHover.java12
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineNumberChangeRulerColumn.java8
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/OverviewRuler.java139
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/VisualAnnotationModel.java49
15 files changed, 743 insertions, 166 deletions
diff --git a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/ProjectionAnnotation.java b/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/ProjectionAnnotation.java
index 6f3b0f062e2..4dc7ae8cd88 100644
--- a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/ProjectionAnnotation.java
+++ b/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/ProjectionAnnotation.java
@@ -32,7 +32,7 @@ import org.eclipse.jface.text.Position;
*
* @since 2.1
*/
-public class ProjectionAnnotation extends Annotation {
+public class ProjectionAnnotation extends Annotation implements IAnnotationPresentation {
private static final int OUTER_MARGIN= 1;
private static final int INNER_MARGIN= 1;
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/Annotation.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/Annotation.java
index 5e7edfb52a1..28f48d49e2f 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/Annotation.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/Annotation.java
@@ -20,7 +20,7 @@ import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Canvas;
/**
- * Abstract annotation managed by an <code>IAnnotationModel</code>.
+ * Annotation managed by an <code>IAnnotationModel</code>.
* Annotations are considered being located at layers and are considered being painted
* starting with layer 0 upwards. Thus an annotation of layer 5 will be drawn on top of
* all co-located annotations at the layers 4 - 0. Subclasses must provide the annotations
@@ -28,7 +28,9 @@ import org.eclipse.swt.widgets.Canvas;
*
* @see IVerticalRuler
*/
-public abstract class Annotation {
+public class Annotation {
+
+ public final static String TYPE_UNKNOWN= "org.eclipse.text.annotation.unknown"; //$NON-NLS-1$
/**
* Convenience method for drawing an image aligned inside a rectangle.
@@ -95,11 +97,132 @@ public abstract class Annotation {
/** The layer of this annotation. */
private int fLayer;
+ /**
+ * The type of this annotation.
+ * @since 3.0
+ */
+ private String fType;
+ /**
+ * Indicates whether this annotation is persistent or not.
+ * @since 3.0
+ */
+ private boolean fIsPersistent= false;
+ /**
+ * Indicates whether this annotation is marked as deleted or not.
+ * @since 3.0
+ */
+ private boolean fMarkedAsDeleted= false;
+ /**
+ * The text associated with this annotation.
+ * @since 3.0
+ */
+ private String fText;
+
+
/**
- * Creates a new annotation.
+ * Creates a new annotation that is not persistent and type less.
*/
protected Annotation() {
+ this(null, false, null);
+ }
+
+ /**
+ * Creates a new annotation with the given properties.
+ *
+ * @param type the type of this annotation
+ * @param isPersistent <code>true</code> if this annotation is
+ * persistent, <code>false</code> otherwise
+ * @param text the text associated with this annotation
+ * @since 3.0
+ */
+ public Annotation(String type, boolean isPersistent, String text) {
+ fType= type;
+ fIsPersistent= isPersistent;
+ fText= text;
+ }
+
+ /**
+ * Creates a new annotation.
+ *
+ * @param isPersistent <code>true</code> if persistent, <code>false</code> otherwise
+ * @since 3.0
+ */
+ public Annotation(boolean isPersistent) {
+ this(null, isPersistent, null);
+ }
+
+ /**
+ * Returns whether this annotation is persistent.
+ *
+ * @return <code>true</code> if this annotation is persistent, <code>false</code>
+ * otherwise
+ * @since 3.0
+ */
+ public boolean isPersistent() {
+ return fIsPersistent;
+ }
+
+ /**
+ * Sets the type of this annotation.
+ *
+ * @param type the annotation type
+ * @since 3.0
+ */
+ public void setType(String type) {
+ fType= type;
+ }
+
+ /**
+ * Returns the type of the annotation.
+ *
+ * @return the type of the annotation
+ * @since 3.0
+ */
+ public String getType() {
+ return fType == null? TYPE_UNKNOWN : fType;
+ }
+
+ /**
+ * Marks this annotation deleted according to the value of the
+ * <code>deleted</code> parameter.
+ *
+ * @param deleted <code>true</code> if annotation should be marked as deleted
+ * @since 3.0
+ */
+ public void markDeleted(boolean deleted) {
+ fMarkedAsDeleted= deleted;
+ }
+
+ /**
+ * Returns whether this annotation is marked as deleted.
+ *
+ * @return <code>true</code> if annotation is marked as deleted, <code>false</code>
+ * otherwise
+ * @since 3.0
+ */
+ public boolean isMarkedDeleted() {
+ return fMarkedAsDeleted;
+ }
+
+ /**
+ * Sets the text associated with this annotation.
+ *
+ * @param text the text associated with this annotation
+ * @since 3.0
+ */
+ public void setText(String text) {
+ fText= text;
+ }
+
+ /**
+ * Returns the text associated with this annotation.
+ *
+ * @return the text associated with this annotation or <code>null</code>
+ * @since 3.0
+ */
+ public String getText() {
+ return fText;
}
/**
@@ -124,12 +247,14 @@ public abstract class Annotation {
/**
* Implement this method to draw a graphical representation
- * of this annotation within the given bounds.
+ * of this annotation within the given bounds. This default implementation
+ * does nothing.
*
* @param GC the drawing GC
* @param canvas the canvas to draw on
* @param bounds the bounds inside the canvas to draw on
* @deprecated use <code>IAnnotationAccessExtension.paint(Annotation, GC, Canvas, Rectangle)</code>
*/
- public abstract void paint(GC gc, Canvas canvas, Rectangle bounds);
+ public void paint(GC gc, Canvas canvas, Rectangle bounds) {
+ }
}
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 5a040bd83d6..fcb48a245b9 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
@@ -8,10 +8,8 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-
package org.eclipse.jface.text.source;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -30,7 +28,7 @@ import org.eclipse.jface.text.Position;
/**
* Standard implementation of <code>IAnnotationModel</code>. This class can directly
- * be used by clients. Subclasses may adapt this annotation model to other exsisting
+ * be used by clients. Subclasses may adapt this annotation model to other existing
* annotation mechanisms.
*/
public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtension {
@@ -39,7 +37,7 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
protected Map fAnnotations;
/** The list of annotation model listeners */
protected ArrayList fAnnotationModelListeners;
- /** The document conntected with this model */
+ /** The document connected with this model */
protected IDocument fDocument;
/** The number of open connections to the same document */
private int fOpenConnections= 0;
@@ -53,7 +51,7 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
*/
private Map fAttachments= new HashMap();
/**
- * The annotation model listener on attached submodels.
+ * The annotation model listener on attached sub-models.
* @since 3.0
*/
private IAnnotationModelListener fModelListener= new IAnnotationModelListener() {
@@ -61,7 +59,15 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
AnnotationModel.this.fireModelChanged();
}
};
-
+ /**
+ * The current annotation model event.
+ * @since 3.0
+ */
+ private AnnotationModelEvent fModelEvent= new AnnotationModelEvent(this);
+
+
+
+
/**
* Creates a new annotation model. The annotation is empty, i.e. does not
* manage any annotations and is not connected to any document.
@@ -97,45 +103,42 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
* @since 3.0
*/
public void replaceAnnotations(Annotation[] annotationsToRemove, Map annotationsToAdd) {
-
- boolean modelChanged= true;
+ try {
+ replaceAnnotations(annotationsToRemove, annotationsToAdd, false);
+ } catch (BadLocationException x) {
+ }
+ }
+
+ /**
+ * Replaces the given annotations in this model and if advised fires a
+ * model change event.
+ *
+ * @param annotationsToRemove the annotations to be removed
+ * @param annotationsToAdd the annotations to be added
+ * @param fireModelChanged <code>true</code> if a model change event
+ * should be fired, <code>false</code> otherwise
+ * @throws BadLocationException in case an annotation should be added at an
+ * invalid position
+ * @since 3.0
+ */
+ protected void replaceAnnotations(Annotation[] annotationsToRemove, Map annotationsToAdd, boolean fireModelChanged) throws BadLocationException {
if (annotationsToRemove != null) {
- for (int i= 0, length= annotationsToRemove.length; i < length; i++) {
- Annotation annotation= annotationsToRemove[i];
- if (fAnnotations.containsKey(annotation)) {
-
- if (fDocument != null) {
- Position p= (Position) fAnnotations.get(annotation);
- fDocument.removePosition(p);
- }
-
- fAnnotations.remove(annotation);
-
- modelChanged= true;
- }
- }
+ for (int i= 0, length= annotationsToRemove.length; i < length; i++)
+ removeAnnotation(annotationsToRemove[i]);
}
if (annotationsToAdd != null) {
Iterator iter= annotationsToAdd.entrySet().iterator();
while (iter.hasNext()) {
- try {
- Map.Entry mapEntry= (Map.Entry)iter.next();
- Annotation annotation= (Annotation)mapEntry.getKey();
- if (!fAnnotations.containsKey(annotation)) {
- Position position= (Position)mapEntry.getValue();
- addPosition(fDocument, position);
- fAnnotations.put(annotation, position);
- modelChanged= true;
- }
- } catch (BadLocationException e) {
- // ignore invalid position
- }
+ Map.Entry mapEntry= (Map.Entry) iter.next();
+ Annotation annotation= (Annotation) mapEntry.getKey();
+ Position position= (Position) mapEntry.getValue();
+ addAnnotation(annotation, position, false);
}
}
- if (modelChanged)
+ if (fireModelChanged)
fireModelChanged();
}
@@ -155,6 +158,7 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
addPosition(fDocument, position);
fAnnotations.put(annotation, position);
+ fModelEvent.annotationAdded(annotation);
if (fireModelChanged)
fireModelChanged();
@@ -221,7 +225,7 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
}
/**
- * Hook method. Is called as soon as this model becomes diconnected from its document.
+ * Hook method. Is called as soon as this model becomes disconnected from its document.
* Subclasses may re-implement.
*/
protected void disconnected() {
@@ -260,7 +264,19 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
* Informs all annotation model listeners that this model has been changed.
*/
protected void fireModelChanged() {
- fireModelChanged(new AnnotationModelEvent(this));
+ AnnotationModelEvent event= fModelEvent;
+ fModelEvent= createAnnotationModelEvent();
+ fireModelChanged(event);
+ }
+
+ /**
+ * Creates and returns a new annotation model event. Subclasses may override.
+ *
+ * @return a new and empty annotation model event
+ * @since 3.0
+ */
+ protected AnnotationModelEvent createAnnotationModelEvent() {
+ return new AnnotationModelEvent(this);
}
/**
@@ -273,6 +289,10 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
* @since 2.0
*/
protected void fireModelChanged(AnnotationModelEvent event) {
+
+ if (event.isEmpty())
+ return;
+
ArrayList v= new ArrayList(fAnnotationModelListeners);
Iterator e= v.iterator();
while (e.hasNext()) {
@@ -339,10 +359,10 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
* Returns all annotations managed by this model. <code>cleanup</code>
* indicates whether all annotations whose associated positions are
* deleted should previously be removed from the model. <code>recurse</code> indicates
- * whether annotations of attached submodels should also be returned.
+ * whether annotations of attached sub-models should also be returned.
*
* @param cleanup indicates whether annotations with deleted associated positions are removed
- * @param recurse whether to return annotations managed by submodels.
+ * @param recurse whether to return annotations managed by sub-models.
* @return all annotations managed by this model
* @since 3.0
*/
@@ -411,10 +431,12 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
*/
public Position getPosition(Annotation annotation) {
Position position= (Position) fAnnotations.get(annotation);
+ if (position != null)
+ return position;
+
Iterator it= fAttachments.values().iterator();
while (position == null && it.hasNext())
- position= ((IAnnotationModel)it.next()).getPosition(annotation);
-
+ position= ((IAnnotationModel)it.next()).getPosition(annotation);
return position;
}
@@ -435,10 +457,12 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
protected void removeAllAnnotations(boolean fireModelChanged) {
if (fDocument != null) {
- Iterator e= fAnnotations.values().iterator();
+ Iterator e= fAnnotations.keySet().iterator();
while (e.hasNext()) {
- Position p= (Position) e.next();
+ Annotation a= (Annotation) e.next();
+ Position p= (Position) fAnnotations.get(a);
fDocument.removePosition(p);
+ fModelEvent.annotationRemoved(a);
}
}
@@ -471,12 +495,67 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
}
fAnnotations.remove(annotation);
+ fModelEvent.annotationRemoved(annotation);
if (fireModelChanged)
fireModelChanged();
}
}
+ /**
+ * Modifies the position associated with the given annotation to the given
+ * position. If the annotation is not yet managed by this annotation model,
+ * the annotation is added. All annotation model change listeners will be
+ * informed about the change.
+ *
+ * @param annotation the annotation whose associated position should be
+ * modified
+ * @param position the position to whose values the associated position
+ * should be changed
+ * @since 3.0
+ */
+ public void modifyAnnotation(Annotation annotation, Position position) {
+ modifyAnnotation(annotation, position, true);
+ }
+
+ /**
+ * Modifies the associated position of the given annotation to the given
+ * position. If the annotation is not yet managed by this annotation model,
+ * the annotation is added. If requested, all annotation model change
+ * listeners will be informed about the change.
+ *
+ * @param annotation the annotation whose associated position should be
+ * modified
+ * @param position the position to whose values the associated position
+ * should be changed
+ * @param fireModelChanged indicates whether to notify all model listeners
+ * @since 3.0
+ */
+ protected void modifyAnnotation(Annotation annotation, Position position, boolean fireModelChanged) {
+ if (position == null) {
+ removeAnnotation(annotation, fireModelChanged);
+ } else {
+ Position p= (Position) fAnnotations.get(annotation);
+ if (p != null) {
+
+ if (position.getOffset() != p.getOffset() && position.getLength() != p.getLength()) {
+ p.setOffset(position.getOffset());
+ p.setLength(position.getLength());
+ }
+ fModelEvent.annotationChanged(annotation);
+ if (fireModelChanged)
+ fireModelChanged();
+
+ } else {
+ try {
+ addAnnotation(annotation, position, fireModelChanged);
+ } catch (BadLocationException x) {
+ // ignore invalid position
+ }
+ }
+ }
+ }
+
/*
* @see IAnnotationModel#removeAnnotationModelListener(IAnnotationModelListener)
*/
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 855cca7e79c..b6ad0fcba69 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,10 +11,13 @@
package org.eclipse.jface.text.source;
+import java.util.HashSet;
+import java.util.Set;
+
/**
* Specification of changes applied to annotation models.
- * The event carries the changed annotation model. <p>
- * Work in progress. Intented to also contain added, removed, and modified annotations.
+ * The event carries the changed annotation model
+ * as well as added, removed, and modified annotations.
*
* @see IAnnotationModel
* @since 2.0
@@ -23,6 +26,21 @@ public class AnnotationModelEvent {
/** The model this event refers to. For internal use only. */
IAnnotationModel fAnnotationModel;
+ /**
+ * The added annotations.
+ * @since 3.0
+ */
+ private Set fAddedAnnotations= new HashSet();
+ /**
+ * The removed annotations.
+ * @since 3.0
+ */
+ private Set fRemovedAnnotations= new HashSet();
+ /**
+ * The changed annotations.
+ * @since 3.0
+ */
+ private Set fChangedAnnotations= new HashSet();
/**
* Creates a new annotation model event for the given model.
@@ -41,4 +59,86 @@ public class AnnotationModelEvent {
public IAnnotationModel getAnnotationModel() {
return fAnnotationModel;
}
+
+ /**
+ * Adds the given annotation to the set of annotations that are reported as
+ * being added from the model.
+ *
+ * @param annotation the added annotation
+ * @since 3.0
+ */
+ public void annotationAdded(Annotation annotation) {
+ fAddedAnnotations.add(annotation);
+ }
+
+ /**
+ * Returns the added annotations.
+ *
+ * @return the added annotations
+ * @since 3.0
+ */
+ public Annotation[] getAddedAnnotations() {
+ int size= fAddedAnnotations.size();
+ Annotation[] added= new Annotation[size];
+ fAddedAnnotations.toArray(added);
+ return added;
+ }
+
+ /**
+ * Adds the given annotation to the set of annotations that are reported as
+ * being removed from the model.
+ *
+ * @param annotation the removed annotation
+ * @since 3.0
+ */
+ public void annotationRemoved(Annotation annotation) {
+ fRemovedAnnotations.add(annotation);
+ }
+
+ /**
+ * Returns the removed annotations.
+ *
+ * @return the removed annotations
+ * @since 3.0
+ */
+ public Annotation[] getRemovedAnnotations() {
+ int size= fRemovedAnnotations.size();
+ Annotation[] removed= new Annotation[size];
+ fRemovedAnnotations.toArray(removed);
+ return removed;
+ }
+
+ /**
+ * Adds the given annotation to the set of annotations that are reported as
+ * being changed from the model.
+ *
+ * @param annotation the changed annotation
+ * @since 3.0
+ */
+ public void annotationChanged(Annotation annotation) {
+ fChangedAnnotations.add(annotation);
+ }
+
+ /**
+ * Returns the changed annotations.
+ *
+ * @return the changed annotations
+ * @since 3.0
+ */
+ public Annotation[] getChangedAnnotations() {
+ int size= fChangedAnnotations.size();
+ Annotation[] changed= new Annotation[size];
+ fChangedAnnotations.toArray(changed);
+ return changed;
+ }
+
+ /**
+ * Returns whether this annotation model event is empty or not.
+ *
+ * @return <code>true</code> if this event is empty
+ * @since 3.0
+ */
+ public boolean isEmpty() {
+ return fAddedAnnotations.isEmpty() && fRemovedAnnotations.isEmpty() && fChangedAnnotations.isEmpty();
+ }
}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationPainter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationPainter.java
index a6d8612c959..191870c5d86 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationPainter.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationPainter.java
@@ -92,13 +92,23 @@ public class AnnotationPainter implements IPainter, PaintListener, IAnnotationMo
private List fHighlightedDecorations= new ArrayList();
/** The internal color table */
private Map fColorTable= new HashMap();
- /** The list of types of annotations that are painted by this painter */
- private Set fAnnotationTypes= new HashSet();
+ /** The list of configured annotation types for being painted by this painter */
+ private Set fConfiguredAnnotationTypes= new HashSet();
/**
- * The list of types of annotations that are highlighted by this painter.
+ * The list of allowed annotation types for being painted by this painter.
* @since 3.0
*/
- private Set fHighlightAnnotationTypes= new HashSet();
+ private Set fAllowedAnnotationTypes= new HashSet();
+ /**
+ * The list of configured annotation typed to be highlighted by this painter.
+ * @since 3.0
+ */
+ private Set fConfiguredHighlightAnnotationTypes= new HashSet();
+ /**
+ * The list of allowed annotation types to be highlighted by this painter.
+ * @since 3.0
+ */
+ private Set fAllowedHighlightAnnotationTypes= new HashSet();
/**
* The range in which all highlight annotations can be found.
* @since 3.0
@@ -195,7 +205,7 @@ public class AnnotationPainter implements IPainter, PaintListener, IAnnotationMo
* the painter's annotation model.
*/
private synchronized void catchupWithModel() {
- if (fDecorations != null && fHighlightAnnotationTypes != null) {
+ if (fDecorations != null) {
fDecorations.clear();
fHighlightedDecorations.clear();
@@ -208,15 +218,15 @@ public class AnnotationPainter implements IPainter, PaintListener, IAnnotationMo
while (e.hasNext()) {
Annotation annotation= (Annotation) e.next();
- Object annotationType= fAnnotationAccess.getType(annotation);
- if (annotationType == null)
+ if (annotation.isMarkedDeleted())
continue;
-
+
Color color= null;
- boolean isHighlighting= fHighlightAnnotationTypes.contains(annotationType);
- boolean isDrawingSquiggles= fAnnotationTypes.contains(annotationType);
+ Object annotationType= fAnnotationAccess.getType(annotation);
+ boolean isHighlighting= shouldBeHighlighted(annotationType);
+ boolean isDrawingSquiggles= shouldBeDrawn(annotationType);
if (isDrawingSquiggles || isHighlighting)
- color= (Color) fColorTable.get(annotationType);
+ color= findColor(annotationType);
if (color != null) {
Position position= fModel.getPosition(annotation);
@@ -255,6 +265,101 @@ public class AnnotationPainter implements IPainter, PaintListener, IAnnotationMo
}
/**
+ * Returns whether the given annotation type should be drawn.
+ *
+ * @param annotationType the annotation type
+ * @return <code>true</code> if annotation type should be drawn, <code>false</code>
+ * otherwise
+ * @since 3.0
+ */
+ private boolean shouldBeDrawn(Object annotationType) {
+ return contains(annotationType, fAllowedAnnotationTypes, fConfiguredAnnotationTypes);
+ }
+
+ /**
+ * Returns whether the given annotation type should be highlighted.
+ *
+ * @param annotationType the annotation type
+ * @return <code>true</code> if annotation type should be highlighted, <code>false</code>
+ * otherwise
+ * @since 3.0
+ */
+ private boolean shouldBeHighlighted(Object annotationType) {
+ return contains(annotationType, fAllowedHighlightAnnotationTypes, fConfiguredHighlightAnnotationTypes);
+ }
+
+ /**
+ * Returns whether the given annotation type is contained in the given <code>allowed</code>
+ * set. This is the case if the type is either in the set
+ * or covered by the <code>configured</code> set.
+ *
+ * @param annotationType the annotation type
+ * @return <code>true</code> if annotation is contained, <code>false</code>
+ * otherwise
+ * @since 3.0
+ */
+ private boolean contains(Object annotationType, Set allowed, Set configured) {
+ if (allowed.contains(annotationType))
+ return true;
+
+ boolean covered= isCovered(annotationType, configured);
+ if (covered)
+ allowed.add(annotationType);
+
+ return covered;
+ }
+
+ /**
+ * Computes whether the annotations of the given type are covered by the given <code>configured</code>
+ * set. This is the case if either the type of the annotation or any of its
+ * super types is contained in the <code>configured</code> set.
+ *
+ * @param annotation the annotation
+ * @param annotationType the annotation type
+ * @return <code>true</code> if annotation is covered, <code>false</code>
+ * otherwise
+ * @since 3.0
+ */
+ private boolean isCovered(Object annotationType, Set configured) {
+ if (fAnnotationAccess instanceof IAnnotationAccessExtension) {
+ IAnnotationAccessExtension extension= (IAnnotationAccessExtension) fAnnotationAccess;
+ Iterator e= configured.iterator();
+ while (e.hasNext()) {
+ if (extension.isSubtype(annotationType,e.next()))
+ return true;
+ }
+ return false;
+ }
+ return configured.contains(annotationType);
+ }
+
+ /**
+ * Returns the color for the given annotation type
+ *
+ * @param annotationType the annotation type
+ * @return the color
+ */
+ private Color findColor(Object annotationType) {
+ Color color= (Color) fColorTable.get(annotationType);
+ if (color != null)
+ return color;
+
+ if (fAnnotationAccess instanceof IAnnotationAccessExtension) {
+ IAnnotationAccessExtension extension= (IAnnotationAccessExtension) fAnnotationAccess;
+ Object[] superTypes= extension.getSupertypes(annotationType);
+ if (superTypes != null) {
+ for (int i= superTypes.length -1; i > -1; i--) {
+ color= (Color) fColorTable.get(superTypes[i]);
+ if (color != null)
+ return color;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
* Recomputes the squiggles to be drawn and redraws them.
*/
private void updatePainting() {
@@ -352,7 +457,7 @@ public class AnnotationPainter implements IPainter, PaintListener, IAnnotationMo
* @param annotationType the annotation type
*/
public void addAnnotationType(Object annotationType) {
- fAnnotationTypes.add(annotationType);
+ fConfiguredAnnotationTypes.add(annotationType);
}
/**
@@ -364,7 +469,7 @@ public class AnnotationPainter implements IPainter, PaintListener, IAnnotationMo
* @since 3.0
*/
public void addHighlightAnnotationType(Object annotationType) {
- fHighlightAnnotationTypes.add(annotationType);
+ fConfiguredHighlightAnnotationTypes.add(annotationType);
if (fTextInputListener == null) {
fTextInputListener= new ITextInputListener() {
/*
@@ -392,7 +497,8 @@ public class AnnotationPainter implements IPainter, PaintListener, IAnnotationMo
* @param annotationType the annotation type
*/
public void removeAnnotationType(Object annotationType) {
- fAnnotationTypes.remove(annotationType);
+ fConfiguredAnnotationTypes.remove(annotationType);
+ fAllowedAnnotationTypes.clear();
}
/**
@@ -404,8 +510,9 @@ public class AnnotationPainter implements IPainter, PaintListener, IAnnotationMo
* @since 3.0
*/
public void removeHighlightAnnotationType(Object annotationType) {
- fHighlightAnnotationTypes.remove(annotationType);
- if (fHighlightAnnotationTypes.isEmpty() && fTextInputListener != null) {
+ fConfiguredHighlightAnnotationTypes.remove(annotationType);
+ fAllowedHighlightAnnotationTypes.clear();
+ if (fConfiguredHighlightAnnotationTypes.isEmpty() && fTextInputListener != null) {
fSourceViewer.removeTextInputListener(fTextInputListener);
fTextInputListener= null;
fInputDocumentAboutToBeChanged= false;
@@ -417,8 +524,10 @@ public class AnnotationPainter implements IPainter, PaintListener, IAnnotationMo
* painted by this painter.
*/
public void removeAllAnnotationTypes() {
- fAnnotationTypes.clear();
- fHighlightAnnotationTypes.clear();
+ fConfiguredAnnotationTypes.clear();
+ fAllowedAnnotationTypes.clear();
+ fConfiguredHighlightAnnotationTypes.clear();
+ fAllowedHighlightAnnotationTypes.clear();
if (fTextInputListener != null) {
fSourceViewer.removeTextInputListener(fTextInputListener);
fTextInputListener= null;
@@ -432,7 +541,7 @@ public class AnnotationPainter implements IPainter, PaintListener, IAnnotationMo
* @return <code>true</code> if there is an annotation type whose annotations are painted
*/
public boolean isPaintingAnnotations() {
- return !fAnnotationTypes.isEmpty() || !fHighlightAnnotationTypes.isEmpty();
+ return !fConfiguredAnnotationTypes.isEmpty() || !fConfiguredHighlightAnnotationTypes.isEmpty();
}
/*
@@ -444,13 +553,21 @@ public class AnnotationPainter implements IPainter, PaintListener, IAnnotationMo
fColorTable.clear();
fColorTable= null;
- if (fAnnotationTypes != null)
- fAnnotationTypes.clear();
- fAnnotationTypes= null;
+ if (fConfiguredAnnotationTypes != null)
+ fConfiguredAnnotationTypes.clear();
+ fConfiguredAnnotationTypes= null;
+
+ if (fAllowedAnnotationTypes != null)
+ fAllowedAnnotationTypes.clear();
+ fAllowedAnnotationTypes= null;
+
+ if (fConfiguredHighlightAnnotationTypes != null)
+ fConfiguredHighlightAnnotationTypes.clear();
+ fConfiguredHighlightAnnotationTypes= null;
- if (fHighlightAnnotationTypes != null)
- fHighlightAnnotationTypes.clear();
- fHighlightAnnotationTypes= null;
+ if (fAllowedHighlightAnnotationTypes != null)
+ fAllowedHighlightAnnotationTypes.clear();
+ fAllowedHighlightAnnotationTypes= null;
fTextWidget= null;
fSourceViewer= null;
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationRulerColumn.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationRulerColumn.java
index 47548481234..9f2a5e1f355 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationRulerColumn.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationRulerColumn.java
@@ -108,7 +108,12 @@ public class AnnotationRulerColumn implements IVerticalRulerColumn {
* The list of annotation types to be shown in this ruler.
* @since 3.0
*/
- private Set fAnnotationTypes= new HashSet();
+ private Set fConfiguredAnnotationTypes= new HashSet();
+ /**
+ * The list of allowed annotation types to be shown in this ruler.
+ * @since 3.0
+ */
+ private Set fAllowedAnnotationTypes= new HashSet();
/**
* The annotation access.
* @since 3.0
@@ -252,7 +257,8 @@ public class AnnotationRulerColumn implements IVerticalRulerColumn {
fBuffer= null;
}
- fAnnotationTypes.clear();
+ fConfiguredAnnotationTypes.clear();
+ fAllowedAnnotationTypes.clear();
fAnnotationAccess= null;
}
@@ -376,7 +382,7 @@ public class AnnotationRulerColumn implements IVerticalRulerColumn {
while (iter.hasNext()) {
Annotation annotation= (Annotation) iter.next();
- if (skip(fAnnotationAccess.getType(annotation)))
+ if (skip(annotation))
continue;
int lay= IAnnotationAccessExtension.DEFAULT_LAYER;
@@ -464,7 +470,7 @@ public class AnnotationRulerColumn implements IVerticalRulerColumn {
Annotation annotation= (Annotation) iter.next();
- if (fAnnotationAccess != null && skip(fAnnotationAccess.getType(annotation)))
+ if (fAnnotationAccess != null && skip(annotation))
continue;
int lay= IAnnotationAccessExtension.DEFAULT_LAYER;
@@ -583,7 +589,7 @@ public class AnnotationRulerColumn implements IVerticalRulerColumn {
* @since 3.0
*/
public void addAnnotationType(Object annotationType) {
- fAnnotationTypes.add(annotationType);
+ fConfiguredAnnotationTypes.add(annotationType);
}
/**
@@ -595,20 +601,49 @@ public class AnnotationRulerColumn implements IVerticalRulerColumn {
* @since 3.0
*/
public void removeAnnotationType(Object annotationType) {
- fAnnotationTypes.remove(annotationType);
+ fConfiguredAnnotationTypes.remove(annotationType);
}
/**
- * Returns whether annotation of the given annotation type should be skipped
- * by the drawing routine.
+ * Returns whether the given annotation should be skipped by the drawing
+ * routine.
*
* @param annotationType the annotation type
- * @return <code>true</code> if annotation of the given type should be skipped
+ * @return <code>true</code> if annotation of the given type should be
+ * skipped, <code>false</code> otherwise
* @since 3.0
*/
- private boolean skip(Object annotationType) {
- if (annotationType == null)
+ private boolean skip(Annotation annotation) {
+ Object annotationType= fAnnotationAccess.getType(annotation);
+ if (fAllowedAnnotationTypes.contains(annotationType))
return false;
- return !fAnnotationTypes.contains(annotationType);
+
+ boolean skip= skip(annotationType);
+ if (!skip)
+ fAllowedAnnotationTypes.add(annotationType);
+ return skip;
+ }
+
+ /**
+ * Computes whether the annotation of the given type should be skiped or
+ * not.
+ *
+ * @param annotation the annotation
+ * @param annotationType the annotation type
+ * @return <code>true</code> if annotation should be skipped, <code>false</code>
+ * otherwise
+ * @since 3.0
+ */
+ private boolean skip(Object annotationType) {
+ if (fAnnotationAccess instanceof IAnnotationAccessExtension) {
+ IAnnotationAccessExtension extension= (IAnnotationAccessExtension) fAnnotationAccess;
+ Iterator e= fConfiguredAnnotationTypes.iterator();
+ while (e.hasNext()) {
+ if (extension.isSubtype(annotationType, e.next()))
+ return false;
+ }
+ return true;
+ }
+ return !fConfiguredAnnotationTypes.contains(annotationType);
}
}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ChangeRulerColumn.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ChangeRulerColumn.java
index f159c45bdb1..b1d26b4f95a 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ChangeRulerColumn.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ChangeRulerColumn.java
@@ -504,7 +504,7 @@ public final class ChangeRulerColumn implements IVerticalRulerColumn, IVerticalR
* @return <code>true</code> if <code>info</code> describes either a changed or an added line.
*/
private boolean hasSpecialColor(ILineDiffInfo info) {
- return info.getType() == ILineDiffInfo.ADDED || info.getType() == ILineDiffInfo.CHANGED;
+ return info.getChangeType() == ILineDiffInfo.ADDED || info.getChangeType() == ILineDiffInfo.CHANGED;
}
/**
@@ -544,9 +544,9 @@ public final class ChangeRulerColumn implements IVerticalRulerColumn, IVerticalR
* @return the correct background color for the line type being described by <code>info</code>
*/
private Color getColor(ILineDiffInfo info, Display display) {
- Assert.isTrue(info != null && info.getType() != ILineDiffInfo.UNCHANGED);
+ Assert.isTrue(info != null && info.getChangeType() != ILineDiffInfo.UNCHANGED);
Color ret= null;
- switch (info.getType()) {
+ switch (info.getChangeType()) {
case ILineDiffInfo.CHANGED :
ret= fChangedColor;
break;
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccess.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccess.java
index d7d96ebdc42..9b10687ff5a 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccess.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccess.java
@@ -24,6 +24,7 @@ public interface IAnnotationAccess {
*
* @param annotation the annotation
* @return the type of the given annotation or <code>null</code> if it has none.
+ * @deprecated use <code>Annotation.getType()</code>
*/
Object getType(Annotation annotation);
@@ -44,6 +45,7 @@ public interface IAnnotationAccess {
* @param annotation the annotation
* @return <code>true</code> if the annotation is temporary,
* <code>false</code> otherwise
+ * @deprecated use <code>Annotation.isPersistent()</code>
*/
boolean isTemporary(Annotation annotation);
}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccessExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccessExtension.java
index aee0a7c8515..7d1ede7451f 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccessExtension.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccessExtension.java
@@ -28,7 +28,6 @@ public interface IAnnotationAccessExtension {
* The default annotation layer.
*/
static final int DEFAULT_LAYER= 0;
-
/**
* Returns the label for the given annotation's type.
@@ -58,4 +57,22 @@ public interface IAnnotationAccessExtension {
* @param bounds the bounds inside the canvas to draw on
*/
void paint(Annotation annotation, GC gc, Canvas canvas, Rectangle bounds);
+
+
+ /**
+ * Returns <code>true</code> if the given annotation is of the given type
+ * or <code>false</code> otherwise.
+ *
+ * @param annotationType the annotation type
+ * @param potentialSupertype the potential super annotation type
+ * @return <code>true</code> if annotation type is a subtype of the potential annotation super type
+ */
+ boolean isSubtype(Object annotationType, Object potentialSupertype);
+
+ /**
+ * Returns the list of super types for the given annotation type. This does not include the type
+ * itself.
+ * @return the super types for the given annotation type
+ */
+ Object[] getSupertypes(Object annotationType);
}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationPresentation.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationPresentation.java
new file mode 100644
index 00000000000..16f7fc253f6
--- /dev/null
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationPresentation.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jface.text.source;
+
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Canvas;
+
+/**
+ * Interface for annotations that know how to represent themselves.
+ *
+ * @since 3.0
+ */
+public interface IAnnotationPresentation {
+
+ /**
+ * Returns the annotations drawing layer.
+ *
+ * @return the annotations drawing layer
+ */
+ int getLayer();
+
+ /**
+ * Implement this method to draw a graphical representation
+ * of this annotation within the given bounds.
+ *
+ * @param GC the drawing GC
+ * @param canvas the canvas to draw on
+ * @param bounds the bounds inside the canvas to draw on
+ */
+ void paint(GC gc, Canvas canvas, Rectangle bounds);
+} \ No newline at end of file
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ILineDiffInfo.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ILineDiffInfo.java
index c106d4cffd6..abec44689c8 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ILineDiffInfo.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ILineDiffInfo.java
@@ -49,7 +49,7 @@ public interface ILineDiffInfo {
*
* @return the type of this line.
*/
- int getType();
+ int getChangeType();
/**
* Returns whether this line has any changes (to itself, or any deletions before or after it).
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineChangeHover.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineChangeHover.java
index b977cfa8743..360c4c2e5ad 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineChangeHover.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineChangeHover.java
@@ -154,7 +154,7 @@ public class LineChangeHover implements IAnnotationHover, IAnnotationHoverExtens
for (Iterator it= diffInfos.iterator(); it.hasNext();) {
ILineDiffInfo info= (ILineDiffInfo)it.next();
String[] original= info.getOriginalText();
- int type= info.getType();
+ int type= info.getChangeType();
int i= 0;
if (type == ILineDiffInfo.ADDED)
added++; //$NON-NLS-1$
@@ -239,7 +239,7 @@ public class LineChangeHover implements IAnnotationHover, IAnnotationHoverExtens
// here comes the hack: since we only get deleted lines *after* a line, we decrease one further if conditions met
int l= lineRange.x - 1;
ILineDiffInfo info= differ.getLineInfo(l);
- if (l >= first - 1 && info != null && info.getType() == ILineDiffInfo.UNCHANGED && info.getRemovedLinesBelow() > 0)
+ if (l >= first - 1 && info != null && info.getChangeType() == ILineDiffInfo.UNCHANGED && info.getRemovedLinesBelow() > 0)
return new Point(l, lineRange.y);
else
return lineRange;
@@ -278,12 +278,12 @@ public class LineChangeHover implements IAnnotationHover, IAnnotationHoverExtens
int l= line;
ILineDiffInfo info= differ.getLineInfo(l);
// if this is a special case, we'll start the search one above line
- if (l >= min && info != null && info.getType() == ILineDiffInfo.UNCHANGED && info.getRemovedLinesAbove() > 0) {
+ if (l >= min && info != null && info.getChangeType() == ILineDiffInfo.UNCHANGED && info.getRemovedLinesAbove() > 0) {
info= differ.getLineInfo(--l);
}
// search backwards until a line has no changes to itself
- while (l >= min && info != null && (info.getType() == ILineDiffInfo.CHANGED || info.getType() == ILineDiffInfo.ADDED)) {
+ while (l >= min && info != null && (info.getChangeType() == ILineDiffInfo.CHANGED || info.getChangeType() == ILineDiffInfo.ADDED)) {
info= differ.getLineInfo(--l);
}
@@ -296,11 +296,11 @@ public class LineChangeHover implements IAnnotationHover, IAnnotationHoverExtens
l= line;
info= differ.getLineInfo(l);
// if this is a special case, we'll start the search one below line
- if (l <= max && info != null && info.getType() == ILineDiffInfo.UNCHANGED && info.getRemovedLinesBelow() > 0) {
+ if (l <= max && info != null && info.getChangeType() == ILineDiffInfo.UNCHANGED && info.getRemovedLinesBelow() > 0) {
info= differ.getLineInfo(++l);
}
// search forward until a line has no changes to itself
- while (l <= max && info != null && (info.getType() == ILineDiffInfo.CHANGED || info.getType() == ILineDiffInfo.ADDED)) {
+ while (l <= max && info != null && (info.getChangeType() == ILineDiffInfo.CHANGED || info.getChangeType() == ILineDiffInfo.ADDED)) {
info= differ.getLineInfo(++l);
}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineNumberChangeRulerColumn.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineNumberChangeRulerColumn.java
index d25f5ec0cea..c3dead57d2a 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineNumberChangeRulerColumn.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineNumberChangeRulerColumn.java
@@ -190,7 +190,7 @@ public final class LineNumberChangeRulerColumn extends LineNumberRulerColumn imp
* @return <code>true</code> if <code>info</code> describes either a changed or an added line.
*/
private boolean hasSpecialColor(ILineDiffInfo info) {
- return info.getType() == ILineDiffInfo.ADDED || info.getType() == ILineDiffInfo.CHANGED;
+ return info.getChangeType() == ILineDiffInfo.ADDED || info.getChangeType() == ILineDiffInfo.CHANGED;
}
/**
@@ -231,9 +231,9 @@ public final class LineNumberChangeRulerColumn extends LineNumberRulerColumn imp
* @return the correct background color for the line type being described by <code>info</code>
*/
private Color getColor(ILineDiffInfo info, Display display) {
- Assert.isTrue(info != null && info.getType() != ILineDiffInfo.UNCHANGED);
+ Assert.isTrue(info != null && info.getChangeType() != ILineDiffInfo.UNCHANGED);
Color ret= null;
- switch (info.getType()) {
+ switch (info.getChangeType()) {
case ILineDiffInfo.CHANGED :
ret= getShadedColor(fChangedColor, display);
break;
@@ -253,7 +253,7 @@ public final class LineNumberChangeRulerColumn extends LineNumberRulerColumn imp
private String getDisplayCharacter(ILineDiffInfo info) {
if (info == null)
return ""; //$NON-NLS-1$
- switch (info.getType()) {
+ switch (info.getChangeType()) {
case ILineDiffInfo.CHANGED :
return "~"; //$NON-NLS-1$
case ILineDiffInfo.ADDED :
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/OverviewRuler.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/OverviewRuler.java
index 790468ed153..caab941e4f6 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/OverviewRuler.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/OverviewRuler.java
@@ -125,12 +125,12 @@ public class OverviewRuler implements IOverviewRuler {
private void skip() {
while (fIterator.hasNext()) {
Annotation next= (Annotation) fIterator.next();
- Object annotationType= fAnnotationAccess.getType(next);
- if (annotationType == null)
+ if (next.isMarkedDeleted())
continue;
fNext= next;
- if (fType == null || fType.equals(annotationType)) {
+ Object annotationType= fAnnotationAccess.getType(next);
+ if (fType == null || isSubtype(annotationType)) {
if (fTemporary == IGNORE) return;
boolean temporary= fAnnotationAccess.isTemporary(fNext);
if (fTemporary == TEMPORARY && temporary) return;
@@ -140,6 +140,14 @@ public class OverviewRuler implements IOverviewRuler {
fNext= null;
}
+ private boolean isSubtype(Object annotationType) {
+ if (fAnnotationAccess instanceof IAnnotationAccessExtension) {
+ IAnnotationAccessExtension extension= (IAnnotationAccessExtension) fAnnotationAccess;
+ return extension.isSubtype(annotationType, fType);
+ }
+ return fType.equals(annotationType);
+ }
+
/*
* @see Iterator#hasNext()
*/
@@ -243,9 +251,9 @@ public class OverviewRuler implements IOverviewRuler {
/** The header painter */
private HeaderPainter fHeaderPainter;
/** The list of annotation types to be shown in this ruler */
- private Set fAnnotationTypes= new HashSet();
+ private Set fConfiguredAnnotationTypes= new HashSet();
/** The list of annotation types to be shown in the header of this ruler */
- private Set fHeaderAnnotationTypes= new HashSet();
+ private Set fConfiguredHeaderAnnotationTypes= new HashSet();
/** The mapping between annotation types and colors */
private Map fAnnotationTypes2Colors= new HashMap();
/** The color manager */
@@ -263,6 +271,16 @@ public class OverviewRuler implements IOverviewRuler {
* @since 3.0
*/
private List fLayersSortedByLayer= new ArrayList();
+ /**
+ * Set of allowed annotation types.
+ * @since 3.0
+ */
+ private Set fAllowedAnnotationTypes= new HashSet();
+ /**
+ * Set of allowed header annotation types.
+ * @since 3.0
+ */
+ private Set fAllowedHeaderAnnotationTypes= new HashSet();
/**
@@ -379,8 +397,10 @@ public class OverviewRuler implements IOverviewRuler {
fHitDetectionCursor= null;
}
- fAnnotationTypes.clear();
- fHeaderAnnotationTypes.clear();
+ fConfiguredAnnotationTypes.clear();
+ fAllowedAnnotationTypes.clear();
+ fConfiguredHeaderAnnotationTypes.clear();
+ fAllowedHeaderAnnotationTypes.clear();
fAnnotationTypes2Colors.clear();
fAnnotationsSortedByLayer.clear();
fLayersSortedByLayer.clear();
@@ -709,6 +729,8 @@ public class OverviewRuler implements IOverviewRuler {
Iterator e= new FilterIterator(annotationType);
while (e.hasNext() && found == null) {
Annotation a= (Annotation) e.next();
+ if (a.isMarkedDeleted())
+ continue;
if (skip(fAnnotationAccess.getType(a)))
continue;
@@ -797,14 +819,15 @@ public class OverviewRuler implements IOverviewRuler {
* @see org.eclipse.jface.text.source.IOverviewRuler#addAnnotationType(java.lang.Object)
*/
public void addAnnotationType(Object annotationType) {
- fAnnotationTypes.add(annotationType);
+ fConfiguredAnnotationTypes.add(annotationType);
}
/*
* @see org.eclipse.jface.text.source.IOverviewRuler#removeAnnotationType(java.lang.Object)
*/
public void removeAnnotationType(Object annotationType) {
- fAnnotationTypes.remove(annotationType);
+ fConfiguredAnnotationTypes.remove(annotationType);
+ fAllowedAnnotationTypes.clear();
}
/*
@@ -836,13 +859,68 @@ public class OverviewRuler implements IOverviewRuler {
}
/**
- * Returns whether annotation of the given annotation type should be skipped by the drawing routine.
+ * Returns whether the given annotation type should be skipped by the drawing routine.
*
* @param annotationType the annotation type
* @return <code>true</code> if annotation of the given type should be skipped
*/
private boolean skip(Object annotationType) {
- return !fAnnotationTypes.contains(annotationType);
+ return !contains(annotationType, fAllowedAnnotationTypes, fConfiguredAnnotationTypes);
+ }
+
+ /**
+ * Returns whether the given annotation type should be skipped by the drawing routine of the header.
+ *
+ * @param annotationType the annotation type
+ * @return <code>true</code> if annotation of the given type should be skipped
+ */
+ private boolean skipInHeader(Object annotationType) {
+ return !contains(annotationType, fAllowedHeaderAnnotationTypes, fConfiguredHeaderAnnotationTypes);
+ }
+
+ /**
+ * Returns whether the given annotation type is contained in the given <code>allowed</code>
+ * set. This is the case if the type is either in the set
+ * or covered by the <code>configured</code> set.
+ *
+ * @param annotationType the annotation type
+ * @return <code>true</code> if annotation is contained, <code>false</code>
+ * otherwise
+ * @since 3.0
+ */
+ private boolean contains(Object annotationType, Set allowed, Set configured) {
+ if (allowed.contains(annotationType))
+ return true;
+
+ boolean covered= isCovered(annotationType, configured);
+ if (covered)
+ allowed.add(annotationType);
+
+ return covered;
+ }
+
+ /**
+ * Computes whether the annotations of the given type are covered by the given <code>configured</code>
+ * set. This is the case if either the type of the annotation or any of its
+ * super types is contained in the <code>configured</code> set.
+ *
+ * @param annotation the annotation
+ * @param annotationType the annotation type
+ * @return <code>true</code> if annotation is covered, <code>false</code>
+ * otherwise
+ * @since 3.0
+ */
+ private boolean isCovered(Object annotationType, Set configured) {
+ if (fAnnotationAccess instanceof IAnnotationAccessExtension) {
+ IAnnotationAccessExtension extension= (IAnnotationAccessExtension) fAnnotationAccess;
+ Iterator e= configured.iterator();
+ while (e.hasNext()) {
+ if (extension.isSubtype(annotationType,e.next()))
+ return true;
+ }
+ return false;
+ }
+ return configured.contains(annotationType);
}
/**
@@ -892,7 +970,7 @@ public class OverviewRuler implements IOverviewRuler {
* @return the computed color
*/
private Color getColor(Object annotationType, double scale) {
- Color base= (Color) fAnnotationTypes2Colors.get(annotationType);
+ Color base= findColor(annotationType);
if (base == null)
return null;
@@ -910,6 +988,32 @@ public class OverviewRuler implements IOverviewRuler {
}
/**
+ * Returns the color for the given annotation type
+ *
+ * @param annotationType the annotation type
+ * @return the color
+ */
+ private Color findColor(Object annotationType) {
+ Color color= (Color) fAnnotationTypes2Colors.get(annotationType);
+ if (color != null)
+ return color;
+
+ if (fAnnotationAccess instanceof IAnnotationAccessExtension) {
+ IAnnotationAccessExtension extension= (IAnnotationAccessExtension) fAnnotationAccess;
+ Object[] superTypes= extension.getSupertypes(annotationType);
+ if (superTypes != null) {
+ for (int i= superTypes.length -1; i > -1; i--) {
+ color= (Color) fAnnotationTypes2Colors.get(superTypes[i]);
+ if (color != null)
+ return color;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
* Returns the stroke color for the given annotation type and characteristics.
*
* @param annotationType the annotation type
@@ -985,14 +1089,15 @@ public class OverviewRuler implements IOverviewRuler {
* @see org.eclipse.jface.text.source.IOverviewRuler#addHeaderAnnotationType(java.lang.Object)
*/
public void addHeaderAnnotationType(Object annotationType) {
- fHeaderAnnotationTypes.add(annotationType);
+ fConfiguredHeaderAnnotationTypes.add(annotationType);
}
/*
* @see org.eclipse.jface.text.source.IOverviewRuler#removeHeaderAnnotationType(java.lang.Object)
*/
public void removeHeaderAnnotationType(Object annotationType) {
- fHeaderAnnotationTypes.remove(annotationType);
+ fConfiguredHeaderAnnotationTypes.remove(annotationType);
+ fAllowedHeaderAnnotationTypes.clear();
}
/**
@@ -1008,7 +1113,7 @@ public class OverviewRuler implements IOverviewRuler {
Object annotationType= fAnnotationsSortedByLayer.get(i);
- if (!fHeaderAnnotationTypes.contains(annotationType) || !fAnnotationTypes.contains(annotationType))
+ if (skipInHeader(annotationType) || skip(annotationType))
continue;
for (Iterator e= new FilterIterator(annotationType); e.hasNext();) {
@@ -1021,7 +1126,7 @@ public class OverviewRuler implements IOverviewRuler {
Color color= null;
if (colorType != null)
- color= (Color) fAnnotationTypes2Colors.get(colorType);
+ color= findColor(colorType);
if (color == null) {
if (fHeaderPainter != null)
@@ -1059,7 +1164,7 @@ public class OverviewRuler implements IOverviewRuler {
Object annotationType= fAnnotationsSortedByLayer.get(i);
- if (!fHeaderAnnotationTypes.contains(annotationType) || !fAnnotationTypes.contains(annotationType))
+ if (skipInHeader(annotationType) || skip(annotationType))
continue;
int count= 0;
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/VisualAnnotationModel.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/VisualAnnotationModel.java
index 000a14a8a18..a54a031892e 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/VisualAnnotationModel.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/VisualAnnotationModel.java
@@ -16,7 +16,6 @@ package org.eclipse.jface.text.source;
import java.util.ArrayList;
import java.util.Iterator;
-import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
@@ -115,13 +114,13 @@ class VisualAnnotationModel extends AnnotationModel implements IAnnotationModelL
Position p= (Position) fAnnotations.get(annotation);
if (p != null)
return p;
-
+
if (fModel != null)
return fModel.getPosition(annotation);
-
+
return null;
}
-
+
/*
* @see IAnnotationModelListener#modelChanged(IAnnotationModel)
*/
@@ -135,48 +134,6 @@ class VisualAnnotationModel extends AnnotationModel implements IAnnotationModelL
}
}
- /**
- * Modifies associated position of the given annotation to the given position.
- * If the annotation is not yet managed by this annotation model, the annotation
- * is added. All annotation model change listeners will be informed about the change.
- *
- * @param annotation the annotation whose associated position should be modified
- * @param position the position to whose values the associated position should be changed
- */
- public void modifyAnnotation(Annotation annotation, Position position) {
- modifyAnnotation(annotation, position, true);
- }
-
- /**
- * Modifies the associated position of the given annotation to the given position.
- * If the annotation is not yet managed by this annotation model, the annotation
- * is added. If requested, all annotation model change listeners will be informed
- * about the change.
- *
- * @param annotation the annotation whose associated position should be modified
- * @param position the position to whose values the associated position should be changed
- * @param fireModelChanged indicates whether to notify all model listeners
- */
- private void modifyAnnotation(Annotation annotation, Position position, boolean fireModelChanged) {
- if (position == null) {
- removeAnnotation(annotation, fireModelChanged);
- } else {
- Position p= (Position) fAnnotations.get(annotation);
- if (p != null) {
- p.setOffset(position.getOffset());
- p.setLength(position.getLength());
- if (fireModelChanged)
- fireModelChanged();
- } else {
- try {
- addAnnotation(annotation, position, fireModelChanged);
- } catch (BadLocationException e) {
- // ignore invalid position
- }
- }
- }
- }
-
/*
* @see IAnnotationModel#removeAnnotationModelListener(IAnnotationModelListener)
*/

Back to the top