Eclipse Platform
2.0

org.eclipse.jface.text.source
Class AnnotationModel

java.lang.Object
  |
  +--org.eclipse.jface.text.source.AnnotationModel
All Implemented Interfaces:
IAnnotationModel
Direct Known Subclasses:
AbstractMarkerAnnotationModel

public class AnnotationModel
extends Object
implements IAnnotationModel

Standard implementation of IAnnotationModel. This class can directly be used by clients. Subclasses may adapt this annotation model to other exsisting annotation mechanisms.


Field Summary
protected  ArrayList fAnnotationModelListeners
          The list of annotation model listeners
protected  Map fAnnotations
          The list of managed annotations
protected  IDocument fDocument
          The document conntected with this model
 
Constructor Summary
AnnotationModel()
          Creates a new annotation model.
 
Method Summary
 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 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.
 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.
 Position getPosition(Annotation annotation)
          Returns the position associated with the given annotation.
 void removeAllAnnotations()
          Removes all annotations from the annotation model and informs all model listeners about this change.
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.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fAnnotations

protected Map fAnnotations
The list of managed annotations


fAnnotationModelListeners

protected ArrayList fAnnotationModelListeners
The list of annotation model listeners


fDocument

protected IDocument fDocument
The document conntected with this model

Constructor Detail

AnnotationModel

public 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 Detail

addAnnotation

public void addAnnotation(Annotation annotation,
                          Position position)
Description copied from interface: IAnnotationModel
Adds a annotation to this annotation model. The annotation is associated with with the given position which desscribes 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 nothing happens.

Specified by:
addAnnotation in 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

addAnnotation

protected void addAnnotation(Annotation annotation,
                             Position position,
                             boolean fireModelChanged)
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

addAnnotationModelListener

public void addAnnotationModelListener(IAnnotationModelListener listener)
Description copied from interface: IAnnotationModel
Registers 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:
addAnnotationModelListener in interface IAnnotationModel
Parameters:
listener - the listener to be registered, may not be null

addPosition

protected void addPosition(IDocument document,
                           Position position)
Adds 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

connect

public void connect(IDocument document)
Description copied from interface: IAnnotationModel
Connects 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 further connect 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.

Specified by:
connect in interface IAnnotationModel
Parameters:
document - the document the model gets connected to, may not be null
See Also:
IAnnotationModel.disconnect(org.eclipse.jface.text.IDocument)

connected

protected void connected()
Hook method. Is called as soon as this model becomes connected to a document.


disconnected

protected void disconnected()
Hook method. Is called as soon as this model becomes diconnected from its document.


disconnect

public void disconnect(IDocument document)
Description copied from interface: IAnnotationModel
Disconnects 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:
disconnect in interface IAnnotationModel
Parameters:
document - the document the model gets disconnected from, may not be null
See Also:
for further specification details

fireModelChanged

protected void fireModelChanged()
Informs all annotation model listeners that this model has been changed.


fireModelChanged

protected void fireModelChanged(AnnotationModelEvent event)
Informs 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 implementing IAnnotationModelListenerExtension. All other listeners are notified by just calling modelChanged(IAnnotationModel).

Parameters:
event - the event to be sent out to the listeners
Since:
2.0

removeAnnotations

protected void removeAnnotations(List annotations,
                                 boolean fireModelChanged,
                                 boolean modelInitiated)
Removes the given annotations from this model. If requested all annotation model listeners will be informed about this change. modelInitiated indicates 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

cleanup

protected 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

getAnnotationIterator

public Iterator getAnnotationIterator()
Description copied from interface: IAnnotationModel
Returns all annotations managed by this model.

Specified by:
getAnnotationIterator in interface IAnnotationModel
Returns:
all annotations managed by this model

getAnnotationIterator

protected Iterator getAnnotationIterator(boolean cleanup)
Returns all annotations managed by this model. cleanup indicates 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

getPosition

public Position getPosition(Annotation annotation)
Description copied from interface: IAnnotationModel
Returns the position associated with the given annotation.

Specified by:
getPosition in interface IAnnotationModel
Parameters:
annotation - the annotation whose position should be returned
Returns:
the position of the given annotation or null if no associated annotation exists

removeAllAnnotations

public void removeAllAnnotations()
Removes all annotations from the annotation model and informs all model listeners about this change.


removeAllAnnotations

protected 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

removeAnnotation

public void removeAnnotation(Annotation annotation)
Description copied from interface: IAnnotationModel
Removes 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.

Specified by:
removeAnnotation in interface IAnnotationModel
Parameters:
annotation - the annotation to be removed from this model, may not be null

removeAnnotation

protected void removeAnnotation(Annotation annotation,
                                boolean fireModelChanged)
Removes 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

removeAnnotationModelListener

public void removeAnnotationModelListener(IAnnotationModelListener listener)
Description copied from interface: IAnnotationModel
Removes the listener from the model's list of annotation model listeners. If the listener is not registered with the model nothing happens.

Specified by:
removeAnnotationModelListener in interface IAnnotationModel
Parameters:
listener - the listener to be removed, may not be null

Eclipse Platform
2.0

Copyright (c) IBM Corp. and others 2000, 2002. All Rights Reserved.