use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.
the class AnnotationsIterator method findNext.
private Annotation findNext() {
while (index < positions.size()) {
final Position position = positions.get(index);
index++;
if (map.containsKey(position)) {
return map.get(position);
}
}
return null;
}
use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.
the class GutterAnnotationRenderer method addAnnotationItem.
private void addAnnotationItem(final AnnotationModel model, final Annotation annotation) {
final Position position = model.getPosition(annotation);
if (position == null) {
Log.warn(GutterAnnotationRenderer.class, "No position for annotation " + annotation);
return;
}
final TextPosition textPosition = this.document.getPositionFromIndex(position.getOffset());
final Element annotationItem = this.hasGutter.getGutterItem(textPosition.getLine(), ANNOTATION_GUTTER);
AnnotationGroup annotationGroup;
if (!AnnotationGroupImpl.isAnnotation(annotationItem)) {
LOG.fine("Create new annotation group for line " + textPosition.getLine());
final AnnotationGroup newGroup = AnnotationGroupImpl.create();
newGroup.getElement().addEventListener(Event.MOUSEOVER, new EventListener() {
@Override
public void handleEvent(final Event evt) {
showToolTip(newGroup, textPosition.getLine());
}
}, false);
this.hasGutter.addGutterItem(textPosition.getLine(), ANNOTATION_GUTTER, newGroup.getElement());
annotationGroup = newGroup;
} else {
LOG.fine("Reuse annotation group for line " + textPosition.getLine());
annotationGroup = AnnotationGroupImpl.create(annotationItem);
}
annotationGroup.addAnnotation(annotation, position.getOffset());
}
use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.
the class InlineAnnotationRenderer method addAnnotationItem.
/**
* Add an inline annotation.
*
* @param annotationModel the annotation model
* @param annotation the annotation to add
* @param decorations the available decorations
*/
private void addAnnotationItem(AnnotationModel annotationModel, Annotation annotation, Map<String, String> decorations) {
if (this.hasTextMarkers != null) {
final String className = decorations.get(annotation.getType());
if (className == null) {
return;
}
final Position position = annotationModel.getPosition(annotation);
if (position == null) {
Log.warn(InlineAnnotationRenderer.class, "Can't add annotation with no position");
return;
}
final TextPosition from = this.document.getPositionFromIndex(position.getOffset());
final TextPosition to = this.document.getPositionFromIndex(position.getOffset() + position.getLength());
final MarkerRegistration registration = this.hasTextMarkers.addMarker(new TextRange(from, to), className);
if (registration != null) {
this.markers.put(annotation, registration);
}
}
}
use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.
the class MinimapAnnotationRenderer method addAnnotationItem.
private void addAnnotationItem(final AnnotationModel model, final Annotation annotation, final Map<String, String> decorations) {
final Position position = model.getPosition(annotation);
if (position == null) {
Log.warn(MinimapAnnotationRenderer.class, "No position for annotation " + annotation);
return;
}
// final TextPosition textPosition = this.document.getPositionFromIndex(position.getOffset());
// final int line = textPosition.getLine();
final String style = decorations.get(annotation.getType());
this.minimap.addMark(position.getOffset(), style, annotation.getLayer(), annotation.getText());
}
use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.
the class MinimapAnnotationRenderer method removeAnnotationItem.
private void removeAnnotationItem(final AnnotationModelEvent event, final Annotation annotation, final Map<Integer, List<Annotation>> toRestore) {
final Position position = event.getPositionOfRemovedAnnotation(annotation);
final TextPosition textPosition = this.document.getPositionFromIndex(position.getOffset());
final int line = textPosition.getLine();
// remove all marks on the line
this.minimap.removeMarks(line, line);
// restore marks that are not removed
final LinearRange rangeForLine = this.document.getLinearRangeForLine(line);
final AnnotationModel model = event.getAnnotationModel();
final Iterator<Annotation> it = model.getAnnotationIterator(rangeForLine.getStartOffset(), rangeForLine.getLength(), false, true);
while (it.hasNext()) {
final Annotation current = it.next();
List<Annotation> lineAnnotations = toRestore.get(line);
if (!current.equals(annotation)) {
if (lineAnnotations == null) {
lineAnnotations = new ArrayList<>();
toRestore.put(line, lineAnnotations);
}
lineAnnotations.add(current);
} else {
if (lineAnnotations != null) {
lineAnnotations.removeAll(Collections.singletonList(current));
if (lineAnnotations.isEmpty()) {
toRestore.remove(line);
}
}
}
}
}
Aggregations