Example usage for javafx.concurrent Service start

List of usage examples for javafx.concurrent Service start

Introduction

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

Prototype

public void start() 

Source Link

Document

Starts this Service.

Usage

From source file:de.halirutan.spectralis.examples.sloexporter.Controller.java

public void exportFiles() {
    File outputDir = showDirectorySelectDialog("Select output directory");
    if (!outputDir.canWrite()) {
        Alert alert = new Alert(AlertType.ERROR, "Cannot write to output directory");
        alert.show();/* w w w . j a  va2  s  . c  om*/
    }

    Task<Integer> exportTask = new ExportWorker(outputDir);
    Service<Integer> service = new Service<Integer>() {
        @Override
        protected Task<Integer> createTask() {
            return exportTask;
        }
    };

    service.start();

}

From source file:mesclasses.objects.LoadWindow.java

private void temporize(long millis) {
    Service<Object> service = new Service() {
        @Override//from   w  w w  .j  ava 2s  . c o  m
        protected Task createTask() {
            return new WaitTask(millis);
        }
    };
    service.stateProperty().addListener(
            (ObservableValue<? extends Worker.State> o, Worker.State oldValue, Worker.State newValue) -> {
                switch (newValue) {
                case FAILED:
                case CANCELLED:
                    successful = false;
                    dialogStage.close();
                    break;

                case SUCCEEDED:
                    next();
                }
            });
    service.start();
}

From source file:herudi.controller.controllSplash.java

private void longStart() {
    Service<ApplicationContext> service = new Service<ApplicationContext>() {
        @Override//from  w w w  .ja  va  2  s .  co  m
        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  w w w  .  jav  a 2  s.  c o m*/
        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 w  w .j  av  a2s  . 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//w w w. j a  va  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);
                    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);
    });
}

From source file:herudi.controller.customerController.java

private void displayZip() {
    Service<ObservableList<MicroMarket>> service = new Service<ObservableList<MicroMarket>>() {
        @Override/*  ww  w .java2  s . c o m*/
        protected Task<ObservableList<MicroMarket>> createTask() {
            return new Task<ObservableList<MicroMarket>>() {
                @Override
                protected ObservableList<MicroMarket> call() throws Exception {
                    ObservableList<MicroMarket> listTask = FXCollections.observableArrayList();
                    if (listTask == null) {
                        listTask = FXCollections.observableArrayList(crud.selectZip());
                    } else {
                        listTask.clear();
                        listTask.addAll(crud.selectZip());
                    }
                    cbZip.setItems(listTask);
                    return listTask;
                }
            };
        }
    };
    service.start();
}

From source file:herudi.controller.customerController.java

private void displayDiscountCode() {
    Service<ObservableList<DiscountCode>> service = new Service<ObservableList<DiscountCode>>() {
        @Override/*from w w  w.j ava 2s.  co m*/
        protected Task<ObservableList<DiscountCode>> createTask() {
            return new Task<ObservableList<DiscountCode>>() {
                @Override
                protected ObservableList<DiscountCode> call() throws Exception {
                    ObservableList<DiscountCode> listTask = FXCollections.observableArrayList();
                    if (listTask == null) {
                        listTask = FXCollections.observableArrayList(crud.selectCode());
                    } else {
                        listTask.clear();
                        listTask.addAll(crud.selectCode());
                    }
                    cbDiscount.setItems(listTask);
                    return listTask;
                }
            };
        }
    };
    service.start();
}

From source file:herudi.controller.productController.java

private void displayProductCode() {
    Service<ObservableList<ProductCode>> service = new Service<ObservableList<ProductCode>>() {
        @Override//w  w  w. j  ava  2s  .  co  m
        protected Task<ObservableList<ProductCode>> createTask() {
            return new Task<ObservableList<ProductCode>>() {
                @Override
                protected ObservableList<ProductCode> call() throws Exception {
                    ObservableList<ProductCode> listTask = FXCollections.observableArrayList();
                    if (listTask == null) {
                        listTask = FXCollections.observableArrayList(crud.selectProductCode());
                    } else {
                        listTask.clear();
                        listTask.addAll(crud.selectProductCode());
                    }
                    cbProductCode.setItems(listTask);
                    return listTask;
                }
            };
        }
    };
    service.start();
}

From source file:herudi.controller.productController.java

private void displayManufacturer() {
    Service<ObservableList<Manufacturer>> service = new Service<ObservableList<Manufacturer>>() {
        @Override//from w  w w.ja v  a2 s.c  om
        protected Task<ObservableList<Manufacturer>> createTask() {
            return new Task<ObservableList<Manufacturer>>() {
                @Override
                protected ObservableList<Manufacturer> call() throws Exception {
                    ObservableList<Manufacturer> listTask = FXCollections.observableArrayList();
                    if (listTask == null) {
                        listTask = FXCollections.observableArrayList(crud.selectManufacturerID());
                    } else {
                        listTask.clear();
                        listTask.addAll(crud.selectManufacturerID());
                    }
                    cbManufacturer.setItems(listTask);
                    return listTask;
                }
            };
        }
    };
    service.start();
}