Example usage for javafx.concurrent Worker getState

List of usage examples for javafx.concurrent Worker getState

Introduction

In this page you can find the example usage for javafx.concurrent Worker getState.

Prototype

public State getState();

Source Link

Document

Specifies the current state of this Worker.

Usage

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 w w  .j  a  va 2s  .co  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;

}