Search in sources :

Example 1 with ProjectionAnnotation

use of org.eclipse.jface.text.source.projection.ProjectionAnnotation in project tdi-studio-se by Talend.

the class ReconcilerViewer method getAllSnippetsAnnotations.

private Map<ProjectionAnnotation, Position> getAllSnippetsAnnotations() {
    Map<ProjectionAnnotation, Position> annotations = new HashMap<ProjectionAnnotation, Position>();
    IDocument document = getDocument();
    int curOffset = 0;
    FindReplaceDocumentAdapter frda = new FindReplaceDocumentAdapter(document);
    try {
        //$NON-NLS-1$
        IRegion startRegion = frda.find(curOffset, "SNIPPET_START", true, false, false, false);
        while (startRegion != null && startRegion.getOffset() >= curOffset) {
            int startLine = document.getLineOfOffset(startRegion.getOffset());
            int startOffset = document.getLineOffset(startLine);
            curOffset = startOffset + document.getLineLength(startLine);
            //$NON-NLS-1$
            IRegion endRegion = frda.find(startRegion.getOffset(), "SNIPPET_END", true, false, false, false);
            if (endRegion != null) {
                int endLine = document.getLineOfOffset(endRegion.getOffset());
                int endOffset = document.getLineOffset(endLine);
                endOffset += document.getLineLength(endLine);
                curOffset = endOffset;
                String text = document.get(startOffset, endOffset - startOffset);
                ProjectionAnnotation annotation = new ProjectionAnnotation(true);
                annotation.setText(text);
                annotation.setRangeIndication(true);
                annotations.put(annotation, new Position(startOffset, endOffset - startOffset));
            }
            if (curOffset < document.getLength()) {
                //$NON-NLS-1$
                startRegion = frda.find(curOffset, "SNIPPET_START", true, false, false, false);
            }
        }
    } catch (BadLocationException e) {
        ExceptionHandler.process(e);
    }
    return annotations;
}
Also used : ProjectionAnnotation(org.eclipse.jface.text.source.projection.ProjectionAnnotation) HashMap(java.util.HashMap) Position(org.eclipse.jface.text.Position) IDocument(org.eclipse.jface.text.IDocument) FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 2 with ProjectionAnnotation

use of org.eclipse.jface.text.source.projection.ProjectionAnnotation 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)

Example 3 with ProjectionAnnotation

use of org.eclipse.jface.text.source.projection.ProjectionAnnotation in project tdi-studio-se by Talend.

the class ReconcilerViewer method hasSnippetsModifications.

/**
     * Check if there is any new snippet or if some has been deleted.
     * 
     * @return
     */
private boolean hasSnippetsModifications() {
    IDocument document = getDocument();
    if (document == null) {
        return false;
    }
    int curNbAnnotations = oldAnnotations.size();
    int actualNbAnnotations = 0;
    int curOffset = 0;
    FindReplaceDocumentAdapter frda = new FindReplaceDocumentAdapter(document);
    try {
        //$NON-NLS-1$
        IRegion startRegion = frda.find(curOffset, "SNIPPET_START", true, false, false, false);
        while (startRegion != null && startRegion.getOffset() >= curOffset) {
            int startLine = document.getLineOfOffset(startRegion.getOffset());
            int startOffset = document.getLineOffset(startLine);
            curOffset = startOffset + document.getLineLength(startLine);
            //$NON-NLS-1$
            IRegion endRegion = frda.find(startRegion.getOffset(), "SNIPPET_END", true, false, false, false);
            if (endRegion != null) {
                actualNbAnnotations++;
                int endLine = document.getLineOfOffset(endRegion.getOffset());
                int endOffset = document.getLineOffset(endLine);
                endOffset += document.getLineLength(endLine);
                curOffset = endOffset;
                boolean contains = false;
                String text = document.get(startOffset, endOffset - startOffset);
                for (ProjectionAnnotation annotation : oldAnnotations.keySet()) {
                    Position pos = oldAnnotations.get(annotation);
                    if (annotation.getText().equals(text) && (startOffset == pos.getOffset())) {
                        contains = true;
                    }
                }
                if (!contains) {
                    return true;
                }
            }
            if (curOffset < document.getLength()) {
                //$NON-NLS-1$
                startRegion = frda.find(curOffset, "SNIPPET_START", true, false, false, false);
            }
        }
    } catch (BadLocationException e) {
        ExceptionHandler.process(e);
    }
    if (curNbAnnotations != actualNbAnnotations) {
        return true;
    }
    return false;
}
Also used : ProjectionAnnotation(org.eclipse.jface.text.source.projection.ProjectionAnnotation) Position(org.eclipse.jface.text.Position) IDocument(org.eclipse.jface.text.IDocument) FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

Position (org.eclipse.jface.text.Position)3 ProjectionAnnotation (org.eclipse.jface.text.source.projection.ProjectionAnnotation)3 HashMap (java.util.HashMap)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 FindReplaceDocumentAdapter (org.eclipse.jface.text.FindReplaceDocumentAdapter)2 IDocument (org.eclipse.jface.text.IDocument)2 IRegion (org.eclipse.jface.text.IRegion)2 Annotation (org.eclipse.jface.text.source.Annotation)1