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 SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier 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_UNICODE- See Also:
 
- 
OPERATION_SELECT- See Also:
 
- 
OPERATION_DOWN- See Also:
 
- 
OPERATION_UP- See Also:
 
 
- 
- 
Constructor Details- 
AbstractComponentpublic AbstractComponent(org.jline.terminal.Terminal terminal) 
 
- 
- 
Method Details- 
setResourceLoaderpublic void setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader) - Specified by:
- setResourceLoaderin interface- org.springframework.context.ResourceLoaderAware
 
- 
getTerminalpublic org.jline.terminal.Terminal getTerminal()Gets aTerminal.- Returns:
- a terminal
 
- 
setRendererSets a display renderer.- Parameters:
- renderer- the display renderer function
 
- 
renderRender to be shows content of a display with set display renderer using a given context.- Parameters:
- context- the context
- Returns:
- list of attributed strings
 
- 
addPreRunHandlerAdds a pre-run handler.- Parameters:
- handler- the handler
 
- 
addPostRunHandlerAdds a post-run handler.- Parameters:
- handler- the handler
 
- 
setPrintResultspublic void setPrintResults(boolean printResults) Sets if results should be printed into a console, Defaults totrue.- Parameters:
- printResults- flag setting if results are printed
 
- 
runRuns a component logic with a given context and returns updated context.- Parameters:
- context- the context
- Returns:
- a context
 
- 
getTemplateExecutorGets a template executor.- Returns:
- a template executor
 
- 
setTemplateExecutorSets a template executor.- Parameters:
- templateExecutor- the template executor
 
- 
setTemplateLocationSets a template location.- Parameters:
- templateLocation- the template location
 
- 
hasTtyprotected boolean hasTty()Checks if this component has an existingtty.- Returns:
- true if component has tty
 
- 
renderTemplateResourceprotected 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
 
- 
getThisContextGets a real component context using common this trick.- Parameters:
- context- the context
- Returns:
- a component context
 
- 
readprotected abstract boolean read(org.jline.keymap.BindingReader bindingReader, org.jline.keymap.KeyMap<String> keyMap, T context) Read input.- Parameters:
- bindingReader- the binding reader
- keyMap- the key map
- context- the context
- Returns:
- true if read is complete, false to stop
 
- 
runInternalRun internal logic called from public run method.- Parameters:
- context- the context
- Returns:
- a context
 
- 
bindKeyMapBind key map.- Parameters:
- keyMap-
 
- 
loopEnter into read loop. This should be called from a component.- Parameters:
- context- the context
 
- 
runPreRunHandlersRun pre-run handlers- Parameters:
- context- the context
- Returns:
- a context
 
- 
runPostRunHandlersRun post-run handlers- Parameters:
- context- the context
- Returns:
- a context
 
 
-