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());
}
}
}
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);
}
}
}
}
}
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;
}
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;
}
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);
}
}
Aggregations