-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidexecuteWhen(BooleanExpression booleanExpression, Runnable action, boolean executeNow, boolean addListenerIfTrue, boolean isOneShot) Executes the given action if the given expression and the executeNow parameter are true.static voidexecuteWhen(BooleanExpression booleanExpression, Runnable trueAction, Runnable falseAction, boolean executeTrueNow, boolean executeFalseNow, boolean addListenerIfTrue, boolean isOneShot) Executes the given truAction if the given expression and the executeTrueNow parameter are true.static voidexecuteWhen(Observable observable, Runnable action, boolean executeNow, Supplier<Boolean> executionCondition, boolean isOneShot) Executes the given action when the givenObservablechanges.static <T> voidexecuteWhen(ObservableValue<? extends T> property, BiConsumer<T, T> consumer, boolean executeNow, BiFunction<T, T, Boolean> executionCondition, boolean isOneShot) Executes the givenBiConsumeraction when the givenObservableValuechanges.static voidrunAndWait(Runnable runnable) CallsrunAndWaitEx(Runnable)but consumes/ignores any thrown exception.static voidrunAndWaitEx(Runnable run) Invokes a Runnable on the JavaFX Application Thread and waits for it to finish.static <V> VtryCallableAndIgnore(Callable<V> callable) Tries to execute the given callable but ignores the exception in case of fail.static <V> VtryCallableAndPrint(Callable<V> callable) Tries to execute the given callable and prints the stacktrace in case of exception.
-
Constructor Details
-
ExecutionUtils
public ExecutionUtils()
-
-
Method Details
-
runAndWaitEx
Invokes a Runnable on the JavaFX Application Thread and waits for it to finish.- Parameters:
run- The Runnable that has to be called on JFX thread.- Throws:
InterruptedException- If the execution is interrupted.ExecutionException- If an exception is occurred in the run method of the Runnable
-
runAndWait
CallsrunAndWaitEx(Runnable)but consumes/ignores any thrown exception. -
tryCallableAndPrint
Tries to execute the given callable and prints the stacktrace in case of exception.- Returns:
- the callable result or null in case of exception
-
tryCallableAndIgnore
Tries to execute the given callable but ignores the exception in case of fail.- Returns:
- the callable result or null in case of exception
-
executeWhen
public static <T> void executeWhen(ObservableValue<? extends T> property, BiConsumer<T, T> consumer, boolean executeNow, BiFunction<T, T, Boolean> executionCondition, boolean isOneShot) Executes the givenBiConsumeraction when the givenObservableValuechanges.The consumer inputs are the oldValue and the newValue of the observable.
If executeNow is true the consumer action is immediately executed with null as the oldValue and the current value as newValue, the listener is added anyway.
The executeCondition
BiFunctionis used to specify on what conditions the action can be executed, the inputs of the function are the oldValue and newValue of the observable.The isOneShot flag is to specify if the added listener should be removed after the first time the observable changes.
- Type Parameters:
T- the value type of the property- Parameters:
property- the observable to listen toconsumer- the action to perform on changeexecuteNow- to specify if the given action should be immediately executedexecutionCondition- to specify on what conditions the action should be executedisOneShot- to specify if the added listener should be removed after the first time the observable changes
-
executeWhen
public static void executeWhen(Observable observable, Runnable action, boolean executeNow, Supplier<Boolean> executionCondition, boolean isOneShot) Executes the given action when the givenObservablechanges.If executeNow is true the action is immediately executed.
Adds a listener to the observable and executes the given action every time the observable changes and the execution condition is met or just once if the isOneShot parameter is true.
- Parameters:
observable- the observable to listen toaction- the action to execute when the observable changesexecuteNow- to specify if the given action should be immediately executedexecutionCondition- to specify on what conditions the action should be executedisOneShot- to specify if the added listener should be removed after the first time the observable changes
-
executeWhen
public static void executeWhen(BooleanExpression booleanExpression, Runnable action, boolean executeNow, boolean addListenerIfTrue, boolean isOneShot) Executes the given action if the given expression and the executeNow parameter are true.If the given expression is false or the addListenerIfTrue parameter is true, adds a listener to the expression and executes the given action every time the property becomes true or just once if the isOneShot parameter is true.
- Parameters:
booleanExpression- the expression to evaluateaction- the action to execute when the expression is trueexecuteNow- to specify if the given action should be immediately executed if the expression is already trueaddListenerIfTrue- to specify if the listener should be added anyway to the expression even if it is already trueisOneShot- to specify if the added listener should be removed after the first time the expression becomes true
-
executeWhen
public static void executeWhen(BooleanExpression booleanExpression, Runnable trueAction, Runnable falseAction, boolean executeTrueNow, boolean executeFalseNow, boolean addListenerIfTrue, boolean isOneShot) Executes the given truAction if the given expression and the executeTrueNow parameter are true.Executes the given falseAction if the given expression is false and the executeFalseNow parameter is true.
If the given expression is false or the addListenerIfTrue parameter is true, adds a listener to the expression and executes the given trueAction every time the property becomes true, and the given falseAction every time the property becomes false, or just once if the isOneShot parameter is true.
- Parameters:
booleanExpression- the expression to evaluatetrueAction- the action to execute when the expression is truefalseAction- the action to execute when the expression is falseexecuteTrueNow- to specify if the given trueAction should be immediately executed if the expression is already trueexecuteFalseNow- to specify if the given falseAction should be immediately executed if the expression is already falseaddListenerIfTrue- to specify if the listener should be added anyway to the expression even if it is already trueisOneShot- to specify if the added listener should be removed after the first time the expression becomes true
-