@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, workDoneProperty
progressProperty, runningProperty
Modifier and Type | Field and Description |
---|---|
protected javafx.beans.property.ReadOnlyBooleanWrapper |
executable |
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.ObservableBooleanValue executableBinding)
Creates a command with a condition about the executability by using the #executableBinding parameter.
|
DelegateCommand(java.util.function.Supplier<Action> actionSupplier,
javafx.beans.value.ObservableBooleanValue executableBinding,
boolean inBackground)
Creates a command with a condition about the executability by using the #executableBinding parameter.
|
Modifier and Type | Method and Description |
---|---|
protected javafx.concurrent.Task<Void> |
createTask() |
javafx.beans.property.ReadOnlyBooleanProperty |
executableProperty() |
void |
execute()
This method will be called when the command is invoked.
|
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, workDoneProperty
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getProgress, isRunning, progressProperty, runningProperty
public javafx.beans.property.ReadOnlyBooleanProperty executableProperty
executableProperty
in interface Command
isExecutable()
public final javafx.beans.property.ReadOnlyBooleanProperty notExecutableProperty
notExecutableProperty
in interface Command
isNotExecutable()
public final javafx.beans.property.ReadOnlyBooleanProperty notRunningProperty
notRunningProperty
in interface Command
isNotRunning()
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.ObservableBooleanValue executableBinding)
actionSupplier
- a function that returns a new Action which should be executedexecutableBinding
- which defines whether the Command
can executepublic DelegateCommand(java.util.function.Supplier<Action> actionSupplier, javafx.beans.value.ObservableBooleanValue executableBinding, 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()
Command
execute
in interface Command
Command.execute()
protected javafx.concurrent.Task<Void> createTask()
createTask
in class javafx.concurrent.Service<Void>
public javafx.beans.property.ReadOnlyBooleanProperty executableProperty()
executableProperty
in interface Command
isExecutable()
public boolean isExecutable()
isExecutable
in interface Command
true
if the Command
can executed, otherwise false
.public final javafx.beans.property.ReadOnlyBooleanProperty notExecutableProperty()
notExecutableProperty
in interface Command
isNotExecutable()
public final boolean isNotExecutable()
isNotExecutable
in interface Command
true
if the Command
can not execute, otherwise false
.public final javafx.beans.property.ReadOnlyBooleanProperty notRunningProperty()
notRunningProperty
in interface Command
isNotRunning()
public final boolean isNotRunning()
isNotRunning
in interface Command
true
if the Command
is not running, otherwise false
.Copyright © 2015 Saxonia Systems AG. All rights reserved.