Eclipse Platform
2.0

org.eclipse.ui.texteditor
Class AbstractMarkerAnnotationModel

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

public abstract class AbstractMarkerAnnotationModel
extends AnnotationModel

Abstract implementation of a marker-based annotation model.

Markers are provided by an underlying source (a subclass responsibility). Markers whose textual range gets deleted during text editing are removed from the model on save. The updateMarkers method can be used to force the model to update the source's markers with any changes to their locations due to edits. Clients can register IMarkerUpdater objects in order to define the process of marker updating. Registration can be done using the "org.eclipse.ui.markerUpdaters" extension point.

Subclasses must implement the following methods:


Field Summary
 
Fields inherited from class org.eclipse.jface.text.source.AnnotationModel
fAnnotationModelListeners, fAnnotations, fDocument
 
Constructor Summary
protected AbstractMarkerAnnotationModel()
          Creates a new annotation model.
 
Method Summary
protected  void addMarkerAnnotation(IMarker marker)
          Creates an annotation for the given marker and adds it to this model.
protected  void addMarkerUpdater(IMarkerUpdater markerUpdater)
          Adds the given marker updater to this annotation model.
protected  void connected()
          Connects to the source of markers as marker change listener.
protected  MarkerAnnotation createMarkerAnnotation(IMarker marker)
          Creates a new annotation for the given marker.
protected  Position createPositionFromMarker(IMarker marker)
          Creates and returns the character position of the given marker based on its attributes.
protected abstract  void deleteMarkers(IMarker[] markers)
          Deletes the given markers from this model.
protected  void disconnected()
          Removes the marker change listener.
 MarkerAnnotation getMarkerAnnotation(IMarker marker)
          Returns this model's annotation for the given marker.
 Position getMarkerPosition(IMarker marker)
          Returns the position known to this annotation model for the given marker.
protected  void handleCoreException(CoreException exception, String message)
          Handles an unanticipated CoreException in a standard manner.
protected abstract  boolean isAcceptable(IMarker marker)
          Determines whether the marker is acceptable as an addition to this model.
protected abstract  void listenToMarkerChanges(boolean listen)
          Tells the model whether it should listen for marker changes.
protected  void modifyMarkerAnnotation(IMarker marker)
          Updates the annotation corresponding to the given marker which has changed in some way.
protected  void removeAnnotations(List annotations, boolean fireModelChanged, boolean modelInitiated)
          Removes the given annotations from this model.
protected  void removeMarkerAnnotation(IMarker marker)
          Removes the annotation corresponding to the given marker.
protected  void removeMarkerUpdater(IMarkerUpdater markerUpdater)
          Removes the given marker updater from this annotation model.
 void resetMarkers()
          Resets all the markers to their original state.
protected abstract  IMarker[] retrieveMarkers()
          Retrieves all markers from this model.
 boolean updateMarker(IMarker marker, IDocument document, Position position)
          Updates the given marker according to the given position in the given document.
 void updateMarkers(IDocument document)
          Updates the markers managed by this annotation model by calling all registered marker updaters (IMarkerUpdater).
 
Methods inherited from class org.eclipse.jface.text.source.AnnotationModel
addAnnotation, addAnnotation, addAnnotationModelListener, addPosition, cleanup, connect, disconnect, fireModelChanged, fireModelChanged, getAnnotationIterator, getAnnotationIterator, getPosition, removeAllAnnotations, removeAllAnnotations, removeAnnotation, removeAnnotation, removeAnnotationModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractMarkerAnnotationModel

protected AbstractMarkerAnnotationModel()
Creates a new annotation model. The annotation model does not manage any annotations and is not connected to any document.

Method Detail

retrieveMarkers

protected abstract IMarker[] retrieveMarkers()
                                      throws CoreException
Retrieves all markers from this model.

Subclasses must implement this method.

Returns:
the list of markers
Throws:
CoreException - if there is a problem getting the markers

deleteMarkers

protected abstract void deleteMarkers(IMarker[] markers)
                               throws CoreException
Deletes the given markers from this model.

Subclasses must implement this method.

Parameters:
markers - the list of markers
Throws:
CoreException - if there are problems deleting the markers

listenToMarkerChanges

