List of usage examples for javafx.concurrent Worker stateProperty
public ReadOnlyObjectProperty<State> stateProperty();
From source file:Main.java
public static <V> BooleanBinding isFinishedProperty(Worker<V> worker) { return worker.stateProperty().isEqualTo(Worker.State.CANCELLED).or(worker.stateProperty() .isEqualTo(Worker.State.FAILED).or(worker.stateProperty().isEqualTo(Worker.State.SUCCEEDED))); }
From source file:Main.java
/** * Returns a property that defines the state of the given worker. Once the worker is done the value of the * property will be set to true/* w ww .ja va 2 s . c o m*/ * @param worker the worker * @return the property */ public static ReadOnlyBooleanProperty createIsDoneProperty(Worker<?> worker) { final BooleanProperty property = new SimpleBooleanProperty(); Consumer<Worker.State> stateChecker = (s) -> { if (s.equals(Worker.State.CANCELLED) || s.equals(Worker.State.FAILED) || s.equals(Worker.State.SUCCEEDED)) { property.setValue(true); } else { property.setValue(false); } }; worker.stateProperty().addListener((o, oldValue, newValue) -> stateChecker.accept(newValue)); stateChecker.accept(worker.getState()); return property; }