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