Search in sources :

Example 1 with LineHeaderCodeMining

use of org.eclipse.jface.text.codemining.LineHeaderCodeMining 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());
}
Also used : ICodeMining(org.eclipse.jface.text.codemining.ICodeMining) Position(org.eclipse.jface.text.Position) LineHeaderCodeMining(org.eclipse.jface.text.codemining.LineHeaderCodeMining) AbstractInlinedAnnotation(org.eclipse.jface.text.source.inlined.AbstractInlinedAnnotation) IDocument(org.eclipse.jface.text.IDocument) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 IDocument (org.eclipse.jface.text.IDocument)1 Position (org.eclipse.jface.text.Position)1 ICodeMining (org.eclipse.jface.text.codemining.ICodeMining)1 LineHeaderCodeMining (org.eclipse.jface.text.codemining.LineHeaderCodeMining)1 AbstractInlinedAnnotation (org.eclipse.jface.text.source.inlined.AbstractInlinedAnnotation)1