Search in sources :

Example 1 with ICodeMining

use of org.eclipse.jface.text.codemining.ICodeMining in project eclipse.platform.text by eclipse.

the class CodeMiningLineContentAnnotation method redraw.

@Override
public void redraw() {
    // redraw codemining annotation is done only if all current minings are resolved.
    List<ICodeMining> minings = new ArrayList<>(fMinings);
    for (ICodeMining mining : minings) {
        if (!mining.isResolved()) {
            // one of mining is not resolved, resolve it and then redraw the annotation.
            mining.resolve(getViewer(), fMonitor).thenRunAsync(() -> {
                this.redraw();
            });
            return;
        }
    }
    // all minings are resolved, redraw the annotation
    super.redraw();
}
Also used : ICodeMining(org.eclipse.jface.text.codemining.ICodeMining) ArrayList(java.util.ArrayList)

Example 2 with ICodeMining

use of org.eclipse.jface.text.codemining.ICodeMining in project eclipse.platform.text by eclipse.

the class CodeMiningLineContentAnnotation method update.

@Override
public void update(List<ICodeMining> minings, IProgressMonitor monitor) {
    if (fResolvedMinings == null || (fResolvedMinings.length != minings.size())) {
        // size of resolved minings are different from size of minings to update, initialize it with size of minings to update
        fResolvedMinings = new ICodeMining[minings.size()];
    }
    // fill valid resolved minings with old minings.
    int length = Math.min(fMinings.size(), minings.size());
    for (int i = 0; i < length; i++) {
        ICodeMining mining = fMinings.get(i);
        if (mining.getLabel() != null) {
            // mining was resolved without an error.
            fResolvedMinings[i] = mining;
        }
    }
    disposeMinings();
    fMonitor = monitor;
    fMinings.addAll(minings);
}
Also used : ICodeMining(org.eclipse.jface.text.codemining.ICodeMining) Point(org.eclipse.swt.graphics.Point)

Example 3 with ICodeMining

use of org.eclipse.jface.text.codemining.ICodeMining in project eclipse.platform.text by eclipse.

the class CodeMiningLineContentAnnotation method drawAndComputeWidth.

@Override
protected int drawAndComputeWidth(GC gc, StyledText textWidget, int offset, int length, Color color, int x, int y) {
    List<ICodeMining> minings = new ArrayList<>(fMinings);
    int nbDraw = 0;
    int originalX = x;
    int separatorWidth = -1;
    boolean redrawn = false;
    fBounds.clear();
    for (int i = 0; i < minings.size(); i++) {
        ICodeMining mining = minings.get(i);
        // try to get the last resolved mining.
        ICodeMining lastResolvedMining = (fResolvedMinings != null && fResolvedMinings.length > i) ? fResolvedMinings[i] : null;
        if (mining.getLabel() != null) {
            // mining is resolved without error, update the resolved mining list
            fResolvedMinings[i] = mining;
        } else if (!mining.isResolved()) {
            // the mining is not resolved, draw the last resolved mining
            mining = lastResolvedMining;
            if (!redrawn) {
                // redraw the annotation when mining is resolved.
                redraw();
                redrawn = true;
            }
        } else {
            // the mining is resolved with error, draw the last resolved mining
            mining = lastResolvedMining;
        }
        if (mining == null) {
            // ignore the draw of mining
            continue;
        }
        // draw the mining
        if (nbDraw > 0) {
            initGC(textWidget, color, gc);
            gc.drawText(SEPARATOR, x, y);
            if (separatorWidth == -1) {
                separatorWidth = gc.stringExtent(SEPARATOR).x;
            }
            x += separatorWidth;
        }
        initGC(textWidget, color, gc);
        Point loc = mining.draw(gc, textWidget, color, x, y);
        fBounds.add(new Rectangle(x, y, loc.x, loc.y));
        x += loc.x;
        nbDraw++;
    }
    return x - originalX;
}
Also used : ICodeMining(org.eclipse.jface.text.codemining.ICodeMining) ArrayList(java.util.ArrayList) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 4 with ICodeMining

use of org.eclipse.jface.text.codemining.ICodeMining in project eclipse.platform.text by eclipse.

the class CodeMiningLineHeaderAnnotation method update.

@Override
public void update(List<ICodeMining> minings, IProgressMonitor monitor) {
    if (fResolvedMinings == null || (fResolvedMinings.length != minings.size())) {
        // size of resolved minings are different from size of minings to update, initialize it with size of minings to update
        fResolvedMinings = new ICodeMining[minings.size()];
    }
    // fill valid resolved minings with old minings.
    int length = Math.min(fMinings.size(), minings.size());
    for (int i = 0; i < length; i++) {
        ICodeMining mining = fMinings.get(i);
        if (mining.getLabel() != null) {
            fResolvedMinings[i] = mining;
        }
    }
    disposeMinings();
    fMonitor = monitor;
    fMinings.addAll(minings);
}
Also used : ICodeMining(org.eclipse.jface.text.codemining.ICodeMining) Point(org.eclipse.swt.graphics.Point)

Example 5 with ICodeMining

use of org.eclipse.jface.text.codemining.ICodeMining in project eclipse.platform.text by eclipse.

the class CodeMiningLineHeaderAnnotation method redraw.

@Override
public void redraw() {
    // redraw codemining annotation is done only if all current minings are resolved.
    List<ICodeMining> minings = new ArrayList<>(fMinings);
    for (ICodeMining mining : minings) {
        if (!mining.isResolved()) {
            // one of mining is not resolved, resolve it and then redraw the annotation.
            mining.resolve(getViewer(), fMonitor).thenRunAsync(() -> {
                this.redraw();
            });
            return;
        }
    }
    // all minings are resolved, redraw the annotation
    super.redraw();
}
Also used : ICodeMining(org.eclipse.jface.text.codemining.ICodeMining) ArrayList(java.util.ArrayList)

Aggregations

ICodeMining (org.eclipse.jface.text.codemining.ICodeMining)10 ArrayList (java.util.ArrayList)7 IDocument (org.eclipse.jface.text.IDocument)4 Point (org.eclipse.swt.graphics.Point)4 BadLocationException (org.eclipse.jface.text.BadLocationException)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 HashSet (java.util.HashSet)1 Position (org.eclipse.jface.text.Position)1 LineHeaderCodeMining (org.eclipse.jface.text.codemining.LineHeaderCodeMining)1 AbstractInlinedAnnotation (org.eclipse.jface.text.source.inlined.AbstractInlinedAnnotation)1