Package org.eclipse.jface.text.source
Class AnnotationModel
java.lang.Object
org.eclipse.jface.text.source.AnnotationModel
- All Implemented Interfaces:
- ISynchronizable,- IAnnotationModel,- IAnnotationModelExtension,- IAnnotationModelExtension2
- Direct Known Subclasses:
- AbstractMarkerAnnotationModel,- ProjectionAnnotationModel
public class AnnotationModel
extends Object
implements IAnnotationModel, IAnnotationModelExtension, IAnnotationModelExtension2, ISynchronizable
Standard implementation of 
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.- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected ArrayList<IAnnotationModelListener> The list of annotation model listenersprotected Map<Annotation, Position> Deprecated.protected IDocumentThe document connected with this model
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddAnnotation(Annotation annotation, Position position) Adds a annotation to this annotation model.protected voidaddAnnotation(Annotation annotation, Position position, boolean fireModelChanged) Adds the given annotation to this model.voidaddAnnotationModel(Object key, IAnnotationModel attachment) Attachesattachmentto the receiver.voidRegisters the annotation model listener with this annotation model.protected voidaddPosition(IDocument document, Position position) Adds the given position to the default position category of the given document.protected voidcleanup(boolean fireModelChanged) Removes all annotations from the model whose associated positions have been deleted.voidConnects the annotation model to a document.protected voidHook method.protected AnnotationModelEventCreates and returns a new annotation model event.voiddisconnect(IDocument document) Disconnects this model from a document.protected voidHook method.protected voidInforms all annotation model listeners that this model has been changed.protected voidInforms all annotation model listeners that this model has been changed as described in the annotation model event.Returns all annotations managed by this model.protected Iterator<Annotation> getAnnotationIterator(boolean cleanup) Returns all annotations managed by this model.getAnnotationIterator(int offset, int length, boolean canStartBefore, boolean canEndAfter) Returns an iterator over all annotations managed by this model that are inside the given region.protected IAnnotationMapReturns the annotation map internally used by this annotation model.getAnnotationModel(Object key) Returns the attachedIAnnotationModelforkey, ornullif none is attached forkey.protected final AnnotationModelEventReturns the current annotation model event.Returns the lock object ornullif there is none.Returns the modification stamp of this annotation model.getPosition(Annotation annotation) Returns the position associated with the given annotation.protected voidmodifyAnnotation(Annotation annotation, boolean fireModelChanged) Modifies the given annotation if the annotation is managed by this annotation model.voidmodifyAnnotationPosition(Annotation annotation, Position position) Modifies the position associated with the given annotation to equal the given position.protected voidmodifyAnnotationPosition(Annotation annotation, Position position, boolean fireModelChanged) Modifies the associated position of the given annotation to the given position.voidRemoves all annotations from this annotation model.protected voidremoveAllAnnotations(boolean fireModelChanged) Removes all annotations from the annotation model.voidremoveAnnotation(Annotation annotation) Removes the given annotation from the model.protected voidremoveAnnotation(Annotation annotation, boolean fireModelChanged) Removes the given annotation from the annotation model.Removes and returns the attachedIAnnotationModelforkey.voidRemoves the listener from the model's list of annotation model listeners.protected voidremoveAnnotations(List<? extends Annotation> annotations, boolean fireModelChanged, boolean modelInitiated) Removes the given annotations from this model.protected voidremovePosition(IDocument document, Position position) Removes the given position from the default position category of the given document.voidreplaceAnnotations(Annotation[] annotationsToRemove, Map<? extends Annotation, ? extends Position> annotationsToAdd) Adds and removes annotations to/from this annotation model in a single step.protected voidreplaceAnnotations(Annotation[] annotationsToRemove, Map<? extends Annotation, ? extends Position> annotationsToAdd, boolean fireModelChanged) Replaces the given annotations in this model and if advised fires a model change event.voidsetLockObject(Object lockObject) Sets the lock object for this object.
- 
Field Details- 
fAnnotationsDeprecated.since 3.0 usegetAnnotationMapinsteadThe list of managed annotations
- 
fAnnotationModelListenersThe list of annotation model listeners
- 
fDocumentThe document connected with this model
 
