Class AbstractController<T extends AbstractController<?>>
- java.lang.Object
-
- net.sourceforge.pmd.util.fxdesigner.app.AbstractController<T>
-
- 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.
MessageChannel
s 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 Summary
Constructors Modifier Constructor Description protected
AbstractController(DesignerRoot root, T parent)
protected
AbstractController(T parent)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
afterChildrenInit()
Runs once after every child has finished their initialization.protected void
afterParentInit()
Executed after the parent's initialization (so afterafterChildrenInit()
).protected void
beforeParentInit()
Executed before the parent's initialization.protected java.util.List<? extends AbstractController<?>>
getChildren()
java.util.List<? extends SettingsOwner>
getChildrenSettingsNodes()
Gets the children of this node in order.DesignerRoot
getDesignerRoot()
void
initialize(java.net.URL url, java.util.ResourceBundle resourceBundle)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.sourceforge.pmd.util.fxdesigner.app.ApplicationComponent
getDebugName, getLogger, getMainStage, isDeveloperMode, logInternalDebugInfo, logInternalException, logMessageTrace, logUserException, raiseParsableSourceFlag, raiseParsableXPathFlag
-
-
-
-
Field Detail
-
parent
protected final T extends AbstractController<?> parent
-
-
Constructor Detail
-
AbstractController
protected AbstractController(DesignerRoot root, T parent)
-
AbstractController
protected AbstractController(T parent)
-
-
Method Detail
-
getDesignerRoot
public DesignerRoot getDesignerRoot()
- Specified by:
getDesignerRoot
in interfaceApplicationComponent
-
initialize
public final void initialize(java.net.URL url, java.util.ResourceBundle resourceBundle)
- Specified by:
initialize
in interfacejavafx.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 afterafterChildrenInit()
). 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 theirafterParentInit()
.
-
getChildrenSettingsNodes
public java.util.List<? extends SettingsOwner> getChildrenSettingsNodes()
Description copied from interface:SettingsOwner
Gets the children of this node in order.- Specified by:
getChildrenSettingsNodes
in interfaceSettingsOwner
-
getChildren
protected java.util.List<? extends AbstractController<?>> getChildren()
-
-