Example usage for javafx.concurrent Service setOnSucceeded

List of usage examples for javafx.concurrent Service setOnSucceeded

Introduction

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

Prototype

public final void setOnSucceeded(EventHandler<WorkerStateEvent> value) 

Source Link

Document

The onSucceeded event handler is called whenever the Task state transitions to the SUCCEEDED 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 -> {
        // 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);
            }/* w  w  w  . j a v a  2  s.  co  m*/
        }

        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:herudi.controller.controllSplash.java

private void longStart() {
    Service<ApplicationContext> service = new Service<ApplicationContext>() {
        @Override/*  w ww .j a v a 2 s  .c om*/
        protected Task<ApplicationContext> createTask() {
            return new Task<ApplicationContext>() {
                @Override
                protected ApplicationContext call() throws Exception {
                    ApplicationContext appContex = config.getInstance().getApplicationContext();
                    int max = appContex.getBeanDefinitionCount();
                    updateProgress(0, max);
                    for (int k = 0; k < max; k++) {
                        Thread.sleep(50);
                        updateProgress(k + 1, max);
                    }
                    return appContex;
                }
            };
        }
    };
    service.start();
    service.setOnRunning((WorkerStateEvent event) -> {
        new FadeInLeftTransition(lblWelcome).play();
        new FadeInRightTransition(lblRudy).play();
        new FadeInTransition(vboxBottom).play();
    });
    service.setOnSucceeded((WorkerStateEvent event) -> {
        config2 config = new config2();
        config.newStage(stage, lblClose, "/herudi/view/login.fxml", "Sample Apps", true, StageStyle.UNDECORATED,
                false);
    });
}

From source file:herudi.controller.microMarketController.java

private void selectWithService() {
    Service<Integer> service = new Service<Integer>() {
        @Override/*from   www.jav  a 2s  .c  om*/
        protected Task<Integer> createTask() {
            selectData();
            return new Task<Integer>() {
                @Override
                protected Integer call() throws Exception {
                    Integer max = crud.selectData().size();
                    if (max > 35) {
                        max = 30;
                    }
                    updateProgress(0, max);
                    for (int k = 0; k < max; k++) {
                        Thread.sleep(40);
                        updateProgress(k + 1, max);
                    }
                    return max;
                }
            };
        }
    };
    service.start();
    bar.progressProperty().bind(service.progressProperty());
    service.setOnRunning((WorkerStateEvent event) -> {
        imgLoad.setVisible(true);
    });
    service.setOnSucceeded((WorkerStateEvent event) -> {
        imgLoad.setVisible(false);
        new FadeInUpTransition(paneTabel).play();
    });
}

From source file:herudi.controller.customerController.java

private void selectWithService() {
    Service<Integer> service = new Service<Integer>() {
        @Override//w  ww.  ja  v  a2  s  .  c o m
        protected Task<Integer> createTask() {
            selectData();
            return new Task<Integer>() {
                @Override
                protected Integer call() throws Exception {
                    Integer max = crud.select().size();
                    if (max > 35) {
                        max = 30;
                    }
                    updateProgress(0, max);
                    for (int k = 0; k < max; k++) {
                        Thread.sleep(40);
                        updateProgress(k + 1, max);
                    }
                    return max;
                }
            };
        }
    };
    service.start();
    bar.progressProperty().bind(service.progressProperty());
    service.setOnRunning((WorkerStateEvent event) -> {
        imgLoad.setVisible(true);
    });
    service.setOnSucceeded((WorkerStateEvent event) -> {
        imgLoad.setVisible(false);
        new FadeInUpTransition(paneTabel).play();
    });
}

From source file:com.toyota.carservice.controller.SplashController.java

private void longStart() {
    Service<ApplicationContext> service = new Service<ApplicationContext>() {
        @Override//from ww  w .j  ava 2  s .com
        protected Task<ApplicationContext> createTask() {
            return new Task<ApplicationContext>() {
                @Override
                protected ApplicationContext call() throws Exception {
                    ApplicationContext appContex = config.getInstance().getApplicationContext();
                    int max = appContex.getBeanDefinitionCount();
                    updateProgress(0, max);
                    System.out.println(PathUtil.getRootPath());
                    File file = new File(PathUtil.getRootPath());

                    if (!file.exists()) {
                        file.mkdir();
                    }

                    if (max < 50) {
                        max = 50;
                    }
                    for (int k = 0; k < max; k++) {
                        Thread.sleep(50);
                        updateProgress(k + 1, max);
                    }
                    return appContex;
                }
            };
        }
    };
    service.start();
    service.setOnRunning((WorkerStateEvent event) -> {
        new FadeInLeftTransition(lblWelcome).play();
        new FadeInRightTransition(lblRudy).play();
        new FadeInTransition(vboxBottom).play();
    });
    service.setOnSucceeded((WorkerStateEvent event) -> {
        config2 config = new config2();
        config.newStage(stage, lblClose, "/com/toyota/carservice/view/formSwitchMode.fxml",
                "Aplikasi Informasi Service", true, StageStyle.UNDECORATED, false);
    });
}