Class AbstractComponent<T extends ComponentContext<T>>
java.lang.Object
org.springframework.shell.component.support.AbstractComponent<T>
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.context.ResourceLoaderAware
- Direct Known Subclasses:
AbstractSelectorComponent,AbstractTextComponent
public abstract class AbstractComponent<T extends ComponentContext<T>>
extends Object
implements org.springframework.context.ResourceLoaderAware
Base class for components.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPostRunHandler(Consumer<T> handler) Adds a post-run handler.voidaddPreRunHandler(Consumer<T> handler) Adds a pre-run handler.protected abstract voidbindKeyMap(org.jline.keymap.KeyMap<String> keyMap) Bind key map.Gets a template executor.org.jline.terminal.TerminalGets aTerminal.abstract TgetThisContext(ComponentContext<?> context) Gets a real component context using common this trick.protected booleanhasTty()Checks if this component has an existingtty.protected voidloop(ComponentContext<?> context) Enter into read loop.protected abstract booleanread(org.jline.keymap.BindingReader bindingReader, org.jline.keymap.KeyMap<String> keyMap, T context) Read input.List<org.jline.utils.AttributedString>Render to be shows content of a display with set display renderer using a given context.protected List<org.jline.utils.AttributedString>renderTemplateResource(Map<String, Object> attributes) Render a given template with attributes.final Trun(ComponentContext<?> context) Runs a component logic with a given context and returns updated context.protected abstract TrunInternal(T context) Run internal logic called from public run method.protected TrunPostRunHandlers(T context) Run post-run handlersprotected TrunPreRunHandlers(T context) Run pre-run handlersvoidsetPrintResults(boolean printResults) Sets if results should be printed into a console, Defaults totrue.voidsetRenderer(Function<T, List<org.jline.utils.AttributedString>> renderer) Sets a display renderer.voidsetResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader) voidsetTemplateExecutor(TemplateExecutor templateExecutor) Sets a template executor.voidsetTemplateLocation(String templateLocation) Sets a template location.
-
Field Details
-
OPERATION_EXIT
- See Also:
-
OPERATION_BACKSPACE
- See Also:
-
OPERATION_CHAR
- See Also:
-
OPERATION_SELECT
- See Also:
-
OPERATION_DOWN
- See Also:
-
OPERATION_UP
- See Also:
-
-
Constructor Details
-
AbstractComponent
public AbstractComponent(org.jline.terminal.Terminal terminal)
-
-
Method Details
-
setResourceLoader
public void setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader) - Specified by:
setResourceLoaderin interfaceorg.springframework.context.ResourceLoaderAware
-
getTerminal
public org.jline.terminal.Terminal getTerminal()Gets aTerminal.- Returns:
- a terminal
-
setRenderer
Sets a display renderer.- Parameters:
renderer- the display renderer function
-
render
Render to be shows content of a display with set display renderer using a given context.- Parameters:
context- the context- Returns:
- list of attributed strings
-
addPreRunHandler
Adds a pre-run handler.- Parameters:
handler- the handler
-
addPostRunHandler
Adds a post-run handler.- Parameters:
handler- the handler
-
setPrintResults
public void setPrintResults(boolean printResults) Sets if results should be printed into a console, Defaults totrue.- Parameters:
printResults- flag setting if results are printed
-
run
Runs a component logic with a given context and returns updated context.- Parameters:
context- the context- Returns:
- a context
-
getTemplateExecutor
Gets a template executor.- Returns:
- a template executor
-
setTemplateExecutor
Sets a template executor.- Parameters:
templateExecutor- the template executor
-
setTemplateLocation
Sets a template location.- Parameters:
templateLocation- the template location
-
hasTty
protected boolean hasTty()Checks if this component has an existingtty.- Returns:
- true if component has tty
-
renderTemplateResource
protected List<org.jline.utils.AttributedString> renderTemplateResource(Map<String, Object> attributes) Render a given template with attributes.- Parameters:
attributes- the attributes- Returns:
- rendered content as attributed strings
-
getThisContext
Gets a real component context using common this trick.- Parameters:
context- the context- Returns:
- a component context
-
read
protected abstract boolean read(org.jline.keymap.BindingReader bindingReader, org.jline.keymap.KeyMap<String> keyMap, T context) Read input.- Parameters:
bindingReader- the binding readerkeyMap- the key mapcontext- the context- Returns:
- true if read is complete, false to stop
-
runInternal
Run internal logic called from public run method.- Parameters:
context- the context- Returns:
- a context
-
bindKeyMap
Bind key map.- Parameters:
keyMap-
-
loop
Enter into read loop. This should be called from a component.- Parameters:
context- the context
-
runPreRunHandlers
Run pre-run handlers- Parameters:
context- the context- Returns:
- a context
-
runPostRunHandlers
Run post-run handlers- Parameters:
context- the context- Returns:
- a context
-