Class ControllerBase<M>
- Direct Known Subclasses:
ApplicationController
The whole application logic is located in controller classes.
Controller classes work on and manage the Model. Models encapsulate the whole application state.
Controllers provide the whole core functionality of the application, so called 'Actions'
Execution of Actions is asynchronous. The sequence is kept stable, such that for all actions A and B: if B is submitted after A, B will only be executed after A is finished.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final class
protected static final class
protected static interface
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected <V> void
add
(ObservableArray<V> observableArray, V elementToAdd) Convenience method to add an element to anObservableArray<V>
asynchronously.protected <V> void
addUnique
(ObservableArray<V> observableArray, V elementToAdd) Convenience method to add an element to anObservableArray<V>
asynchronously but only if the array doesn't already contain that element.protected static <V> V[]
arrayAdd
(V[] theArray, V toAdd) protected static <V> V[]
arrayRemove
(V[] theArray, V toRemove) protected void
Schedule the given action for execution in strict order in external thread, asynchronously.protected void
Schedule the given action for execution in strict order in external thread, asynchronously.void
Intermediate solution for TestCase support.protected void
decrease
(ObservableArray<Integer> observableArray, int position) Convenience method to decrease aObservableArray<Integer>
by 1 at position xprotected ControllerBase.Setter<Integer>
decrease
(ObservableValue<Integer> observableValue) protected void
decreaseValue
(ObservableValue<Integer> observableValue) Convenience method to decrease aObservableValue<Integer>
by 1protected static <V> V[]
get
(ObservableArray<V> observableArray) protected static <V> V
get
(ObservableArray<V> observableArray, int position) protected static <V> V
get
(ObservableValue<V> observableValue) getModel()
Only the other base classes 'ViewMixin' and 'PUI_Base' need access, therefore it's 'package private' ...except when trying to mock this.protected void
increase
(ObservableArray<Integer> observableArray, int position) Convenience method to increase aObservableArray<Integer>
by 1 at position xprotected ControllerBase.Setter<Integer>
increase
(ObservableValue<Integer> observableValue) protected void
increaseValue
(ObservableValue<Integer> observableValue) Convenience method to increase aObservableValue<Integer>
by 1protected void
pauseExecution
(Duration duration) Utility function to pause execution of actions for the specified amount of time.protected <V> void
remove
(ObservableArray<V> observableArray, V elementToRemove) Convenience method to remove an element from anObservableArray<V>
void
protected <V> ControllerBase.ArraySetter<V>
set
(ObservableArray<V> observableArray, V[] values) protected <V> ControllerBase.Setter<V>
set
(ObservableValue<V> observableValue, V value) protected <V> void
setValue
(ObservableArray<V> observableArray, int position, V newValue) Even for setting a value in the array the controller is responsible.protected <V> void
setValue
(ObservableValue<V> observableValue, V newValue) Even for setting a value the controller is responsible.protected <V> void
setValues
(ObservableArray<V> observableArray, V[] newValues) Even for setting values in the array the controller is responsible.void
shutdown()
void
startUp()
If anything needs to be run once at startup from the controllerprotected static <V> void
syncAdd
(ObservableArray<V> arr, V elem) protected static <V> void
syncAddUnique
(ObservableArray<V> arr, V elem) protected static <V> void
syncRemove
(ObservableArray<V> arr, V elem) protected static <V> void
syncSet
(ObservableArray<V> arr, V[] newVal) protected static <V> void
syncSet
(ObservableValue<V> val, V newVal) protected void
toggle
(ObservableArray<Boolean> observableArray, int position) Convenience method to toggle aObservableArray<Boolean>
at position xprotected ControllerBase.Setter<Boolean>
toggle
(ObservableValue<Boolean> observableValue) protected void
toggleValue
(ObservableValue<Boolean> observableValue) Convenience method to toggle aObservableValue<Boolean>
protected void
updateModel
(ControllerBase.SetterInterface... setters) Use this if you need to update several ObservableValues in one async call.
-
Field Details
-
log
protected final org.slf4j.Logger log -
model
-
-
Constructor Details
-
ControllerBase
Controller needs a Model.- Parameters:
model
- Model managed by this Controller
-
-
Method Details
-
arrayRemove
protected static <V> V[] arrayRemove(V[] theArray, V toRemove) -
arrayAdd
protected static <V> V[] arrayAdd(V[] theArray, V toAdd) -
get
-
get
-
get
-
syncSet
-
syncSet
-
syncRemove
-
syncAdd
-
syncAddUnique
-
shutdown
public void shutdown() -
startUp
public void startUp()If anything needs to be run once at startup from the controller -
async
Schedule the given action for execution in strict order in external thread, asynchronously.onDone is called as soon as action is finished
-
async
Schedule the given action for execution in strict order in external thread, asynchronously. -
runLater
- Parameters:
action
- Schedule the given action after all the actions already scheduled have finished.
-
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.
In most cases it's wrong to call this method from within an application.
-
getModel
Only the other base classes 'ViewMixin' and 'PUI_Base' need access, therefore it's 'package private' ...except when trying to mock this. so nvm.- Returns:
- the model of this controller
-
setValue
Even for setting a value the controller is responsible.No application specific class can access ObservableValue.setValue
Value is set asynchronously.
-
setValues
Even for setting values in the array the controller is responsible.No application specific class can access ObservableValue.setValues
Values are set asynchronously.
-
setValue
Even for setting a value in the array the controller is responsible.No application specific class can access ObservableValue.setValue
Value is set asynchronously.
-
toggleValue
Convenience method to toggle aObservableValue<Boolean>
-
toggle
Convenience method to toggle aObservableArray<Boolean>
at position x -
increaseValue
Convenience method to increase aObservableValue<Integer>
by 1 -
increase
Convenience method to increase aObservableArray<Integer>
by 1 at position x -
decreaseValue
Convenience method to decrease aObservableValue<Integer>
by 1 -
decrease
Convenience method to decrease aObservableArray<Integer>
by 1 at position x -
remove
Convenience method to remove an element from anObservableArray<V>
- Type Parameters:
V
- the type of the array and element- Parameters:
observableArray
- the array that will be affectedelementToRemove
- the element to remove
-
add
Convenience method to add an element to anObservableArray<V>
asynchronously.- Type Parameters:
V
- the type of the array and element- Parameters:
observableArray
- the array that will be affectedelementToAdd
- the element to add
-
addUnique
Convenience method to add an element to anObservableArray<V>
asynchronously but only if the array doesn't already contain that element.- Type Parameters:
V
- the type of the array and element- Parameters:
observableArray
- the array that will be affectedelementToAdd
- the element to add
-
pauseExecution
Utility function to pause execution of actions for the specified amount of time.An
InterruptedException
will be catched and ignored while setting the interrupt flag again.- Parameters:
duration
- time to sleep
-
updateModel
Use this if you need to update several ObservableValues in one async call.Use 'set', 'increase', 'decrease' or 'toggle' to get an appropriate Setter
-
set
-
increase
-
decrease
-
toggle
-
set
-