@Beta public class DelegateCommand extends javafx.concurrent.Service<Void> implements Command
Command implementation of a Service that encapsulates an Action (Task)
which can be called from the UI - for example after a button click. If the Action is a long running
operation, which would block your UI, you can pass a parameter to perform the Action in a background thread.
You can bind to the Service.isRunning() property while the action is executing. This can be used for a loading
indication in the UI.| Type | Property and Description |
|---|---|
javafx.beans.property.ReadOnlyBooleanProperty |
executable |
javafx.beans.property.ReadOnlyBooleanProperty |
notExecutable |
javafx.beans.property.ReadOnlyBooleanProperty |
notRunning |
exceptionProperty, executorProperty, messageProperty, onCancelledProperty, onFailedProperty, onReadyProperty, onRunningProperty, onScheduledProperty, onSucceededProperty, progressProperty, runningProperty, stateProperty, titleProperty, totalWorkProperty, valueProperty, workDonePropertyprogressProperty, runningProperty| Modifier and Type | Field and Description |
|---|---|
protected java.util.function.Supplier<Action> |
actionSupplier |
protected javafx.beans.property.ReadOnlyBooleanWrapper |
executable |
protected boolean |
inBackground |
protected javafx.beans.property.ReadOnlyBooleanWrapper |
notExecutable |
protected javafx.beans.property.ReadOnlyBooleanWrapper |
notRunning |
| Constructor and Description |
|---|
DelegateCommand(java.util.function.Supplier<Action> actionSupplier)
Creates a command without a condition about the executability.
|
DelegateCommand(java.util.function.Supplier<Action> actionSupplier,
boolean inBackground)
Creates a command without an condition about the executability.
|
DelegateCommand(java.util.function.Supplier<Action> actionSupplier,
javafx.beans.value.ObservableValue<Boolean> executableObservable)
Creates a command with a condition about the executability by using the 'executableObservable' parameter.
|
DelegateCommand(java.util.function.Supplier<Action> actionSupplier,
javafx.beans.value.ObservableValue<Boolean> executableObservable,
boolean inBackground)
Creates a command with a condition about the executability by using the 'executableObservable' parameter.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
callActionAndSynthesizeServiceRun() |
protected static javafx.beans.property.Property<Throwable> |
checkExceptionProperty(javafx.beans.property.ReadOnlyObjectProperty<Throwable> exceptionProperty) |
protected javafx.concurrent.Task<Void> |
createTask() |
javafx.beans.property.ReadOnlyBooleanProperty |
executableProperty() |
void |
execute()
This method will be called when the command is invoked.
|
java.util.function.Supplier<Action> |
getActionSupplier() |
boolean |
isExecutable()
Gets the value of the property executable.
|
boolean |
isNotExecutable()
Gets the value of the property notExecutable.
|
boolean |
isNotRunning()
Gets the value of the property notRunning.
|
javafx.beans.property.ReadOnlyBooleanProperty |
notExecutableProperty() |
javafx.beans.property.ReadOnlyBooleanProperty |
notRunningProperty() |
addEventFilter, addEventHandler, buildEventDispatchChain, cancel, cancelled, exceptionProperty, executeTask, executorProperty, failed, fireEvent, getException, getExecutor, getMessage, getOnCancelled, getOnFailed, getOnReady, getOnRunning, getOnScheduled, getOnSucceeded, getProgress, getState, getTitle, getTotalWork, getValue, getWorkDone, isRunning, messageProperty, onCancelledProperty, onFailedProperty, onReadyProperty, onRunningProperty, onScheduledProperty, onSucceededProperty, progressProperty, ready, removeEventFilter, removeEventHandler, reset, restart, running, runningProperty, scheduled, setEventHandler, setExecutor, setOnCancelled, setOnFailed, setOnReady, setOnRunning, setOnScheduled, setOnSucceeded, start, stateProperty, succeeded, titleProperty, totalWorkProperty, valueProperty, workDonePropertyclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetProgress, isRunning, progressProperty, runningPropertypublic javafx.beans.property.ReadOnlyBooleanProperty executableProperty
executableProperty in interface CommandisExecutable()public final javafx.beans.property.ReadOnlyBooleanProperty notExecutableProperty
notExecutableProperty in interface CommandisNotExecutable()public final javafx.beans.property.ReadOnlyBooleanProperty notRunningProperty
notRunningProperty in interface CommandisNotRunning()protected final java.util.function.Supplier<Action> actionSupplier
protected boolean inBackground
protected final javafx.beans.property.ReadOnlyBooleanWrapper executable
protected javafx.beans.property.ReadOnlyBooleanWrapper notExecutable
protected javafx.beans.property.ReadOnlyBooleanWrapper notRunning
public DelegateCommand(java.util.function.Supplier<Action> actionSupplier)
actionSupplier - a function that returns a new Action which should be executedpublic DelegateCommand(java.util.function.Supplier<Action> actionSupplier, boolean inBackground)
true to the
inBackground parameter to run the Command in a background thread.
IF YOU USE THE BACKGROUND THREAD: Your provided action will perform in a background thread. If you
manipulate data in your action, which will be propagated to the UI, use Platform.runLater(Runnable) for
this manipulation, otherwise you get an Exception by JavaFX.actionSupplier - a function that returns a new Action which should be executedinBackground - defines whether the execution execute() is performed in a background thread or notpublic DelegateCommand(java.util.function.Supplier<Action> actionSupplier, javafx.beans.value.ObservableValue<Boolean> executableObservable)
actionSupplier - a function that returns a new Action which should be executedexecutableObservable - which defines whether the Command can executepublic DelegateCommand(java.util.function.Supplier<Action> actionSupplier, javafx.beans.value.ObservableValue<Boolean> executableObservable, boolean inBackground)
true to the #inBackground parameter to run the Command in a background thread.
IF YOU USE THE BACKGROUND THREAD: don't forget to return to the UI-thread by using
Platform.runLater(Runnable), otherwise you get an Exception.public void execute()
Commandexecute in interface CommandCommand.execute()protected void callActionAndSynthesizeServiceRun()
protected javafx.concurrent.Task<Void> createTask()
createTask in class javafx.concurrent.Service<Void>public javafx.beans.property.ReadOnlyBooleanProperty executableProperty()
executableProperty in interface CommandisExecutable()public boolean isExecutable()
isExecutable in interface Commandtrue if the Command can executed, otherwise false.public final javafx.beans.property.ReadOnlyBooleanProperty notExecutableProperty()
notExecutableProperty in interface CommandisNotExecutable()public final boolean isNotExecutable()
isNotExecutable in interface Commandtrue if the Command can not execute, otherwise false.public final javafx.beans.property.ReadOnlyBooleanProperty notRunningProperty()
notRunningProperty in interface CommandisNotRunning()public final boolean isNotRunning()
isNotRunning in interface Commandtrue if the Command is not running, otherwise false.protected static javafx.beans.property.Property<Throwable> checkExceptionProperty(javafx.beans.property.ReadOnlyObjectProperty<Throwable> exceptionProperty)
public java.util.function.Supplier<Action> getActionSupplier()
Copyright © 2019 Saxonia Systems AG. All rights reserved.