|
The Controller isolates business logic from presentation. Every instantiated controller is added to a pool of controllers. Through the pool, its possible reach any controller.
Controllers facilitate the reuse and iteration between Swing components. Each Controller is responsible for a Swing component and must implement the following methods:
getComponent to get the controlled component
isComponentInstancied to indicates whether the controller is instantiated
There are several methods to get a Controller from the pool.
It's possible to get one controller or all controllers of a specific class.
There are some options to instantiate a controller:
- using the construtor
- using the static method
get(Class)
- using the local method
createChild(Class)
Method get: This method gets the first controller of a specific class from the pool. If there is no controller for the class, one will be instantiated.
Method createChild: This method can only be used from other controller. The new instantiated controller will be a child controller in the hierarchy. Both controllers will be connected.
Hierarchical groups
// creating Group 1
Controller cA = new ExampleController1();
Controller cB = cA.createChild(ExampleController2.class);
Controller cC = cA.createChild(ExampleController2.class);
Controller cD = cC.createChild(ExampleController3.class);
// creating Group 2
Controller cE = new ExampleController1();
Controller cF = cE.createChild(ExampleController2.class);
// creating Group 3
Controller cG = Controller.get(ExampleController4.class);
|
|
Some navigations through the groups:
cB.getGroup().get(ExampleController1.class) will returns the cA instance.
cD.getTopController() will returns the cA instance
cA.getGroup().get(ExampleController2.class) will returns the first instance of the ExampleController2 class: cB
cA.getGroup().getAll(ExampleController2.class) will returns all instances of the ExampleController2 class: cB and cC
Controller.get(ExampleController1.class) will returns the first instance of the ExampleController1 class: cA
Controller.getAll(ExampleController1.class) will returns all instances of the ExampleController1 class: cA and cE
Annotations
DisposeAction - marks a method to run when the controller is removed from memory with the free method.
ChildController - defines that a controller can't be instantiated by constructor or get method, only through createChild method.
Singleton - defines a controller as singleton.
Removing from the pool
The state of permanent indicates that the controller can't be removed from the memory, even if it used the removal methods.
Modal functions
Has the addModal method to shows a modal
The standard modal messages:
showInformationModal method: shows a information modal message.

showErrorModal method: shows a error modal message.

showWarningModal method: shows a warning modal message.

showQuestionModal method: shows a question modal message.

showConfirmationModal method: shows a confirmation modal message.

Notes:
- modals are added to the parent frame of controlled component through the
Modal functions.
- the buttons text can be changed forwarding or implementing a new bundle resource.
Task execution
- tasks are executed through the
TaskManager functions for the group controller.
- exists a modal effect to the execution of tasks defined by the
TaskExecutionProgress. It is a listener for the TaskManager. Use: TaskManager.addListener(new TaskExecutionProgress())
Why to use?
- easy to integrate
- isolates business logic from presentation
- the pool avoids excessive parameters in methods
|