- 
- 
Constructor Details- 
AnnotationModelpublic AnnotationModel()Creates a new annotation model. The annotation is empty, i.e. does not manage any annotations and is not connected to any document.
 
- 
- 
Method Details- 
getAnnotationMapReturns the annotation map internally used by this annotation model.- Returns:
- the annotation map internally used by this annotation model
- Since:
- 3.0
 
- 
getLockObjectDescription copied from interface:ISynchronizableReturns the lock object ornullif there is none. Clients should use the lock object in order to synchronize concurrent access to the implementer.- Specified by:
- getLockObjectin interface- ISynchronizable
- Returns:
- the lock object or null
 
- 
setLockObjectDescription copied from interface:ISynchronizableSets the lock object for this object. If the lock object is notnullsubsequent 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. - Specified by:
- setLockObjectin interface- ISynchronizable
- Parameters:
- lockObject- the lock object. May be- null.
 
- 
getAnnotationModelEventReturns the current annotation model event. This is the event that will be sent out when callingfireModelChanged.- Returns:
- the current annotation model event
- Since:
- 3.0
 
- 
addAnnotationDescription copied from interface:IAnnotationModelAdds a annotation to this annotation model. The annotation is associated with with the given position which describes the range covered by the annotation. All registered annotation model listeners are informed about the change. If the model is connected to a document, the position is automatically updated on document changes. If the annotation is already managed by this annotation model or is not a valid position in the connected document nothing happens.Performance hint: Use IAnnotationModelExtension.replaceAnnotations(Annotation[], java.util.Map)if several annotations are added and/or removed.- Specified by:
- addAnnotationin interface- IAnnotationModel
- Parameters:
- annotation- the annotation to add, may not be- null
- position- the position describing the range covered by this annotation, may not be- null
 
- 
replaceAnnotationspublic void replaceAnnotations(Annotation[] annotationsToRemove, Map<? extends Annotation, ? extends Position> annotationsToAdd) Description copied from interface:IAnnotationModelExtensionAdds and removes annotations to/from this annotation model in a single step. The annotations to remove are given in an array. The annotations to add are provided in a map associating the annotations with the positions at which they should be added. All registered annotation model listeners are informed about the change. If the model is connected to a document, the positions are automatically updated on document changes. Annotations that are already managed by this annotation model or are not associated with a valid position in the connected document have no effect.- Specified by:
- replaceAnnotationsin interface- IAnnotationModelExtension
- Parameters:
- annotationsToRemove- the annotations to be removed, may be- null
- annotationsToAdd- the annotations which will be added, may be- nulleach map entry has an- Annotationas key and a- Positionas value
 
- 
replaceAnnotationsprotected void replaceAnnotations(Annotation[] annotationsToRemove, Map<? extends Annotation, ? extends Position> annotationsToAdd, boolean fireModelChanged) throws BadLocationExceptionReplaces the given annotations in this model and if advised fires a model change event.- Parameters:
- annotationsToRemove- the annotations to be removed
- annotationsToAdd- the annotations to be added
- fireModelChanged-- trueif a model change event should be fired,- falseotherwise
- Throws:
- BadLocationException- in case an annotation should be added at an invalid position
- Since:
- 3.0
 
- 
addAnnotationprotected void addAnnotation(Annotation annotation, Position position, boolean fireModelChanged) throws BadLocationException Adds the given annotation to this model. Associates the annotation with the given position. If requested, all annotation model listeners are informed about this model change. If the annotation is already managed by this model nothing happens.- Parameters:
- annotation- the annotation to add
- position- the associate position
- fireModelChanged- indicates whether to notify all model listeners
- Throws:
- BadLocationException- if the position is not a valid document position
 
- 
addAnnotationModelListenerDescription copied from interface:IAnnotationModelRegisters the annotation model listener with this annotation model. After registration listener is informed about each change of this model. If the listener is already registered nothing happens.- Specified by:
- addAnnotationModelListenerin interface- IAnnotationModel
- Parameters:
- listener- the listener to be registered, may not be- null
 
- 
addPositionAdds the given position to the default position category of the given document.- Parameters:
- document- the document to which to add the position
- position- the position to add
- Throws:
- BadLocationException- if the position is not a valid document position
 
