Search in sources :

Example 21 with IAnnotationModelExtension

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;
    }
}
Also used : Position(org.eclipse.jface.text.Position) HashMap(java.util.HashMap) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) Annotation(org.eclipse.jface.text.source.Annotation) Entry(java.util.Map.Entry) IDocument(org.eclipse.jface.text.IDocument)

Example 22 with IAnnotationModelExtension

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);
        }
    }
}
Also used : IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) Annotation(org.eclipse.jface.text.source.Annotation)

Example 23 with IAnnotationModelExtension

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());
        }
    }
}
Also used : Entry(java.util.Map.Entry) Position(org.eclipse.jface.text.Position) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) Annotation(org.eclipse.jface.text.source.Annotation)

Example 24 with IAnnotationModelExtension

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());
}
Also used : Revision(org.eclipse.jface.text.revisions.Revision) Position(org.eclipse.jface.text.Position) RevisionRange(org.eclipse.jface.text.revisions.RevisionRange) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) Annotation(org.eclipse.jface.text.source.Annotation) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 25 with IAnnotationModelExtension

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);
}
Also used : IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel)

Aggregations

IAnnotationModelExtension (org.eclipse.jface.text.source.IAnnotationModelExtension)30 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)20 Annotation (org.eclipse.jface.text.source.Annotation)14 Position (org.eclipse.jface.text.Position)12 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)6 HashMap (java.util.HashMap)5 IDocument (org.eclipse.jface.text.IDocument)5 Entry (java.util.Map.Entry)4 BadLocationException (org.eclipse.jface.text.BadLocationException)4 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)4 IEditorInput (org.eclipse.ui.IEditorInput)4 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Matcher (java.util.regex.Matcher)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 IRegion (org.eclipse.jface.text.IRegion)2 ITextViewer (org.eclipse.jface.text.ITextViewer)2 AnnotationModel (org.eclipse.jface.text.source.AnnotationModel)2 IChangeRulerColumn (org.eclipse.jface.text.source.IChangeRulerColumn)2 ILineDifferExtension (org.eclipse.jface.text.source.ILineDifferExtension)2