Example usage for javafx.concurrent Service runningProperty

List of usage examples for javafx.concurrent Service runningProperty

Introduction

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

Prototype

@Override
    public final ReadOnlyBooleanProperty runningProperty() 

Source Link

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 -> {/*from   ww  w  . ja v  a2s .  c  o m*/
        // 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();
    }
}

From source file:pe.edu.system.jcmr.controlador.LoguinController.java

@FXML
public void btnOnSingIn(ActionEvent event) throws IOException {

    if (StringUtils.isBlank(txtUsuario.getText())) {
        lblMensaje.setText(/*from  w w  w .ja  v a 2s.c o  m*/
                getResourceMessage("required.campo.message", new Object[] { txtUsuario.getPromptText() }));
        return;
    }
    if (StringUtils.isBlank(txtPassword.getText())) {
        lblMensaje.setText(
                getResourceMessage("required.campo.message", new Object[] { txtPassword.getPromptText() }));
        return;
    }
    if (cboIdioma.getValue().getCodigo().equals("0")) {
        lblMensaje.setText(
                getResourceMessage("required.campo.message", new Object[] { cboIdioma.getPromptText() }));
        return;
    }
    Service<TbEmpleado> service = new Service<TbEmpleado>() {
        @Override
        protected Task<TbEmpleado> createTask() {
            return new Task<TbEmpleado>() {
                @Override
                protected TbEmpleado call() throws Exception {

                    TbEmpleado employed = employedService.authenticateUser(txtUsuario.getText(),
                            txtPassword.getText());

                    return employed;
                }
            };
        }

        @Override
        protected void succeeded() {
            SessionJCMR.getInstance().addContextObject("Usuario", getValue());
            SessionJCMR.getInstance().addContextObject("Lenguage", cboIdioma.getValue().getCodigo());
            closeWindow(btnSingIn);
            openWindow(MAIN_FXML);
        }

        @Override
        protected void failed() {
            lblMensaje.setText(getResourceMessage("errors.password.mismatch"));
        }

    };
    viewLoader.visibleProperty().bind(service.runningProperty());
    rgBack.visibleProperty().bind(service.runningProperty());
    service.start();

}