- 
removePositionRemoves the given position from the default position category of the given document.- Parameters:
- document- the document to which to add the position
- position- the position to add
- Since:
- 3.0
 
- 
connectDescription copied from interface:IAnnotationModelConnects the annotation model to a document. The annotations managed by this model must subsequently update according to the changes applied to the document. Once an annotation model is connected to a document, all furtherconnectcalls must mention the document the model is already connected to. An annotation model primarily usesconnectanddisconnectfor reference counting the document. Reference counting frees the clients from keeping tracker whether a model has already been connected to a document.- Specified by:
- connectin interface- IAnnotationModel
- Parameters:
- document- the document the model gets connected to, may not be- null
- See Also:
 
- 
connectedprotected void connected()Hook method. Is called as soon as this model becomes connected to a document. Subclasses may re-implement.
- 
disconnectedprotected void disconnected()Hook method. Is called as soon as this model becomes disconnected from its document. Subclasses may re-implement.
- 
disconnectDescription copied from interface:IAnnotationModelDisconnects this model from a document. After that, document changes no longer matter. An annotation model may only be disconnected from a document to which it has been connected before. If the model reference counts the connections to a document, the connection to the document may only be terminated if the reference count does down to 0.- Specified by:
- disconnectin interface- IAnnotationModel
- Parameters:
- document- the document the model gets disconnected from, may not be- null
- See Also:
 
- 
fireModelChangedprotected void fireModelChanged()Informs all annotation model listeners that this model has been changed.
- 
createAnnotationModelEventCreates and returns a new annotation model event. Subclasses may override.- Returns:
- a new and empty annotation model event
- Since:
- 3.0
 
- 
fireModelChangedInforms all annotation model listeners that this model has been changed as described in the annotation model event. The event is sent out to all listeners implementingIAnnotationModelListenerExtension. All other listeners are notified by just callingmodelChanged(IAnnotationModel).- Parameters:
- event- the event to be sent out to the listeners
- Since:
- 2.0
 
- 
removeAnnotationsprotected void removeAnnotations(List<? extends Annotation> annotations, boolean fireModelChanged, boolean modelInitiated) Removes the given annotations from this model. If requested all annotation model listeners will be informed about this change.modelInitiatedindicates whether the deletion has been initiated by this model or by one of its clients.- Parameters:
- annotations- the annotations to be removed
- fireModelChanged- indicates whether to notify all model listeners
- modelInitiated- indicates whether this changes has been initiated by this model
 
- 
cleanupprotected void cleanup(boolean fireModelChanged) Removes all annotations from the model whose associated positions have been deleted. If requested inform all model listeners about the change.- Parameters:
- fireModelChanged- indicates whether to notify all model listeners
 
- 
getAnnotationIteratorDescription copied from interface:IAnnotationModelReturns all annotations managed by this model.- Specified by:
- getAnnotationIteratorin interface- IAnnotationModel
- Returns:
- all annotations managed by this model
 
- 
getAnnotationIteratorpublic Iterator<Annotation> getAnnotationIterator(int offset, int length, boolean canStartBefore, boolean canEndAfter) Returns an iterator over all annotations managed by this model that are inside the given region.- Specified by:
- getAnnotationIteratorin interface- IAnnotationModelExtension2
- Parameters:
- offset- the start position of the region, must be >= 0
- length- the length of the region, must be >= 0
- canStartBefore- if- truethen annotations are included which start before the region if they end at or after the region's start
- canEndAfter- if- truethen annotations are included which end after the region if they start at or before the region's end
- Returns:
- all annotations inside the region managed by this model
- Since:
- 3.4
 
- 
getAnnotationIteratorReturns all annotations managed by this model.cleanupindicates whether all annotations whose associated positions are deleted should previously be removed from the model.- Parameters:
- cleanup- indicates whether annotations with deleted associated positions are removed
- Returns:
- all annotations managed by this model
 
- 
getPositionDescription copied from interface:IAnnotationModelReturns the position associated with the given annotation.- Specified by:
- getPositionin interface- IAnnotationModel
- Parameters:
- annotation- the annotation whose position should be returned
- Returns:
- the position of the given annotation or nullif no associated annotation exists
 
