Interface PreCommandExecution

All Known Implementing Classes:
SelectionPreCondition

public interface PreCommandExecution
A basic interface for providing safe guards before a command is executed. This is the bare bones implementation of simply checking if it's true and attaching listeners. Concrete implementations need to make their own clean-up or otherwise logging logic.

An example would be SelectionPreCondition, where it allows commands to require that a selection is made before the command can execute. And if on run a selection was not made, it queries the user for a selection.

Author:
Lehlogonolo Poole
See Also:
  • Method Details

    • getPassListener

      EventReactor getPassListener()
      The main event reactor to run if the condition is met on startup or is later called by the getEventEmitterToAttachTo().
      Returns:
      The event reactor to run.
    • getFailListener

      EventReactor getFailListener()
      The event to fire if the condition is false.
      Returns:
      The event reactor to run.
    • getEventEmitterToAttachTo

      EventEmitterInterface getEventEmitterToAttachTo()
      The EventEmitterInterface which the getPassListener() will attach to.
      Returns:
      The event emitter to attach to.
    • getLogText

      SamePair<String> getLogText()
      The text to display to the user via SafeJLabel.setText(String) when the condition is not met on startup. This is usually a friendly message requesting the user to interact with something before proceeding.
      Returns:
      The text to display.
    • getCondition

      Supplier<Boolean> getCondition()
      The actual condition to check against wrapped around a Supplier
      Returns:
      The condition to check against.
    • execute

      default boolean execute(SafeJLabel logLabel)
      Executes the pre-command condition check. If the condition is not met, it displays a message to the user and attaches the pass listener to the appropriate event emitter, waiting for the condition to be met. If the condition is met, it immediately triggers the pass listener.
      Parameters:
      logLabel - The SafeJLabel to display messages to the user.
      Returns:
      true if the condition was met immediately, false otherwise.