use of org.eclipse.jface.text.source.IAnnotationModelExtension in project eclipse.platform.text by eclipse.
the class InlinedAnnotationSupport method updateAnnotations.
/**
* Update the given inlined annotation.
*
* @param annotations the inlined annotation.
*/
public void updateAnnotations(Set<AbstractInlinedAnnotation> annotations) {
IDocument document = fViewer != null ? fViewer.getDocument() : null;
if (document == null) {
// this case comes from when editor is closed before rendered is done.
return;
}
IAnnotationModel annotationModel = fViewer.getAnnotationModel();
if (annotationModel == null) {
return;
}
Map<AbstractInlinedAnnotation, Position> annotationsToAdd = new HashMap<>();
List<AbstractInlinedAnnotation> annotationsToRemove = fInlinedAnnotations != null ? new ArrayList<>(fInlinedAnnotations) : Collections.emptyList();
// Loop for annotations to update
for (AbstractInlinedAnnotation ann : annotations) {
if (!annotationsToRemove.remove(ann)) {
// The annotation was not created, add it
annotationsToAdd.put(ann, ann.getPosition());
}
}
// Process annotations to remove
for (AbstractInlinedAnnotation ann : annotationsToRemove) {
// Mark annotation as deleted to ignore the draw
ann.markDeleted(true);
}
// Update annotation model
synchronized (getLockObject(annotationModel)) {
// Update annotations with this inlined annotation support.
for (AbstractInlinedAnnotation ann : annotations) {
ann.setSupport(this);
}
if (annotationsToAdd.size() == 0 && annotationsToRemove.size() == 0) {
// None change, do nothing. Here the user could change position of codemining
// range
// (ex: user key press
// "Enter"), but we don't need to redraw the viewer because change of position
// is done by AnnotationPainter.
} else {
if (annotationModel instanceof IAnnotationModelExtension) {
((IAnnotationModelExtension) annotationModel).replaceAnnotations(annotationsToRemove.toArray(new Annotation[annotationsToRemove.size()]), annotationsToAdd);
} else {
removeInlinedAnnotations();
Iterator<Entry<AbstractInlinedAnnotation, Position>> iter = annotationsToAdd.entrySet().iterator();
while (iter.hasNext()) {
Entry<AbstractInlinedAnnotation, Position> mapEntry = iter.next();
annotationModel.addAnnotation(mapEntry.getKey(), mapEntry.getValue());
}
}
}
fInlinedAnnotations = annotations;
}
}
use of org.eclipse.jface.text.source.IAnnotationModelExtension in project eclipse.platform.text by eclipse.
the class AnnotationHighlighter method removeAnnotations.
/**
* Removes annotations from the given annotation model. The default implementation works for editors that
* implement <code>ITextEditor</code>.
* Subclasses may override this method.
* @param annotations A set containing the annotations to be removed.
* @see Annotation
*/
private void removeAnnotations(Collection<Annotation> annotations) {
if (fModel instanceof IAnnotationModelExtension) {
IAnnotationModelExtension ame = (IAnnotationModelExtension) fModel;
Annotation[] annotationArray = new Annotation[annotations.size()];
ame.replaceAnnotations(annotations.toArray(annotationArray), Collections.emptyMap());
} else {
for (Annotation element : annotations) {
fModel.removeAnnotation(element);
}
}
}
use of org.eclipse.jface.text.source.IAnnotationModelExtension in project eclipse.platform.text by eclipse.
the class AnnotationHighlighter method addAnnotations.
private void addAnnotations(Map<Annotation, Position> annotationToPositionMap) {
if (fModel instanceof IAnnotationModelExtension) {
IAnnotationModelExtension ame = (IAnnotationModelExtension) fModel;
ame.replaceAnnotations(new Annotation[0], annotationToPositionMap);
} else {
Set<Entry<Annotation, Position>> entrySet = annotationToPositionMap.entrySet();
for (Entry<Annotation, Position> entry : entrySet) {
fModel.addAnnotation(entry.getKey(), entry.getValue());
}
}
}
use of org.eclipse.jface.text.source.IAnnotationModelExtension in project eclipse.platform.text by eclipse.
the class RevisionPainter method updateOverviewAnnotations.
/**
* Shows (or hides) the overview annotations.
*/
private void updateOverviewAnnotations() {
if (fAnnotationModel == null)
return;
Revision revision = fFocusRevision != null ? fFocusRevision : fSelectedRevision;
Map<Annotation, Position> added = null;
if (revision != null) {
added = new HashMap<>();
for (RevisionRange range : revision.getRegions()) {
try {
IRegion charRegion = toCharRegion(range);
Position position = new Position(charRegion.getOffset(), charRegion.getLength());
Annotation annotation = new RevisionAnnotation(revision.getId());
added.put(annotation, position);
} catch (BadLocationException x) {
// ignore - document was changed, show no annotations
}
}
}
if (fAnnotationModel instanceof IAnnotationModelExtension) {
IAnnotationModelExtension ext = (IAnnotationModelExtension) fAnnotationModel;
ext.replaceAnnotations(fAnnotations.toArray(new Annotation[fAnnotations.size()]), added);
} else {
for (Annotation annotation : fAnnotations) {
fAnnotationModel.removeAnnotation(annotation);
}
if (added != null) {
for (Entry<Annotation, Position> entry : added.entrySet()) {
fAnnotationModel.addAnnotation(entry.getKey(), entry.getValue());
}
}
}
fAnnotations.clear();
if (added != null)
fAnnotations.addAll(added.keySet());
}
use of org.eclipse.jface.text.source.IAnnotationModelExtension in project eclipse.platform.text by eclipse.
the class DiffPainter method setModel.
/**
* Sets the annotation model.
*
* @param model the annotation model, possibly <code>null</code>
* @see IVerticalRulerColumn#setModel(IAnnotationModel)
*/
public void setModel(IAnnotationModel model) {
IAnnotationModel newModel;
if (model instanceof IAnnotationModelExtension)
newModel = ((IAnnotationModelExtension) model).getAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID);
else
newModel = model;
setDiffer(newModel);
}
Aggregations