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 classprotected static final classprotected static interface -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected <V> voidadd(ObservableArray<V> observableArray, V elementToAdd) Convenience method to add an element to anObservableArray<V>asynchronously.protected <V> voidaddUnique(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 voidSchedule the given action for execution in strict order in external thread, asynchronously.protected voidSchedule the given action for execution in strict order in external thread, asynchronously.voidIntermediate solution for TestCase support.protected voiddecrease(ObservableArray<Integer> observableArray, int position) Convenience method to decrease aObservableArray<Integer>by 1 at position xprotected ControllerBase.Setter<Integer>decrease(ObservableValue<Integer> observableValue) protected voiddecreaseValue(ObservableValue<Integer> observableValue) Convenience method to decrease aObservableValue<Integer>by 1protected static <V> V[]get(ObservableArray<V> observableArray) protected static <V> Vget(ObservableArray<V> observableArray, int position) protected static <V> Vget(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 voidincrease(ObservableArray<Integer> observableArray, int position) Convenience method to increase aObservableArray<Integer>by 1 at position xprotected ControllerBase.Setter<Integer>increase(ObservableValue<Integer> observableValue) protected voidincreaseValue(ObservableValue<Integer> observableValue) Convenience method to increase aObservableValue<Integer>by 1protected voidpauseExecution(Duration duration) Utility function to pause execution of actions for the specified amount of time.protected <V> voidremove(ObservableArray<V> observableArray, V elementToRemove) Convenience method to remove an element from anObservableArray<V>voidprotected <V> ControllerBase.ArraySetter<V>set(ObservableArray<V> observableArray, V[] values) protected <V> ControllerBase.Setter<V>set(ObservableValue<V> observableValue, V value) protected <V> voidsetValue(ObservableArray<V> observableArray, int position, V newValue) Even for setting a value in the array the controller is responsible.protected <V> voidsetValue(ObservableValue<V> observableValue, V newValue) Even for setting a value the controller is responsible.protected <V> voidsetValues(ObservableArray<V> observableArray, V[] newValues) Even for setting values in the array the controller is responsible.voidshutdown()voidstartUp()If anything needs to be run once at startup from the controllerprotected static <V> voidsyncAdd(ObservableArray<V> arr, V elem) protected static <V> voidsyncAddUnique(ObservableArray<V> arr, V elem) protected static <V> voidsyncRemove(ObservableArray<V> arr, V elem) protected static <V> voidsyncSet(ObservableArray<V> arr, V[] newVal) protected static <V> voidsyncSet(ObservableValue<V> val, V newVal) protected voidtoggle(ObservableArray<Boolean> observableArray, int position) Convenience method to toggle aObservableArray<Boolean>at position xprotected ControllerBase.Setter<Boolean>toggle(ObservableValue<Boolean> observableValue) protected voidtoggleValue(ObservableValue<Boolean> observableValue) Convenience method to toggle aObservableValue<Boolean>protected voidupdateModel(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
InterruptedExceptionwill 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
-