Example usage for javafx.concurrent Service setOnFailed

List of usage examples for javafx.concurrent Service setOnFailed

Introduction

In this page you can find the example usage for javafx.concurrent Service setOnFailed.

Prototype

public final void setOnFailed(EventHandler<WorkerStateEvent> value) 

Source Link

Document

The onFailed event handler is called whenever the Task state transitions to the FAILED state.

Usage

From source file:dtv.controller.FXMLMainController.java

private void handleTask(Service<List<DVBChannel>> task, String zeTitle, String action) throws Exception {

    pi.visibleProperty().bind(task.runningProperty());
    pi.progressProperty().bind(task.progressProperty());

    task.setOnSucceeded(t -> {/*w  w w  .  jav  a2 s. c om*/
        // print services into tableview
        List<DVBChannel> dvbServices = task.getValue();
        if (dvbServices != null) {
            if (action.contains(DVB_S2)) {
                serviceDataS2.setAll(dvbServices);
                serviceDVBS2Table.setItems(sortedDataS2);
            } else if (action.contains(DVB_T2)) {
                serviceDataT2.setAll(dvbServices);
                serviceDVBT2Table.setItems(sortedDataT2);
            }
        }

        if (zeTitle != null)
            title.setText(zeTitle);
        disableComponents(false);
    });

    task.setOnFailed(t -> {
        LOG.error("Exception while executing task", task.getException());
        Message.errorMessage("Error " + action + "\n" + task.getException().getMessage());
    });

    if (!task.isRunning()) {
        task.reset();
        task.start();
    }
}