Class ControllerManager

java.lang.Object
org.fulib.fx.controller.ControllerManager

@Singleton @Internal public class ControllerManager extends Object
Manages the initialization, rendering and destroying of controllers.

This class is used internally by the framework and should not be used directly.

  • Constructor Details

    • ControllerManager

      @Inject public ControllerManager()
  • Method Details

    • initAndRender

      public javafx.scene.Node initAndRender(Object instance, Map<String,Object> parameters)
      Initializes and renders the given controller. Calls the onInit and onRender methods. See init(Object, Map) and render(Object, Map).

      The controller/component instance(s) will be added to the set of initialized controllers and will be destroyed when a new main controller is set.

      Parameters:
      instance - The controller instance
      parameters - The parameters to pass to the controller
      Returns:
      The rendered controller
    • init

      public io.reactivex.rxjava3.disposables.Disposable init(@NotNull @NotNull Object instance, @NotNull @NotNull Map<@NotNull String,@Nullable Object> parameters, boolean disposeOnNewMainController)
      Initializes the given controller/component. Calls the onInit method(s) and recursively initializes all subcomponents.

      Order: Controller -> Subcomponents -> Subcomponents of subcomponents -> ...

      Parameters:
      instance - The controller/component instance
      parameters - The parameters to pass to the controller/component
      disposeOnNewMainController - Whether the controller/component should be destroyed when a new main controller is set
      Returns:
      A disposable that can be used to destroy the controller/component and all its subcomponents manually
    • init

      public void init(@NotNull @NotNull Object instance, @NotNull @NotNull Map<@NotNull String,@Nullable Object> parameters)
      Initializes the given controller/component. Calls the onInit method(s) and recursively initializes all subcomponents.

      All initialized controllers will be added to the list of initialized controllers. If a controller/component is added to the list, all its subcomponents will follow right after it.

      Parameters:
      instance - The controller/component instance
      parameters - The parameters to pass to the controller
    • render

      public javafx.scene.Node render(Object instance, Map<String,Object> parameters)
      Renders the given controller/component instance. Renders all subcomponents recursively and then calls the onRender method(s) before returning the rendered controller.

      Important: This method assumes that the controller has already been initialized. The controller will not automatically be destroyed when using only this method. Use init(Object, Map, boolean) before, to initialize and automatically destroy the controller or destroy it yourself afterward.

      If the controller specifies a fxml file in its Controller.view(), it will be loaded and the controller will be set as the controller of the fxml file.

      If the controller is a component (extends from a JavaFX Node), the component itself will be rendered and returned. This can be combined with the Component.view() to set the controller as the root of the fxml file.

      If the controller specifies a method as Controller.view(), the method will be called and the returned Parent will be used as the view. In order to specify a method, the view must start with a '#'. The method must be in the controller class and must return a (subclass of) Parent. Example: @Controller(view = "#getView") will call the method Parent getView() in the controller.

      Parameters:
      instance - The controller instance
      parameters - The parameters to pass to the controller
      Returns:
      The rendered controller/component
    • destroy

      public void destroy(@NotNull @NotNull Object instance)
      Destroys the given controller/component by calling all methods annotated with onDestroy.

      Important: Do not use this method on a controller's view but on the controller itself.

      If the controller has subcomponents, they will be destroyed first recursively in reverse order.

      If the controller has an undestroyed Subscriber field, a warning will be logged in development mode.

      Parameters:
      instance - The controller/component instance to destroy
    • cleanup

      public void cleanup()
      Destroys all controllers that have been initialized and are currently displayed.
    • setDefaultResourceBundle

      public void setDefaultResourceBundle(ResourceBundle resourceBundle)
      Sets the default resource bundle for all controllers that don't have a resource bundle set.
      Parameters:
      resourceBundle - The default resource bundle
    • getTitle

      public Optional<String> getTitle(@NotNull @NotNull Object instance)
      Returns the title of the given controller instance if it has one. If the title is a key, the title will be looked up in the resource bundle of the controller.
      Parameters:
      instance - The controller instance
      Returns:
      The title of the controller