use of org.eclipse.jface.text.source.Annotation in project dbeaver by serge-rider.
the class SQLAnnotationHover method findAnnotations.
/**
* Finds annotations either by offset or by lineNumber
*/
private void findAnnotations(int offset, IAnnotationModel model, IDocument document, int lineNumber) {
annotations.clear();
if (model == null) {
if (editor != null) {
ITextEditor editor = this.editor;
model = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
}
}
if (model == null) {
return;
}
for (Iterator<?> it = model.getAnnotationIterator(); it.hasNext(); ) {
Annotation annotation = (Annotation) it.next();
Position position = model.getPosition(annotation);
//if position is null, just return.
if (position == null) {
return;
}
try {
if (position.overlapsWith(offset, 1) || document != null && document.getLineOfOffset(position.offset) == lineNumber) {
annotations.add(annotation);
}
} catch (BadLocationException e) {
log.error(e);
}
}
}
use of org.eclipse.jface.text.source.Annotation in project dbeaver by serge-rider.
the class SQLReconcilingStrategy method calculatePositions.
protected void calculatePositions() {
ProjectionAnnotationModel annotationModel = editor.getAnnotationModel();
if (annotationModel == null) {
return;
}
Set<SQLScriptPosition> removedPositions = editor.getRuleManager().getRemovedPositions(true);
Set<SQLScriptPosition> addedPositions = editor.getRuleManager().getAddedPositions(true);
Annotation[] removedAnnotations = null;
if (!removedPositions.isEmpty()) {
removedAnnotations = new Annotation[removedPositions.size()];
int index = 0;
for (SQLScriptPosition pos : removedPositions) {
removedAnnotations[index++] = pos.getFoldingAnnotation();
}
}
Map<Annotation, Position> addedAnnotations = null;
if (!addedPositions.isEmpty()) {
addedAnnotations = new HashMap<>();
for (SQLScriptPosition pos : addedPositions) {
addedAnnotations.put(pos.getFoldingAnnotation(), pos);
}
}
if (removedAnnotations != null || addedAnnotations != null) {
annotationModel.modifyAnnotations(removedAnnotations, addedAnnotations, null);
}
/*
final List<Position> positions;
try {
positions = parseRegion();
} catch (BadLocationException e) {
e.printStackTrace();
return;
}
*/
/*
Display.getDefault().asyncExec(new Runnable()
{
public void run()
{
editor.updateFoldingStructure(regionOffset, regionLength, positions);
}
});
*/
}
use of org.eclipse.jface.text.source.Annotation in project bndtools by bndtools.
the class BndMarkerQuickAssistProcessor method computeQuickAssistProposals.
@Override
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext context) {
List<ICompletionProposal> proposals = new LinkedList<ICompletionProposal>();
ISourceViewer viewer = context.getSourceViewer();
@SuppressWarnings("unused") IDocument document = viewer.getDocument();
IAnnotationModel model = viewer.getAnnotationModel();
@SuppressWarnings("rawtypes") Iterator iter = model.getAnnotationIterator();
while (iter.hasNext()) {
Annotation annotation = (Annotation) iter.next();
if (annotation instanceof MarkerAnnotation && canFix(annotation)) {
Position position = model.getPosition(annotation);
if (isAtPosition(context.getOffset(), position)) {
IMarker marker = ((MarkerAnnotation) annotation).getMarker();
String errorType = marker.getAttribute("$bndType", null);
if (errorType != null) {
BuildErrorDetailsHandler handler = BuildErrorDetailsHandlers.INSTANCE.findHandler(errorType);
if (handler != null) {
proposals.addAll(handler.getProposals(marker));
}
}
}
}
}
if (proposals.isEmpty()) {
proposals.add(new NoCompletionsProposal());
}
return proposals.toArray(new ICompletionProposal[0]);
}
use of org.eclipse.jface.text.source.Annotation in project KaiZen-OpenAPI-Editor by RepreZen.
the class JsonEditor method updateFoldingStructure.
public void updateFoldingStructure(List<Position> positions) {
final Map<Annotation, Position> newAnnotations = new HashMap<Annotation, Position>();
for (Position position : positions) {
newAnnotations.put(new ProjectionAnnotation(), position);
}
annotationModel.modifyAnnotations(oldAnnotations, newAnnotations, null);
oldAnnotations = newAnnotations.keySet().toArray(new Annotation[0]);
}
Aggregations