java.lang.Object
ch.ladestation.connectncharge.util.mvcbase.PuiBase<M,C>
Direct Known Subclasses:
GamePUI

public abstract class PuiBase<M,C extends ControllerBase<M>> extends Object
Base class for all PUIs.

In our scenario we also have a GUI.

We have to avoid that one of the UIs is blocked because the other UI has to perform a long-running task.

Therefore, we need an additional "worker-thread" in both UIs.

For JavaFX-based GUIs that's already available (the JavaFX Application Thread).

For PUIs we need to do that ourselves. It's implemented as a provider/consumer-pattern (see ConcurrentTaskQueue.

  • Field Details

    • pi4J

      protected final com.pi4j.context.Context pi4J
  • Constructor Details

    • PuiBase

      public PuiBase(C controller, com.pi4j.context.Context pi4J)
  • Method Details

    • shutdown

      public void shutdown()
    • async

      protected void async(Supplier<Void> todo, Consumer<Void> onDone)
    • runLater

      public void runLater(Consumer<Void> todo)
    • awaitCompletion

      public void awaitCompletion()
      Intermediate solution for TestCase support.

      Best solution would be that 'action' of 'runLater' is executed on calling thread.

      Waits until all current actions in actionQueue are completed.

    • onChangeOf

      protected <V> PuiBase<M,C>.Updater<V> onChangeOf(ObservableValue<V> observableValue)
      First step to register an observer.
      Parameters:
      observableValue - the value that should trigger some PUI-updates
      Returns:
      an Updater to specify what needs to be done whenever observableValue changes
    • onChangeOf

      protected <V> PuiBase<M,C>.ArrayUpdater<V> onChangeOf(ObservableArray<V> observableArray)
      First step to register an observer.
      Parameters:
      observableArray - the value that should trigger some PUI-updates
      Returns:
      an Updater to specify what needs to be done whenever observableValue changes
    • init

      default void init(C controller)
      needs to be called inside the constructor of your UI-part
    • initializeSelf

      default void initializeSelf()
      Everything that needs to be done to initialize the UI-part itself.

      For GUIs loading stylesheet-files or additional fonts are typical examples.

    • initializeParts

      void initializeParts()
      completely initialize all necessary UI-elements (like buttons, text-fields, etc. on GUI or distance sensors on PUI )
    • setupUiToActionBindings

      default void setupUiToActionBindings(C controller)
      Triggering some action on Controller if the user interacts with the UI.

      There's no need to have access to model for this task.

      All EventHandlers will call a single method on the Controller.

      If you are about to call more than one method, you should introduce a new method on Controller.

    • setupModelToUiBindings

      default void setupModelToUiBindings(M model)
      Whenever an 'ObservableValue' in 'model' changes, the UI must be updated.

      There's no need to have access to controller for this task.

      Register all necessary observers here.

    • startUp

      default void startUp(C controller)
      At the Startup, this method gets called.

      Perfect, if a function in the controller or in the pui needs to be run exactly once.