Class ExecutionUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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.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.static <T> void
executeWhen(ObservableValue<? extends T> property, BiConsumer<T,T> consumer, boolean executeNow, BiFunction<T,T,Boolean> executionCondition, boolean isOneShot)
Executes the given action (as a consumer) when the givenObservableValue
changes.static void
runAndWait(Runnable runnable)
CallsrunAndWaitEx(Runnable)
but consumes/ignores any thrown exception.static void
runAndWaitEx(Runnable run)
Invokes a Runnable on the JavaFX Application Thread and waits for it to finish.static <V> V
tryCallableAndIgnore(Callable<V> callable)
Tries to execute the given callable but ignores the exception in case of fail.static <V> V
tryCallableAndPrint(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
- f 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 given action (as a consumer) when the givenObservableValue
changes.If executeNow is true the action will be immediately run, the first value will be null, the second will be the current observable's value.
When the observable changes the executionCondition is evaluated and if it's true the action will be run with two arguments passed to the consumer, the first is the observable's oldValue, the second is the observable's newValue.If isOneShot is true the listener will be removed from the observable as soon as it changes and executionCondition is true.
- Parameters:
property
- the observable to add a listener toconsumer
- the action as a consumer to offer both the oldValue and newValueexecuteNow
- to specify if the given action should be immediately executed if the expression is already trueexecutionCondition
- to specify when the action should be executedisOneShot
- 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 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
-