Search in sources :

Example 26 with IAnnotationModel

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

the class LinkedModeUI method uninstallAnnotationModel.

private void uninstallAnnotationModel(LinkedModeUITarget target) {
    ITextViewer viewer = target.getViewer();
    if (viewer instanceof ISourceViewer) {
        ISourceViewer sv = (ISourceViewer) viewer;
        IAnnotationModel model = sv.getAnnotationModel();
        if (model instanceof IAnnotationModelExtension) {
            IAnnotationModelExtension ext = (IAnnotationModelExtension) model;
            ext.removeAnnotationModel(getUniqueKey());
        }
    }
}
Also used : IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 27 with IAnnotationModel

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

the class LinkedModeUI method ensureAnnotationModelInstalled.

private void ensureAnnotationModelInstalled() {
    LinkedPositionAnnotations lpa = fCurrentTarget.fAnnotationModel;
    if (lpa != null) {
        ITextViewer viewer = fCurrentTarget.getViewer();
        if (viewer instanceof ISourceViewer) {
            ISourceViewer sv = (ISourceViewer) viewer;
            IAnnotationModel model = sv.getAnnotationModel();
            if (model instanceof IAnnotationModelExtension) {
                IAnnotationModelExtension ext = (IAnnotationModelExtension) model;
                IAnnotationModel ourModel = ext.getAnnotationModel(getUniqueKey());
                if (ourModel == null) {
                    ext.addAnnotationModel(getUniqueKey(), lpa);
                }
            }
        }
    }
}
Also used : IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 28 with IAnnotationModel

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

the class ProjectionAnnotationHover method getProjectionTextAtLine.

private String getProjectionTextAtLine(ISourceViewer viewer, int line, int numberOfLines) {
    IAnnotationModel model = null;
    if (viewer instanceof ISourceViewerExtension2) {
        ISourceViewerExtension2 viewerExtension = (ISourceViewerExtension2) viewer;
        IAnnotationModel visual = viewerExtension.getVisualAnnotationModel();
        if (visual instanceof IAnnotationModelExtension) {
            IAnnotationModelExtension modelExtension = (IAnnotationModelExtension) visual;
            model = modelExtension.getAnnotationModel(ProjectionSupport.PROJECTION);
        }
    }
    if (model != null) {
        try {
            IDocument document = viewer.getDocument();
            Iterator<Annotation> e = model.getAnnotationIterator();
            while (e.hasNext()) {
                ProjectionAnnotation annotation = (ProjectionAnnotation) e.next();
                if (!annotation.isCollapsed())
                    continue;
                Position position = model.getPosition(annotation);
                if (position == null)
                    continue;
                if (isCaptionLine(position, document, line))
                    return getText(document, position.getOffset(), position.getLength(), numberOfLines);
            }
        } catch (BadLocationException x) {
        }
    }
    return null;
}
Also used : Position(org.eclipse.jface.text.Position) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IDocument(org.eclipse.jface.text.IDocument) Annotation(org.eclipse.jface.text.source.Annotation) BadLocationException(org.eclipse.jface.text.BadLocationException) ISourceViewerExtension2(org.eclipse.jface.text.source.ISourceViewerExtension2)

Example 29 with IAnnotationModel

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

the class ProjectionRulerColumn method findAnnotation.

/**
 * Returns the projection annotation of the column's annotation
 * model that contains the given line.
 *
 * @param line the line
 * @param exact <code>true</code> if the annotation range must match exactly
 * @return the projection annotation containing the given line
 */
private ProjectionAnnotation findAnnotation(int line, boolean exact) {
    ProjectionAnnotation previousAnnotation = null;
    IAnnotationModel model = getModel();
    if (model != null) {
        IDocument document = getCachedTextViewer().getDocument();
        int previousDistance = Integer.MAX_VALUE;
        Iterator<Annotation> e = model.getAnnotationIterator();
        while (e.hasNext()) {
            Object next = e.next();
            if (next instanceof ProjectionAnnotation) {
                ProjectionAnnotation annotation = (ProjectionAnnotation) next;
                Position p = model.getPosition(annotation);
                if (p == null)
                    continue;
                int distance = getDistance(annotation, p, document, line);
                if (distance == -1)
                    continue;
                if (!exact) {
                    if (distance < previousDistance) {
                        previousAnnotation = annotation;
                        previousDistance = distance;
                    }
                } else if (distance == 0) {
                    previousAnnotation = annotation;
                }
            }
        }
    }
    return previousAnnotation;
}
Also used : Position(org.eclipse.jface.text.Position) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IDocument(org.eclipse.jface.text.IDocument) Annotation(org.eclipse.jface.text.source.Annotation)

Example 30 with IAnnotationModel

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

the class FileStoreFileBufferFunctions method test18.

/*
	 * Test annotation model existence.
	 * ATTENTION: This test is only effective in a workspace that contains the "org.eclipse.ui.editors" bundle.
	 */
@Test
public void test18() throws Exception {
    fManager.connectFileStore(fFileStore, null);
    try {
        ITextFileBuffer buffer = fManager.getFileStoreTextFileBuffer(fFileStore);
        assertNotNull(buffer);
        Class<IAnnotationModel> clazz = getAnnotationModelClass();
        if (clazz != null) {
            IAnnotationModel model = buffer.getAnnotationModel();
            assertTrue(clazz.isInstance(model));
        }
    } finally {
        fManager.disconnectFileStore(fFileStore, null);
    }
}
Also used : ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) Test(org.junit.Test)

Aggregations

IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)148 Annotation (org.eclipse.jface.text.source.Annotation)71 Position (org.eclipse.jface.text.Position)58 IDocument (org.eclipse.jface.text.IDocument)41 IAnnotationModelExtension (org.eclipse.jface.text.source.IAnnotationModelExtension)26 Iterator (java.util.Iterator)23 ArrayList (java.util.ArrayList)20 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)20 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)19 MarkerAnnotation (org.eclipse.ui.texteditor.MarkerAnnotation)19 BadLocationException (org.eclipse.jface.text.BadLocationException)18 IFile (org.eclipse.core.resources.IFile)17 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)16 IEditorInput (org.eclipse.ui.IEditorInput)13 Test (org.junit.Test)13 HashMap (java.util.HashMap)12 List (java.util.List)12 CoreException (org.eclipse.core.runtime.CoreException)11 IMarker (org.eclipse.core.resources.IMarker)10 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)10