Search in sources :

Example 26 with IAnnotationModelExtension

use of org.eclipse.jface.text.source.IAnnotationModelExtension in project eclipse.platform.text by eclipse.

the class ProjectionViewer method removeProjectionAnnotationModel.

/**
 * Removes the projection annotation model from the given annotation model.
 *
 * @param model the mode from which the projection annotation model is removed
 * @return the removed projection annotation model or <code>null</code> if there was none
 */
private IAnnotationModel removeProjectionAnnotationModel(IAnnotationModel model) {
    if (model instanceof IAnnotationModelExtension) {
        model.removeAnnotationModelListener(fAnnotationModelListener);
        IAnnotationModelExtension extension = (IAnnotationModelExtension) model;
        return extension.removeAnnotationModel(ProjectionSupport.PROJECTION);
    }
    return null;
}
Also used : IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension)

Example 27 with IAnnotationModelExtension

use of org.eclipse.jface.text.source.IAnnotationModelExtension in project eclipse.platform.text by eclipse.

the class ProjectionViewer method addProjectionAnnotationModel.

/**
 * Adds the projection annotation model to the given annotation model.
 *
 * @param model the model to which the projection annotation model is added
 */
private void addProjectionAnnotationModel(IAnnotationModel model) {
    if (model instanceof IAnnotationModelExtension) {
        IAnnotationModelExtension extension = (IAnnotationModelExtension) model;
        extension.addAnnotationModel(ProjectionSupport.PROJECTION, fProjectionAnnotationModel);
        model.addAnnotationModelListener(fAnnotationModelListener);
    }
}
Also used : IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension)

Example 28 with IAnnotationModelExtension

use of org.eclipse.jface.text.source.IAnnotationModelExtension in project eclipse.platform.text by eclipse.

the class ProjectionRulerColumn method setModel.

@Override
public void setModel(IAnnotationModel model) {
    if (model instanceof IAnnotationModelExtension) {
        IAnnotationModelExtension extension = (IAnnotationModelExtension) model;
        model = extension.getAnnotationModel(ProjectionSupport.PROJECTION);
    }
    super.setModel(model);
}
Also used : IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension)

Example 29 with IAnnotationModelExtension

use of org.eclipse.jface.text.source.IAnnotationModelExtension in project eclipse.platform.text by eclipse.

the class ProjectionSummary method createSummaries.

private void createSummaries(IProgressMonitor monitor, IAnnotationModel visualAnnotationModel) {
    ProjectionAnnotationModel model = fProjectionViewer.getProjectionAnnotationModel();
    if (model == null)
        return;
    Map<Annotation, Position> additions = new HashMap<>();
    Iterator<Annotation> e = model.getAnnotationIterator();
    while (e.hasNext()) {
        ProjectionAnnotation projection = (ProjectionAnnotation) e.next();
        if (projection.isCollapsed()) {
            Position position = model.getPosition(projection);
            if (position != null) {
                IRegion[] summaryRegions = fProjectionViewer.computeCollapsedRegions(position);
                if (summaryRegions != null) {
                    Position summaryAnchor = fProjectionViewer.computeCollapsedRegionAnchor(position);
                    if (summaryAnchor != null)
                        createSummary(additions, summaryRegions, summaryAnchor);
                }
            }
        }
        if (isCanceled(monitor))
            return;
    }
    if (additions.size() > 0) {
        if (visualAnnotationModel instanceof IAnnotationModelExtension) {
            IAnnotationModelExtension extension = (IAnnotationModelExtension) visualAnnotationModel;
            if (!isCanceled(monitor))
                extension.replaceAnnotations(null, additions);
        } else {
            Iterator<Annotation> e1 = additions.keySet().iterator();
            while (e1.hasNext()) {
                AnnotationBag bag = (AnnotationBag) e1.next();
                Position position = additions.get(bag);
                if (isCanceled(monitor))
                    return;
                visualAnnotationModel.addAnnotation(bag, position);
            }
        }
    }
}
Also used : Position(org.eclipse.jface.text.Position) HashMap(java.util.HashMap) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) Annotation(org.eclipse.jface.text.source.Annotation) IRegion(org.eclipse.jface.text.IRegion)

Example 30 with IAnnotationModelExtension

use of org.eclipse.jface.text.source.IAnnotationModelExtension in project eclipse.platform.text by eclipse.

the class ProjectionSummary method removeSummaries.

private void removeSummaries(IProgressMonitor monitor, IAnnotationModel visualAnnotationModel) {
    IAnnotationModelExtension extension = null;
    List<Annotation> bags = null;
    if (visualAnnotationModel instanceof IAnnotationModelExtension) {
        extension = (IAnnotationModelExtension) visualAnnotationModel;
        bags = new ArrayList<>();
    }
    Iterator<Annotation> e = visualAnnotationModel.getAnnotationIterator();
    while (e.hasNext()) {
        Annotation annotation = e.next();
        if (annotation instanceof AnnotationBag) {
            if (bags == null)
                visualAnnotationModel.removeAnnotation(annotation);
            else
                bags.add(annotation);
        }
        if (isCanceled(monitor))
            return;
    }
    if (bags != null && bags.size() > 0) {
        Annotation[] deletions = new Annotation[bags.size()];
        bags.toArray(deletions);
        if (!isCanceled(monitor))
            extension.replaceAnnotations(deletions, null);
    }
}
Also used : IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) Annotation(org.eclipse.jface.text.source.Annotation)

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