- 
removeAllAnnotationspublic void removeAllAnnotations()Description copied from interface:IAnnotationModelExtensionRemoves all annotations from this annotation model.- Specified by:
- removeAllAnnotationsin interface- IAnnotationModelExtension
 
- 
removeAllAnnotationsprotected void removeAllAnnotations(boolean fireModelChanged) Removes all annotations from the annotation model. If requested inform all model change listeners about this change.- Parameters:
- fireModelChanged- indicates whether to notify all model listeners
 
- 
removeAnnotationDescription copied from interface:IAnnotationModelRemoves the given annotation from the model. I.e. the annotation is no longer managed by this model. The position associated with the annotation is no longer updated on document changes. If the annotation is not managed by this model, nothing happens.Performance hint: Use IAnnotationModelExtension.replaceAnnotations(Annotation[], java.util.Map)if several annotations are removed and/or added.- Specified by:
- removeAnnotationin interface- IAnnotationModel
- Parameters:
- annotation- the annotation to be removed from this model, may not be- null
 
- 
removeAnnotationRemoves the given annotation from the annotation model. If requested inform all model change listeners about this change.- Parameters:
- annotation- the annotation to be removed
- fireModelChanged- indicates whether to notify all model listeners
 
- 
modifyAnnotationPositionDescription copied from interface:IAnnotationModelExtensionModifies the position associated with the given annotation to equal the given position. If the annotation is not yet managed by this annotation model, the annotation is added. If the given position isnullthe annotation is removed from the model. All annotation model change listeners will be informed about the change.- Specified by:
- modifyAnnotationPositionin interface- IAnnotationModelExtension
- Parameters:
- annotation- the annotation whose associated position should be modified
- position- the position to whose values the associated position should be changed
 
- 
modifyAnnotationPositionprotected void modifyAnnotationPosition(Annotation annotation, Position position, boolean fireModelChanged) 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. When the position isnull, the annotation is removed from the model.If requested, all annotation model change listeners will be informed about the change. - Parameters:
- annotation- the annotation whose associated position should be modified
- position- the position to whose values the associated position should be changed
- fireModelChanged- indicates whether to notify all model listeners
- Since:
- 3.0
 
- 
modifyAnnotationModifies the given annotation if the annotation is managed by this annotation model.If requested, all annotation model change listeners will be informed about the change. - Parameters:
- annotation- the annotation to be modified
- fireModelChanged- indicates whether to notify all model listeners
- Since:
- 3.0
 
- 
removeAnnotationModelListenerDescription copied from interface:IAnnotationModelRemoves the listener from the model's list of annotation model listeners. If the listener is not registered with the model nothing happens.- Specified by:
- removeAnnotationModelListenerin interface- IAnnotationModel
- Parameters:
- listener- the listener to be removed, may not be- null
 
- 
addAnnotationModelDescription copied from interface:IAnnotationModelExtensionAttachesattachmentto the receiver. Connectsattachmentto the currently connected document. Ifattachmentis already attached (even) under a different key), it is not attached again.- Specified by:
- addAnnotationModelin interface- IAnnotationModelExtension
- Parameters:
- key- the key through which the attachment is identified.
- attachment- the attached- IAnnotationModel
 
- 
getAnnotationModelDescription copied from interface:IAnnotationModelExtensionReturns the attachedIAnnotationModelforkey, ornullif none is attached forkey.- Specified by:
- getAnnotationModelin interface- IAnnotationModelExtension
- Parameters:
- key- the key through which the attachment is identified.
- Returns:
- an IAnnotationModelattached underkey, ornull
 
- 
removeAnnotationModelDescription copied from interface:IAnnotationModelExtensionRemoves and returns the attachedIAnnotationModelforkey.- Specified by:
- removeAnnotationModelin interface- IAnnotationModelExtension
- Parameters:
- key- the key through which the attachment is identified.
- Returns:
- an IAnnotationModelattached underkey, ornull
 
- 
getModificationStampDescription copied from interface:IAnnotationModelExtensionReturns the modification stamp of this annotation model.- Specified by:
- getModificationStampin interface- IAnnotationModelExtension
- Returns:
- the modification stamp of this annotation model
 
 
- 
getAnnotationMapinstead