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 Details

  • 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 interface org.springframework.context.ResourceLoaderAware
    • getTerminal

      public org.jline.terminal.Terminal getTerminal()
      Gets a Terminal.
      Returns:
      a terminal
    • setRenderer

      public void setRenderer(Function<T,List<org.jline.utils.AttributedString>> renderer)
      Sets a display renderer.
      Parameters:
      renderer - the display renderer function
    • render

      public List<org.jline.utils.AttributedString> render(T context)
      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

      public void addPreRunHandler(Consumer<T> handler)
      Adds a pre-run handler.
      Parameters:
      handler - the handler
    • addPostRunHandler

      public void addPostRunHandler(Consumer<T> handler)
      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 to true.
      Parameters:
      printResults - flag setting if results are printed
    • run

      public final T run(ComponentContext<?> context)
      Runs a component logic with a given context and returns updated context.
      Parameters:
      context - the context
      Returns:
      a context
    • getTemplateExecutor

      public TemplateExecutor getTemplateExecutor()
      Gets a template executor.
      Returns:
      a template executor
    • setTemplateExecutor

      public void setTemplateExecutor(TemplateExecutor templateExecutor)
      Sets a template executor.
      Parameters:
      templateExecutor - the template executor
    • setTemplateLocation

      public void setTemplateLocation(String templateLocation)
      Sets a template location.
      Parameters:
      templateLocation - the template location
    • hasTty

      protected boolean hasTty()
      Checks if this component has an existing tty.
      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

      public abstract T getThisContext(ComponentContext<?> context)
      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 reader
      keyMap - the key map
      context - the context
      Returns:
      true if read is complete, false to stop
    • runInternal

      protected abstract T runInternal(T context)
      Run internal logic called from public run method.
      Parameters:
      context - the context
      Returns:
      a context
    • bindKeyMap

      protected abstract void bindKeyMap(org.jline.keymap.KeyMap<String> keyMap)
      Bind key map.
      Parameters:
      keyMap -
    • loop

      protected void loop(ComponentContext<?> context)
      Enter into read loop. This should be called from a component.
      Parameters:
      context - the context
    • runPreRunHandlers

      protected T runPreRunHandlers(T context)
      Run pre-run handlers
      Parameters:
      context - the context
      Returns:
      a context
    • runPostRunHandlers

      protected T runPostRunHandlers(T context)
      Run post-run handlers
      Parameters:
      context - the context
      Returns:
      a context