protected abstract void listenToMarkerChanges(boolean listen)
Tells the model whether it should listen for marker changes.

Subclasses must implement this method.

Parameters:
listen - true if this model should listen, and false otherwise

isAcceptable

protected abstract boolean isAcceptable(IMarker marker)
Determines whether the marker is acceptable as an addition to this model. If the marker, say, represents an aspect or range of no interest to this model, the marker is rejected.

Subclasses must implement this method.

Parameters:
marker - the marker
Returns:
true if the marker is acceptable

addMarkerUpdater

protected void addMarkerUpdater(IMarkerUpdater markerUpdater)
Adds the given marker updater to this annotation model. It is client's responsibility to ensure the consitency of the set of registered marker updaters.

Parameters:
markerUpdater - the marker updater to be added

removeMarkerUpdater

protected void removeMarkerUpdater(IMarkerUpdater markerUpdater)
Removes the given marker updater from this annotation model.

Parameters:
markerUpdater - the marker updater to be removed

createMarkerAnnotation

protected MarkerAnnotation createMarkerAnnotation(IMarker marker)
Creates a new annotation for the given marker.

Subclasses may override.

Parameters:
marker - the marker
Returns:
the new marker annotation

handleCoreException

protected void handleCoreException(CoreException exception,
                                   String message)
Handles an unanticipated CoreException in a standard manner.

Parameters:
exception - the exception
message - a message to aid debugging

createPositionFromMarker

protected Position createPositionFromMarker(IMarker marker)
Creates and returns the character position of the given marker based on its attributes.

Subclasses may override.

Parameters:
marker - the marker
Returns:
the new position or null if no valid position

addMarkerAnnotation

protected final void addMarkerAnnotation(IMarker marker)
Creates an annotation for the given marker and adds it to this model. Does nothing if the marker is not acceptable to this model.

Parameters:
marker - the marker
See Also:
isAcceptable(org.eclipse.core.resources.IMarker)

connected

protected void connected()
Connects to the source of markers as marker change listener.

Overrides:
connected in class AnnotationModel
See Also:
AnnotationModel.connected()

disconnected

protected void disconnected()
Removes the marker change listener.

Overrides:
disconnected in class AnnotationModel
See Also:
AnnotationModel.disconnected()

getMarkerPosition

public Position getMarkerPosition(IMarker marker)
Returns the position known to this annotation model for the given marker.

Parameters:
marker - the marker
Returns:
the position, or null if none

modifyMarkerAnnotation

protected void modifyMarkerAnnotation(IMarker marker)
Updates the annotation corresponding to the given marker which has changed in some way.

Subclasses may override.

Parameters:
marker - the marker

removeAnnotations

protected void removeAnnotations(List annotations,
                                 boolean fireModelChanged,
                                 boolean modelInitiated)
Description copied from class: AnnotationModel
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.

Overrides:
removeAnnotations in class AnnotationModel
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

removeMarkerAnnotation

protected final void removeMarkerAnnotation(IMarker marker)
Removes the annotation corresponding to the given marker. Does nothing if there is no annotation for this marker.

Parameters:
marker - the marker

getMarkerAnnotation

public final MarkerAnnotation getMarkerAnnotation(IMarker marker)
Returns this model's annotation for the given marker.

Parameters:
marker - the marker
Returns:
the annotation, or null if none

updateMarker

public boolean updateMarker(IMarker marker,
                            IDocument document,
                            Position position)
                     throws CoreException
Updates the given marker according to the given position in the given document. If the given position is null, the marker is assumed to carry the correct positional information. If it is detected that the marker is invalid and should thus be deleted, this method returns false.

Parameters:
marker - the marker to be updated
document - the document into which the given position points
position - the current position of the marker inside the given document
Throws:
CoreException - if there is a problem updating the marker
Since:
2.0

updateMarkers

public void updateMarkers(IDocument document)
                   throws CoreException
Updates the markers managed by this annotation model by calling all registered marker updaters (IMarkerUpdater).

Parameters:
document - the document to which this model is currently connected
Throws:
CoreException - if there is a problem updating the markers

resetMarkers

public void resetMarkers()
Resets all the markers to their original state.


Eclipse Platform
2.0

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