final IDocumentProvider documentProvider = editor.getDocumentProvider();
if (documentProvider == null) {
return Status.CANCEL_STATUS;
}
final IAnnotationModel annotationModel = documentProvider
.getAnnotationModel(editor.getEditorInput());
if (annotationModel == null) {
return Status.CANCEL_STATUS;
}
// Add occurrence annotations
final HashMap<Annotation, Position> annotationMap = new HashMap<Annotation, Position>(
fRefs.size());
for (final MarkOccurencesSupport.ErlangRef ref : fRefs) {
if (isCanceled(progressMonitor)) {
return Status.CANCEL_STATUS;
}
final Position position = new Position(ref.getOffset(), ref.getLength());
final String description = ref.getDescription();
final String annotationType = ref.isDef() ? "org.erlide.ui.occurrences.definition" //$NON-NLS-1$
: "org.erlide.ui.occurrences";
annotationMap.put(new Annotation(annotationType, false, description),
position);
}
if (isCanceled(progressMonitor)) {
return Status.CANCEL_STATUS;
}
synchronized (editor.getLockObject(annotationModel)) {
if (annotationModel instanceof IAnnotationModelExtension) {
((IAnnotationModelExtension) annotationModel).replaceAnnotations(
editor.markOccurencesHandler.fOccurrenceAnnotations,
annotationMap);
} else {
editor.markOccurencesHandler.removeOccurrenceAnnotations();
for (final Map.Entry<Annotation, Position> mapEntry : annotationMap
.entrySet()) {
annotationModel.addAnnotation(mapEntry.getKey(),
mapEntry.getValue());
}
}
editor.markOccurencesHandler.fOccurrenceAnnotations = annotationMap
.keySet().toArray(new Annotation[annotationMap.keySet().size()]);