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