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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addPostRunHandler
(Consumer<T> handler) Adds a post-run handler.void
addPreRunHandler
(Consumer<T> handler) Adds a pre-run handler.protected abstract void
bindKeyMap
(org.jline.keymap.KeyMap<String> keyMap) Bind key map.Gets a template executor.org.jline.terminal.Terminal
Gets aTerminal
.abstract T
getThisContext
(ComponentContext<?> context) Gets a real component context using common this trick.protected boolean
hasTty()
Checks if this component has an existingtty
.protected void
loop
(ComponentContext<?> context) Enter into read loop.protected abstract boolean
read
(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 T
run
(ComponentContext<?> context) Runs a component logic with a given context and returns updated context.protected abstract T
runInternal
(T context) Run internal logic called from public run method.protected T
runPostRunHandlers
(T context) Run post-run handlersprotected T
runPreRunHandlers
(T context) Run pre-run handlersvoid
setPrintResults
(boolean printResults) Sets if results should be printed into a console, Defaults totrue
.void
setRenderer
(Function<T, List<org.jline.utils.AttributedString>> renderer) Sets a display renderer.void
setResourceLoader
(org.springframework.core.io.ResourceLoader resourceLoader) void
setTemplateExecutor
(TemplateExecutor templateExecutor) Sets a template executor.void
setTemplateLocation
(String templateLocation) Sets a template location.
-
Field Details
-
OPERATION_EXIT
- See Also:
-
OPERATION_BACKSPACE
- See Also:
-
OPERATION_CHAR
- See Also:
-
OPERATION_UNICODE
- 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:
setResourceLoader
in 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
-