public class AnnotationModel extends Object implements IAnnotationModel, IAnnotationModelExtension, ISynchronizable
IAnnotationModel and its extension
interfaces. This class can directly be used by clients. Subclasses may adapt
this annotation model to other existing annotation mechanisms. This class
also implements ISynchronizable. All
modifications of the model's internal annotation map are synchronized using
the model's lock object.| Modifier and Type | Field and Description |
|---|---|
protected ArrayList |
fAnnotationModelListeners
The list of annotation model listeners
|
protected Map |
fAnnotations
Deprecated.
since 3.0 use
getAnnotationMap instead |
protected IDocument |
fDocument
The document connected with this model
|
| Constructor and Description |
|---|
AnnotationModel()
Creates a new annotation model.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAnnotation(Annotation annotation,
Position position)
Adds a annotation to this annotation model.
|
protected void |
addAnnotation(Annotation annotation,
Position position,
boolean fireModelChanged)
Adds the given annotation to this model.
|
void |
addAnnotationModel(Object key,
IAnnotationModel attachment)
Attaches
attachment to the receiver. |
void |
addAnnotationModelListener(IAnnotationModelListener listener)
Registers the annotation model listener with this annotation model.
|
protected void |
addPosition(IDocument document,
Position position)
Adds the given position to the default position category of the
given document.
|
protected void |
cleanup(boolean fireModelChanged)
Removes all annotations from the model whose associated positions have been
deleted.
|
void |
connect(IDocument document)
Connects the annotation model to a document.
|
protected void |
connected()
Hook method.
|
protected AnnotationModelEvent |
createAnnotationModelEvent()
Creates and returns a new annotation model event.
|
void |
disconnect(IDocument document)
Disconnects this model from a document.
|
protected void |
disconnected()
Hook method.
|
protected void |
fireModelChanged()
Informs all annotation model listeners that this model has been changed.
|
protected void |
fireModelChanged(AnnotationModelEvent event)
Informs all annotation model listeners that this model has been changed
as described in the annotation model event.
|
Iterator |
getAnnotationIterator()
Returns all annotations managed by this model.
|
protected Iterator |
getAnnotationIterator(boolean cleanup)
Returns all annotations managed by this model.
|
protected IAnnotationMap |
getAnnotationMap()
Returns the annotation map internally used by this annotation model.
|
IAnnotationModel |
getAnnotationModel(Object key)
Returns the attached
IAnnotationModel for key,
or null if none is attached for key. |
protected AnnotationModelEvent |
getAnnotationModelEvent()
Returns the current annotation model event.
|
Object |
getLockObject()
Returns the lock object or
null if there is none. |
Object |
getModificationStamp()
Returns the modification stamp of this annotation model.
|
Position |
getPosition(Annotation annotation)
Returns the position associated with the given annotation.
|
protected void |
modifyAnnotation(Annotation annotation,
boolean fireModelChanged)
Modifies the given annotation if the annotation is managed by this
annotation model.
|
void |
modifyAnnotationPosition(Annotation annotation,
Position position)
Modifies the position associated with the given annotation to equal the
given position.
|
protected void |
modifyAnnotationPosition(Annotation annotation,
Position position,
boolean fireModelChanged)
Modifies the associated position of the given annotation to the given
position.
|
void |
removeAllAnnotations()
Removes all annotations from this annotation model.
|
protected void |
removeAllAnnotations(boolean fireModelChanged)
Removes all annotations from the annotation model.
|
void |
removeAnnotation(Annotation annotation)
Removes the given annotation from the model.
|
protected void |
removeAnnotation(Annotation annotation,
boolean fireModelChanged)
Removes the given annotation from the annotation model.
|
IAnnotationModel |
removeAnnotationModel(Object key)
Removes and returns the attached
IAnnotationModel for
key. |
void |
removeAnnotationModelListener(IAnnotationModelListener listener)
Removes the listener from the model's list of annotation model listeners.
|
protected void |
removeAnnotations(List annotations,
boolean fireModelChanged,
boolean modelInitiated)
Removes the given annotations from this model.
|
protected void |
removePosition(IDocument document,
Position position)
Removes the given position from the default position category of the
given document.
|
void |
replaceAnnotations(Annotation[] annotationsToRemove,
Map annotationsToAdd)
Adds and removes annotations to/from this annotation model in a single
step.
|
protected void |
replaceAnnotations(Annotation[] annotationsToRemove,
Map annotationsToAdd,
boolean fireModelChanged)
Replaces the given annotations in this model and if advised fires a
model change event.
|
void |
setLockObject(Object lockObject)
Sets the lock object for this object.
|
protected Map fAnnotations
getAnnotationMap insteadprotected ArrayList fAnnotationModelListeners
protected IDocument fDocument
public AnnotationModel()
protected IAnnotationMap getAnnotationMap()
public Object getLockObject()
ISynchronizablenull if there is none. Clients
should use the lock object in order to synchronize concurrent access to
the implementer.getLockObject in interface ISynchronizablenullpublic void setLockObject(Object lockObject)
ISynchronizablenull subsequent calls to specified methods of this object
are synchronized on this lock object. Which methods are synchronized is
specified by the implementer.
You should not override an existing lock object unless you own that lock object yourself. Use the existing lock object instead.
setLockObject in interface ISynchronizablelockObject - the lock object. May be null.protected final AnnotationModelEvent getAnnotationModelEvent()
fireModelChanged.public void addAnnotation(Annotation annotation, Position position)
IAnnotationModeladdAnnotation in interface IAnnotationModelannotation - the annotation to add, may not be nullposition - the position describing the range covered by this annotation,
may not be nullpublic void replaceAnnotations(Annotation[] annotationsToRemove, Map annotationsToAdd)
IAnnotationModelExtensionreplaceAnnotations in interface IAnnotationModelExtensionannotationsToRemove - the annotations to be removed, may be
nullannotationsToAdd - the annotations which will be added, may be
null each map entry has an
Annotation as key and a Position
as valueprotected void replaceAnnotations(Annotation[] annotationsToRemove, Map annotationsToAdd, boolean fireModelChanged) throws BadLocationException
annotationsToRemove - the annotations to be removedannotationsToAdd - the annotations to be addedfireModelChanged - true if a model change event
should be fired, false otherwiseBadLocationException - in case an annotation should be added at an
invalid positionprotected void addAnnotation(Annotation annotation, Position position, boolean fireModelChanged) throws BadLocationException
annotation - the annotation to addposition - the associate positionfireModelChanged - indicates whether to notify all model listenersBadLocationException - if the position is not a valid document positionpublic void addAnnotationModelListener(IAnnotationModelListener listener)
IAnnotationModeladdAnnotationModelListener in interface IAnnotationModellistener - the listener to be registered, may not be nullprotected void addPosition(IDocument document, Position position) throws BadLocationException
document - the document to which to add the positionposition - the position to addBadLocationException - if the position is not a valid document positionprotected void removePosition(IDocument document, Position position)
document - the document to which to add the positionposition - the position to addpublic void connect(IDocument document)
IAnnotationModelconnect calls must mention the document the
model is already connected to. An annotation model primarily uses
connect and disconnect for reference counting
the document. Reference counting frees the clients from keeping tracker
whether a model has already been connected to a document.connect in interface IAnnotationModeldocument - the document the model gets connected to,
may not be nullIAnnotationModel.disconnect(IDocument)protected void connected()
protected void disconnected()
public void disconnect(IDocument document)
IAnnotationModeldisconnect in interface IAnnotationModeldocument - the document the model gets disconnected from,
may not be nullfor further specification detailsprotected void fireModelChanged()
protected AnnotationModelEvent createAnnotationModelEvent()
protected void fireModelChanged(AnnotationModelEvent event)
IAnnotationModelListenerExtension.
All other listeners are notified by just calling modelChanged(IAnnotationModel).event - the event to be sent out to the listenersprotected void removeAnnotations(List annotations, boolean fireModelChanged, boolean modelInitiated)
modelInitiated indicates whether the deletion has
been initiated by this model or by one of its clients.annotations - the annotations to be removedfireModelChanged - indicates whether to notify all model listenersmodelInitiated - indicates whether this changes has been initiated by this modelprotected void cleanup(boolean fireModelChanged)
fireModelChanged - indicates whether to notify all model listenerspublic Iterator getAnnotationIterator()
IAnnotationModelgetAnnotationIterator in interface IAnnotationModelprotected Iterator getAnnotationIterator(boolean cleanup)
cleanup
indicates whether all annotations whose associated positions are
deleted should previously be removed from the model.cleanup - indicates whether annotations with deleted associated positions are removedpublic Position getPosition(Annotation annotation)
IAnnotationModelgetPosition in interface IAnnotationModelannotation - the annotation whose position should be returnednull if no
associated annotation existspublic void removeAllAnnotations()
IAnnotationModelExtensionremoveAllAnnotations in interface IAnnotationModelExtensionprotected void removeAllAnnotations(boolean fireModelChanged)
fireModelChanged - indicates whether to notify all model listenerspublic void removeAnnotation(Annotation annotation)
IAnnotationModelremoveAnnotation in interface IAnnotationModelannotation - the annotation to be removed from this model,
may not be nullprotected void removeAnnotation(Annotation annotation, boolean fireModelChanged)
annotation - the annotation to be removedfireModelChanged - indicates whether to notify all model listenerspublic void modifyAnnotationPosition(Annotation annotation, Position position)
IAnnotationModelExtensionnull the annotation is removed from the model. All
annotation model change listeners will be informed about the change.modifyAnnotationPosition in interface IAnnotationModelExtensionannotation - the annotation whose associated position should be
modifiedposition - the position to whose values the associated position
should be changedprotected void modifyAnnotationPosition(Annotation annotation, Position position, boolean fireModelChanged)
null, the
annotation is removed from the model.
If requested, all annotation model change listeners will be informed about the change.
annotation - the annotation whose associated position should be
modifiedposition - the position to whose values the associated position
should be changedfireModelChanged - indicates whether to notify all model listenersprotected void modifyAnnotation(Annotation annotation, boolean fireModelChanged)
If requested, all annotation model change listeners will be informed about the change.
annotation - the annotation to be modifiedfireModelChanged - indicates whether to notify all model listenerspublic void removeAnnotationModelListener(IAnnotationModelListener listener)
IAnnotationModelremoveAnnotationModelListener in interface IAnnotationModellistener - the listener to be removed, may not be nullpublic void addAnnotationModel(Object key, IAnnotationModel attachment)
IAnnotationModelExtensionattachment to the receiver. Connects
attachment to the currently connected document. If
attachment is already attached (even) under a different
key), it is not attached again.addAnnotationModel in interface IAnnotationModelExtensionkey - the key through which the attachment is identified.attachment - the attached IAnnotationModelpublic IAnnotationModel getAnnotationModel(Object key)
IAnnotationModelExtensionIAnnotationModel for key,
or null if none is attached for key.getAnnotationModel in interface IAnnotationModelExtensionkey - the key through which the attachment is identified.IAnnotationModel attached under
key, or nullpublic IAnnotationModel removeAnnotationModel(Object key)
IAnnotationModelExtensionIAnnotationModel for
key.removeAnnotationModel in interface IAnnotationModelExtensionkey - the key through which the attachment is identified.IAnnotationModel attached under
key, or nullpublic Object getModificationStamp()
IAnnotationModelExtensiongetModificationStamp in interface IAnnotationModelExtensionGuidelines for using Eclipse APIs. Copyright (c) IBM Corp. and others 2000, 2006. All rights reserved.