Search in sources :

Example 1 with Annotation

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);
        }
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) Annotation(org.eclipse.jface.text.source.Annotation)

Example 2 with Annotation

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

        });
*/
}
Also used : ProjectionAnnotationModel(org.eclipse.jface.text.source.projection.ProjectionAnnotationModel) Position(org.eclipse.jface.text.Position) Annotation(org.eclipse.jface.text.source.Annotation)

Example 3 with Annotation

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]);
}
Also used : Position(org.eclipse.jface.text.Position) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) LinkedList(java.util.LinkedList) MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) Annotation(org.eclipse.jface.text.source.Annotation) BuildErrorDetailsHandler(org.bndtools.build.api.BuildErrorDetailsHandler) MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Iterator(java.util.Iterator) IMarker(org.eclipse.core.resources.IMarker) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IDocument(org.eclipse.jface.text.IDocument)

Example 4 with Annotation

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]);
}
Also used : ProjectionAnnotation(org.eclipse.jface.text.source.projection.ProjectionAnnotation) HashMap(java.util.HashMap) Position(org.eclipse.jface.text.Position) Annotation(org.eclipse.jface.text.source.Annotation) ProjectionAnnotation(org.eclipse.jface.text.source.projection.ProjectionAnnotation)

Aggregations

Annotation (org.eclipse.jface.text.source.Annotation)4 Position (org.eclipse.jface.text.Position)3 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 BuildErrorDetailsHandler (org.bndtools.build.api.BuildErrorDetailsHandler)1 IMarker (org.eclipse.core.resources.IMarker)1 IDocument (org.eclipse.jface.text.IDocument)1 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)1 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1 ProjectionAnnotation (org.eclipse.jface.text.source.projection.ProjectionAnnotation)1 ProjectionAnnotationModel (org.eclipse.jface.text.source.projection.ProjectionAnnotationModel)1 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)1 MarkerAnnotation (org.eclipse.ui.texteditor.MarkerAnnotation)1