Search in sources :

Example 26 with Position

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;
}
Also used : TypedPosition(org.eclipse.che.ide.api.editor.text.TypedPosition) Position(org.eclipse.che.ide.api.editor.text.Position)

Example 27 with Position

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());
}
Also used : TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Position(org.eclipse.che.ide.api.editor.text.Position) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Element(elemental.dom.Element) Event(elemental.events.Event) EventListener(elemental.events.EventListener)

Example 28 with Position

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);
        }
    }
}
Also used : MarkerRegistration(org.eclipse.che.ide.api.editor.texteditor.HasTextMarkers.MarkerRegistration) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Position(org.eclipse.che.ide.api.editor.text.Position) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) TextRange(org.eclipse.che.ide.api.editor.text.TextRange)

Example 29 with Position

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());
}
Also used : TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Position(org.eclipse.che.ide.api.editor.text.Position)

Example 30 with Position

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);
                }
            }
        }
    }
}
Also used : LinearRange(org.eclipse.che.ide.api.editor.text.LinearRange) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Position(org.eclipse.che.ide.api.editor.text.Position) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Annotation(org.eclipse.che.ide.api.editor.text.annotation.Annotation)

Aggregations

Position (org.eclipse.che.ide.api.editor.text.Position)36 TextPosition (org.eclipse.che.ide.api.editor.text.TextPosition)14 TypedPosition (org.eclipse.che.ide.api.editor.text.TypedPosition)14 Annotation (org.eclipse.che.ide.api.editor.text.annotation.Annotation)8 BadPositionCategoryException (org.eclipse.che.ide.api.editor.text.BadPositionCategoryException)7 ArrayList (java.util.ArrayList)6 LinearRange (org.eclipse.che.ide.api.editor.text.LinearRange)3 Element (elemental.dom.Element)2 IdentityHashMap (java.util.IdentityHashMap)2 List (java.util.List)2 BadLocationException (org.eclipse.che.ide.api.editor.text.BadLocationException)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 Event (elemental.events.Event)1 EventListener (elemental.events.EventListener)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 DiagnosticDTO (org.eclipse.che.api.languageserver.shared.lsapi.DiagnosticDTO)1 RangeDTO (org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO)1 EditorWithAutoSave (org.eclipse.che.ide.api.editor.EditorWithAutoSave)1 AnnotationModel (org.eclipse.che.ide.api.editor.annotation.AnnotationModel)1