Class AbstractController<T extends AbstractController<?>>

  • Type Parameters:
    T - Type of the parent controller
    All Implemented Interfaces:
    javafx.fxml.Initializable, ApplicationComponent, SettingsOwner
    Direct Known Subclasses:
    EventLogController, MainDesignerController, NodeInfoPanelController, SourceEditorController, XPathPanelController

    public abstract class AbstractController<T extends AbstractController<?>>
    extends java.lang.Object
    implements javafx.fxml.Initializable, SettingsOwner, ApplicationComponent
    Base class for controllers of the app. The main window of the app is split into regions corresponding to some area of functionality. Each has its own FXML file that can be found in the fxml resource directory. Each also has its own independent controller. Since the FXML regions are nested like a tree (the JavaFX scene graph), it's natural to link the controllers in a tree too.

    For now controllers mostly communicate by sending messages to their parent and letting it forward the message to the rest of the app. TODO I'm more and more convinced we should avoid that and stop having the controllers hold a reference to their parent. They should only communicate by exposing properties their parent binds to, but they shouldn't know about their parent. MessageChannels can allow us to decouple them even more.

    This class mainly exists to make the initialization cycle of JavaFX clearer. Children controllers are initialized before their parent, but sometimes they should only perform some actions after its parent has been initialized, e.g. binding properties that depend on a restored setting or stuff. This is part of the reason why Platform.runLater(Runnable) can sometimes be enough to solve initialization problems.

    This only works if all controllers in the initialization sequence of an FXML file extend this class.

    Since:
    6.11.0
    Author:
    Clément Fournier
    • Constructor Detail

      • AbstractController

        protected AbstractController​(DesignerRoot root,
                                     T parent)
      • AbstractController

        protected AbstractController​(T parent)
    • Method Detail

      • initialize

        public final void initialize​(java.net.URL url,
                                     java.util.ResourceBundle resourceBundle)
        Specified by:
        initialize in interface javafx.fxml.Initializable
      • beforeParentInit

        protected void beforeParentInit()
        Executed before the parent's initialization. Always executed once at the start of the initialization of this controller.
      • afterParentInit

        protected void afterParentInit()
        Executed after the parent's initialization (so after afterChildrenInit()). This also means, after persistent settings restoration. If this node has no parent, then this is never executed.
      • afterChildrenInit

        protected void afterChildrenInit()
        Runs once after every child has finished their initialization. This will be run in all cases. It's only useful if the children do something useful in their afterParentInit().