use of org.eclipse.jface.text.source.IAnnotationModel in project eclipse.platform.text by eclipse.
the class MarkerRulerAction method getAnnotationModel.
/**
* Returns the <code>AbstractMarkerAnnotationModel</code> of the editor's input.
*
* @return the marker annotation model
*/
protected AbstractMarkerAnnotationModel getAnnotationModel() {
IDocumentProvider provider = fTextEditor.getDocumentProvider();
IAnnotationModel model = provider.getAnnotationModel(fTextEditor.getEditorInput());
if (model instanceof AbstractMarkerAnnotationModel)
return (AbstractMarkerAnnotationModel) model;
return null;
}
use of org.eclipse.jface.text.source.IAnnotationModel in project eclipse.platform.text by eclipse.
the class SelectMarkerRulerAction method getAnnotationModel.
/**
* Returns the <code>AbstractMarkerAnnotationModel</code> of the editor's input.
*
* @return the marker annotation model or <code>null</code> if there's none
*/
protected final AbstractMarkerAnnotationModel getAnnotationModel() {
IDocumentProvider provider = fTextEditor.getDocumentProvider();
IAnnotationModel model = provider.getAnnotationModel(fTextEditor.getEditorInput());
if (model instanceof AbstractMarkerAnnotationModel)
return (AbstractMarkerAnnotationModel) model;
return null;
}
use of org.eclipse.jface.text.source.IAnnotationModel in project eclipse.platform.text by eclipse.
the class QuickDiffRestoreAction method getModel.
/**
* Returns the annotation model of the document displayed in this action's editor, if it
* implements the {@link IAnnotationModelExtension IAnnotationModelExtension} interface.
*
* @return the displayed document's annotation model if it is an <code>IAnnotationModelExtension</code>, or <code>null</code>
*/
private IAnnotationModelExtension getModel() {
if (getTextEditor() == null)
return null;
IDocumentProvider provider = getTextEditor().getDocumentProvider();
IEditorInput editorInput = getTextEditor().getEditorInput();
IAnnotationModel m = provider.getAnnotationModel(editorInput);
if (m instanceof IAnnotationModelExtension)
return (IAnnotationModelExtension) m;
return null;
}
use of org.eclipse.jface.text.source.IAnnotationModel in project eclipse.platform.text by eclipse.
the class ReferenceSelectionAction method getDiffer.
/**
* Fetches the differ installed with the current editor's document's annotation model. If none
* is installed yet, and <code>createIfNeeded</code> is true, one is created and attached to the
* model.
*
* @param createIfNeeded when set to <code>true</code>, a new differ will be created if needed.
* @return the differ installed with the annotation model, or <code>null</code>.
*/
private DocumentLineDiffer getDiffer(boolean createIfNeeded) {
// get annotation model
if (fEditor == null)
return null;
IDocumentProvider provider = fEditor.getDocumentProvider();
IEditorInput editorInput = fEditor.getEditorInput();
if (provider == null || editorInput == null)
return null;
IAnnotationModel m = provider.getAnnotationModel(editorInput);
IAnnotationModelExtension model = null;
if (m instanceof IAnnotationModelExtension) {
model = (IAnnotationModelExtension) m;
} else {
return null;
}
// get differ
DocumentLineDiffer differ = (DocumentLineDiffer) model.getAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID);
// create if needed
if (differ == null && createIfNeeded) {
differ = new DocumentLineDiffer();
model.addAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID, differ);
}
return differ;
}
use of org.eclipse.jface.text.source.IAnnotationModel in project eclipse.platform.text by eclipse.
the class HighlightStrategy method applyHighlights.
private void applyHighlights(int offset) {
if (sourceViewer == null || !enabled) {
return;
}
String text = document.get();
offset = ((ITextViewerExtension5) sourceViewer).widgetOffset2ModelOffset(offset);
int wordStartOffset = Math.max(text.lastIndexOf('/', offset), text.lastIndexOf('<', offset)) + 1;
int wordEndOffset = findEndingOffset(text, offset);
if (wordEndOffset <= wordStartOffset || wordEndOffset == -1 || wordStartOffset == -1)
return;
String word = text.substring(wordStartOffset, wordEndOffset);
if (word.indexOf('>') != -1 || word.indexOf('<') != -1) {
removeOccurrenceAnnotations();
return;
}
Matcher m = TAG_NAME_PATTERN.matcher(text);
Map<Annotation, Position> annotationMap = new HashMap<>();
while (m.find()) {
if (m.group(1).equals(word)) {
annotationMap.put(new Annotation(ANNOTATION_TYPE, false, null), new Position(m.start(1), m.end(1) - m.start(1)));
}
}
if (annotationMap.size() < 2) {
removeOccurrenceAnnotations();
return;
}
IAnnotationModel annotationModel = sourceViewer.getAnnotationModel();
synchronized (getLockObject(annotationModel)) {
if (annotationModel instanceof IAnnotationModelExtension) {
((IAnnotationModelExtension) annotationModel).replaceAnnotations(fOccurrenceAnnotations, annotationMap);
} else {
removeOccurrenceAnnotations();
Iterator<Entry<Annotation, Position>> iter = annotationMap.entrySet().iterator();
while (iter.hasNext()) {
Entry<Annotation, Position> mapEntry = iter.next();
annotationModel.addAnnotation(mapEntry.getKey(), mapEntry.getValue());
}
}
fOccurrenceAnnotations = annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]);
}
}
Aggregations