Search in sources :

Example 1 with Annotation

use of org.eclipse.che.ide.api.editor.text.annotation.Annotation in project che by eclipse.

the class AnnotationModelImpl method onQueryAnnotations.

@Override
public void onQueryAnnotations(final QueryAnnotationsEvent event) {
    final QueryAnnotationsEvent.QueryCallback callback = event.getCallback();
    if (callback == null) {
        return;
    }
    final LinearRange range = event.getRange();
    Iterator<Annotation> iterator;
    if (range == null) {
        iterator = getAnnotationIterator();
    } else {
        iterator = getAnnotationIterator(range.getStartOffset(), range.getLength(), true, true);
    }
    final QueryAnnotationsEvent.AnnotationFilter filter = event.getAdditionalFilter();
    final Map<Annotation, Position> result = new HashMap<>();
    while (iterator.hasNext()) {
        final Annotation annotation = iterator.next();
        if (filter.accept(annotation)) {
            result.put(annotation, this.annotations.get(annotation));
        }
    }
    callback.respond(result);
}
Also used : LinearRange(org.eclipse.che.ide.api.editor.text.LinearRange) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Position(org.eclipse.che.ide.api.editor.text.Position) TypedPosition(org.eclipse.che.ide.api.editor.text.TypedPosition) Annotation(org.eclipse.che.ide.api.editor.text.annotation.Annotation)

Example 2 with Annotation

use of org.eclipse.che.ide.api.editor.text.annotation.Annotation in project che by eclipse.

the class AnnotationModelImpl method cleanup.

/**
     * Removes all annotations from the model whose associated positions have been deleted. If requested inform all model listeners about
     * the change. If requested a new thread is created for the notification of the model listeners.
     *
     * @param fireModelChanged indicates whether to notify all model listeners
     */
private void cleanup(final boolean fireModelChanged) {
    if (documentChanged) {
        documentChanged = false;
        final List<Annotation> deleted = new ArrayList<Annotation>();
        final Iterator<Annotation> e = getAnnotationIterator();
        while (e.hasNext()) {
            final Annotation annotation = e.next();
            final Position pos = annotations.get(annotation);
            if (pos == null || pos.isDeleted()) {
                deleted.add(annotation);
            }
        }
        if (fireModelChanged) {
            removeAnnotations(deleted, false);
            if (modelEvent != null) {
                Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                    @Override
                    public void execute() {
                        fireModelChanged();
                    }
                });
            }
        } else {
            removeAnnotations(deleted, fireModelChanged);
        }
    }
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Position(org.eclipse.che.ide.api.editor.text.Position) TypedPosition(org.eclipse.che.ide.api.editor.text.TypedPosition) ArrayList(java.util.ArrayList) Annotation(org.eclipse.che.ide.api.editor.text.annotation.Annotation)

Example 3 with Annotation

use of org.eclipse.che.ide.api.editor.text.annotation.Annotation in project che by eclipse.

the class AnnotationModelImpl method forgetLines.

// TODO evaluate: keep?
private void forgetLines(final int fromLine, final int count, final boolean checkCount) {
    // use an iterator to have remove()
    final Iterator<Entry<Annotation, Position>> iterator = this.annotations.entrySet().iterator();
    while (iterator.hasNext()) {
        final Entry<Annotation, Position> entry = iterator.next();
        final Position position = entry.getValue();
        final TextPosition textPos = docHandle.getDocument().getPositionFromIndex(position.getOffset());
        final int line = textPos.getLine();
        if (line >= fromLine && (!checkCount || line < fromLine + count)) {
            iterator.remove();
        }
    }
}
Also used : Entry(java.util.Map.Entry) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Position(org.eclipse.che.ide.api.editor.text.Position) TypedPosition(org.eclipse.che.ide.api.editor.text.TypedPosition) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Annotation(org.eclipse.che.ide.api.editor.text.annotation.Annotation)

Example 4 with Annotation

use of org.eclipse.che.ide.api.editor.text.annotation.Annotation in project che by eclipse.

the class AnnotationModelImpl method shiftLines.

// TODO evaluate: keep?
public void shiftLines(final int fromLine, final int lineDelta, final int charDelta) {
    final Map<Annotation, Position> modified = new IdentityHashMap<>();
    for (final Entry<Annotation, Position> entry : this.annotations.entrySet()) {
        final Position position = entry.getValue();
        final TextPosition textPos = docHandle.getDocument().getPositionFromIndex(position.getOffset());
        int horizontal;
        if (textPos.getLine() == fromLine) {
            horizontal = charDelta;
        } else if (textPos.getLine() >= fromLine) {
            horizontal = 0;
        } else {
            continue;
        }
        final TextPosition newTextPos = new TextPosition(fromLine + lineDelta, textPos.getCharacter() + horizontal);
        final int newOffset = docHandle.getDocument().getIndexFromPosition(newTextPos);
        final Position newPos = new Position(newOffset, position.getLength());
        modified.put(entry.getKey(), newPos);
    }
    // merge changes in the annotartion map
    this.annotations.putAll(modified);
}
Also used : TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Position(org.eclipse.che.ide.api.editor.text.Position) TypedPosition(org.eclipse.che.ide.api.editor.text.TypedPosition) IdentityHashMap(java.util.IdentityHashMap) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Annotation(org.eclipse.che.ide.api.editor.text.annotation.Annotation)

Example 5 with Annotation

use of org.eclipse.che.ide.api.editor.text.annotation.Annotation in project che by eclipse.

the class GutterAnnotationRenderer method onAnnotationModel.

@Override
public void onAnnotationModel(final AnnotationModelEvent event) {
    // remove removed and changed annotations
    for (final Annotation annotation : event.getRemovedAnnotations()) {
        LOG.fine("Remove annotation: " + annotation);
        removeAnnotationItem(event, annotation);
    }
    for (final Annotation annotation : event.getChangedAnnotations()) {
        LOG.fine("Remove changed annotation: " + annotation);
        removeAnnotationItem(event, annotation);
    }
    // add new and changed (new version) annotation
    for (final Annotation annotation : event.getAddedAnnotations()) {
        LOG.fine("Add annotation: " + annotation);
        addAnnotationItem(event.getAnnotationModel(), annotation);
    }
    for (final Annotation annotation : event.getChangedAnnotations()) {
        LOG.fine("Add back changed annotation: " + annotation);
        addAnnotationItem(event.getAnnotationModel(), annotation);
    }
}
Also used : Annotation(org.eclipse.che.ide.api.editor.text.annotation.Annotation)

Aggregations

Annotation (org.eclipse.che.ide.api.editor.text.annotation.Annotation)13 Position (org.eclipse.che.ide.api.editor.text.Position)8 TextPosition (org.eclipse.che.ide.api.editor.text.TextPosition)5 ArrayList (java.util.ArrayList)4 LinearRange (org.eclipse.che.ide.api.editor.text.LinearRange)4 TypedPosition (org.eclipse.che.ide.api.editor.text.TypedPosition)4 HashMap (java.util.HashMap)2 IdentityHashMap (java.util.IdentityHashMap)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 NoSuchElementException (java.util.NoSuchElementException)1 AnnotationModel (org.eclipse.che.ide.api.editor.annotation.AnnotationModel)1 QueryAnnotationsEvent (org.eclipse.che.ide.api.editor.annotation.QueryAnnotationsEvent)1 Document (org.eclipse.che.ide.api.editor.document.Document)1 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)1 OrionProblemOverlay (org.eclipse.che.ide.editor.orion.client.jso.OrionProblemOverlay)1 Problem (org.eclipse.che.ide.ext.java.shared.dto.Problem)1