Class AbstractCodeMining
- All Implemented Interfaces:
ICodeMining
- Direct Known Subclasses:
DocumentFooterCodeMining, LineContentCodeMining, LineHeaderCodeMining
ICodeMining.- Since:
- 3.13
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractCodeMining(Position position, ICodeMiningProvider provider, Consumer<MouseEvent> action) CodeMining constructor to locate the code mining in a given position. -
Method Summary
Modifier and TypeMethodDescriptionvoiddispose()Dispose the mining.protected CompletableFuture<Void> doResolve(ITextViewer viewer, IProgressMonitor monitor) Returns the future which resolved the content of mining and null otherwise.draw(GC gc, StyledText textWidget, Color color, int x, int y) Draw thegetLabel()of mining with gray color.Returns the action to execute when mining is clicked and null otherwise.getLabel()Returns the label may be set early in the class lifecycle, or upon completion of the future provided byICodeMining.resolve(ITextViewer, IProgressMonitor)operation.protected final StringReturns the label, unless the label isnullandthisis not resolved, then theplaceholderis returned.final StringReturns the placeholder label, which is displayed whileICodeMining.getLabel()returnsnulland the mining is not yet resolved.Returns the line position where code mining must be displayed in the line spacing area.Returns the owner provider which has created this mining.booleanReturns whether the content mining is resolved.final CompletableFuture<Void> resolve(ITextViewer viewer, IProgressMonitor monitor) Returns the future to resolve the content of mining, orCompletableFuture.completedFuture(Object)if no such resolution is necessary (in which case {#isResolved()} is expected to returntrue).voidSet the label mining.final voidsetPlaceholderLabel(String placeholderLabel) Set the placeholder label.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ICodeMining
getMouseHover, getMouseMove, getMouseOut
-
Constructor Details
-
AbstractCodeMining
protected AbstractCodeMining(Position position, ICodeMiningProvider provider, Consumer<MouseEvent> action) CodeMining constructor to locate the code mining in a given position.- Parameters:
position- the position where the mining must be drawn.provider- the owner codemining provider which creates this mining.action- the action to execute when mining is clicked and null otherwise.
-
-
Method Details
-
getPosition
Description copied from interface:ICodeMiningReturns the line position where code mining must be displayed in the line spacing area.- Specified by:
getPositionin interfaceICodeMining- Returns:
- the line position where code mining must be displayed in the line spacing area.
-
getProvider
Description copied from interface:ICodeMiningReturns the owner provider which has created this mining.- Specified by:
getProviderin interfaceICodeMining- Returns:
- the owner provider which has created this mining.
-
getLabel
Description copied from interface:ICodeMiningReturns the label may be set early in the class lifecycle, or upon completion of the future provided byICodeMining.resolve(ITextViewer, IProgressMonitor)operation.The returned label can have several values:
nullwhen mining is not resolvednullwhen mining is resolved means that mining was resolved with an error and it will not be displayed.- empty when mining is resolved means that mining will not be displayed
- non empty when mining must be displayed
- Specified by:
getLabelin interfaceICodeMining- Returns:
- the label may be set early in the class lifecycle, or upon completion of the future
provided by
ICodeMining.resolve(ITextViewer, IProgressMonitor)operation.
-
setLabel
-
getPlaceholderLabel
Description copied from interface:ICodeMiningReturns the placeholder label, which is displayed whileICodeMining.getLabel()returnsnulland the mining is not yet resolved.If the placeholder label is
nullor empty, no placeholder is displayed.A placeholder label can be used to prevent editor jumping for code minings with expensive
ICodeMining.resolve(ITextViewer, IProgressMonitor)implementations, especially for LineHeaderCodeMinings. To actually prevent editor jumping, the placeholder should have the same number of lines as the resolved label. If the mining resolves to anullor empty label, the placeholder disappears and the lines it occupied are removed again.This method may be called from any thread, including the UI thread, possibly several times. Implementations must not block the calling thread and should return a pre-computed value.
When implemented to return a non-empty value, the code mining implementation must adhere to the following contract for
ICodeMining.getLabel():ICodeMining.getLabel()must returnnulluntil the label is computed. The placeholder is only used whileICodeMining.getLabel()returnsnulland the mining is not resolved. If a non-nulllabel is set before resolving, the placeholder is never displayed.- The label must be set during resolution, i.e. after
ICodeMining.resolve(ITextViewer, IProgressMonitor)is invoked and before the future returned by it completes. - If resolution fails or is cancelled, the label should remain
null. The mining is then treated as resolved with an error, seeICodeMining.getLabel().
- Specified by:
getPlaceholderLabelin interfaceICodeMining- Returns:
- the placeholder label, may be
nullor empty.
-
setPlaceholderLabel
Set the placeholder label.If a non-empty value is set, subclasses must adhere to the contract described in
getPlaceholderLabel().- Parameters:
placeholderLabel- The placeholder label.- Since:
- 3.33
-
resolve
Description copied from interface:ICodeMiningReturns the future to resolve the content of mining, orCompletableFuture.completedFuture(Object)if no such resolution is necessary (in which case {#isResolved()} is expected to returntrue).If
ICodeMining.getPlaceholderLabel()returns a non-empty value, then the value ofICodeMining.getLabel()must be set after this method is invoked but before the future returned by it completes.- Specified by:
resolvein interfaceICodeMining- Parameters:
viewer- the viewer, can be nullmonitor- the monitor.- Returns:
- the future to resolve the content of mining, or
CompletableFuture.completedFuture(Object)if no such resolution is necessary (in which case {#isResolved()} is expected to returntrue).
-
doResolve
Returns the future which resolved the content of mining and null otherwise. By default, the resolve do nothing.- Parameters:
viewer- the viewermonitor- the monitor- Returns:
- the future which resolved the content of mining and null otherwise.
-
isResolved
public boolean isResolved()Description copied from interface:ICodeMiningReturns whether the content mining is resolved. If it is not resolved, {ICodeMining.resolve(ITextViewer, IProgressMonitor)} will be invoked later, triggering the future to resolve content.- Specified by:
isResolvedin interfaceICodeMining- Returns:
- whether the content mining is resolved. If it is not resolved,
{
ICodeMining.resolve(ITextViewer, IProgressMonitor)} will be invoked later, triggering the future to resolve content.
-
dispose
public void dispose()Description copied from interface:ICodeMiningDispose the mining. Typically shuts down or cancels all related asynchronous operations.- Specified by:
disposein interfaceICodeMining
-
draw
Draw thegetLabel()of mining with gray color. User can override this method to draw anything.- Specified by:
drawin interfaceICodeMining- Parameters:
gc- the graphics contexttextWidget- the text widget to draw oncolor- the color of the linex- the x position of the annotationy- the y position of the annotation- Returns:
- the size of the draw of mining.
-
getLabelOrPlaceholder
Returns the label, unless the label isnullandthisis not resolved, then theplaceholderis returned.- Returns:
- The label, or the placeholder if
nulland not resolved - Since:
- 3.33
-
getAction
Description copied from interface:ICodeMiningReturns the action to execute when mining is clicked and null otherwise.- Specified by:
getActionin interfaceICodeMining- Returns:
- the action to execute when mining is clicked and null otherwise.
-