use of org.eclipse.jface.text.source.inlined.AbstractInlinedAnnotation in project eclipse.platform.text by eclipse.
the class CodeMiningManager method renderCodeMinings.
/**
* Render the codemining grouped by line position.
*
* @param groups code minings grouped by lines position
* @param viewer the viewer
* @param monitor the progress monitor
*/
private void renderCodeMinings(Map<Position, List<ICodeMining>> groups, ISourceViewer viewer, IProgressMonitor monitor) {
// check if request was canceled.
monitor.isCanceled();
IDocument document = viewer != null ? viewer.getDocument() : null;
if (document == null) {
// done.
return;
}
Set<ICodeMiningAnnotation> annotationsToRedraw = new HashSet<>();
Set<AbstractInlinedAnnotation> currentAnnotations = new HashSet<>();
// Loop for grouped code minings
groups.entrySet().stream().forEach(g -> {
// check if request was canceled.
monitor.isCanceled();
Position pos = new Position(g.getKey().offset, g.getKey().length);
List<ICodeMining> minings = g.getValue();
boolean inLineHeader = minings.size() > 0 ? (minings.get(0) instanceof LineHeaderCodeMining) : true;
// Try to find existing annotation
AbstractInlinedAnnotation ann = fInlinedAnnotationSupport.findExistingAnnotation(pos);
if (ann == null) {
// The annotation doesn't exists, create it.
ann = inLineHeader ? new CodeMiningLineHeaderAnnotation(pos, viewer) : new CodeMiningLineContentAnnotation(pos, viewer);
} else if (ann instanceof ICodeMiningAnnotation && ((ICodeMiningAnnotation) ann).isInVisibleLines()) {
// annotation is in visible lines
annotationsToRedraw.add((ICodeMiningAnnotation) ann);
}
((ICodeMiningAnnotation) ann).update(minings, monitor);
currentAnnotations.add(ann);
});
// check if request was canceled.
monitor.isCanceled();
fInlinedAnnotationSupport.updateAnnotations(currentAnnotations);
// redraw the existing codemining annotations since their content can change
annotationsToRedraw.stream().forEach(ann -> ann.redraw());
}
use of org.eclipse.jface.text.source.inlined.AbstractInlinedAnnotation in project eclipse.platform.text by eclipse.
the class InlinedAnnotationDemo method getInlinedAnnotation.
/**
* Returns the inlined annotations list to display in the given viewer.
*
* @param viewer
* the viewer
* @param support
* the inlined annotation suppor.
* @return the inlined annotations list to display in the given viewer.
*/
private static Set<AbstractInlinedAnnotation> getInlinedAnnotation(ISourceViewer viewer, InlinedAnnotationSupport support) {
IDocument document = viewer.getDocument();
Set<AbstractInlinedAnnotation> annotations = new HashSet<>();
int lineCount = document.getNumberOfLines();
for (int i = 0; i < lineCount; i++) {
String line = getLineText(document, i).trim();
int index = line.indexOf("color:");
if (index == 0) {
String rgb = line.substring(index + "color:".length(), line.length()).trim();
try {
String status = "OK!";
Color color = parse(rgb, viewer.getTextWidget().getDisplay());
if (color != null) {
} else {
status = "ERROR!";
}
// Status color annotation
Position pos = Positions.of(i, document, true);
ColorStatusAnnotation statusAnnotation = support.findExistingAnnotation(pos);
if (statusAnnotation == null) {
statusAnnotation = new ColorStatusAnnotation(pos, viewer);
}
statusAnnotation.setStatus(status);
annotations.add(statusAnnotation);
// Color annotation
if (color != null) {
Position colorPos = new Position(pos.offset + index + "color:".length(), 1);
ColorAnnotation colorAnnotation = support.findExistingAnnotation(colorPos);
if (colorAnnotation == null) {
colorAnnotation = new ColorAnnotation(colorPos, viewer);
}
colorAnnotation.setColor(color);
annotations.add(colorAnnotation);
}
// rgb parameter names annotations
int rgbIndex = line.indexOf("rgb");
if (rgbIndex != -1) {
rgbIndex = rgbIndex + "rgb".length();
int startOffset = pos.offset + rgbIndex;
String rgbContent = line.substring(rgbIndex, line.length());
int startIndex = addRGBParamNameAnnotation("red:", rgbContent, 0, startOffset, viewer, support, annotations);
if (startIndex != -1) {
startIndex = addRGBParamNameAnnotation("green:", rgbContent, startIndex, startOffset, viewer, support, annotations);
if (startIndex != -1) {
startIndex = addRGBParamNameAnnotation("blue:", rgbContent, startIndex, startOffset, viewer, support, annotations);
}
}
}
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
return annotations;
}
Aggregations