List of usage examples for javafx.concurrent Task Task
public Task()
From source file:herudi.controller.customerController.java
private void displayZip() { Service<ObservableList<MicroMarket>> service = new Service<ObservableList<MicroMarket>>() { @Override/* w ww.jav a 2s .com*/ 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:io.uploader.drive.DriveUploader.java
private static void authorize(final Browser browser, final Callback<Credential> callback) { try {// w ww . java 2s . com // load client secrets GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(AuthenticationSettingsImpl.getClientSecretJson())); if (clientSecrets.getDetails().getClientId().startsWith("Enter") || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) { System.out.println( "Overwrite the src/main/resources/client_secrets.json file with the client secrets file " + "you downloaded from the Quickstart tool or manually enter your Client ID and Secret " + "from https://code.google.com/apis/console/?api=drive#project:94720202188 " + "into src/main/resources/client_secrets.json"); System.exit(1); } Configuration.INSTANCE.setAuthenticationSettingsImpl(new AuthenticationSettingsImpl(clientSecrets)); // Set up authorization code flow. Set<String> scopes = new HashSet<String>(); scopes.add(DriveScopes.DRIVE); // old api for large file support (where upload takes more than one hour) scopes.add("https://docs.google.com/feeds"); final GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets, scopes).setDataStoreFactory(dataStoreFactory) .setAccessType("offline").setApprovalPrompt("force").build(); // authorize final VerificationCodeReceiver receiver = new LocalServerReceiver(); ObserverService<Credential> service = new ObserverService<Credential>() { private volatile DriveUploaderAuthorizationCodeInstalledApp driveUploaderAuthorizationCodeInstalledApp = null; @Override protected Task<Credential> createTask() { Task<Credential> task = new Task<Credential>() { @Override protected Credential call() throws Exception { driveUploaderAuthorizationCodeInstalledApp = new DriveUploaderAuthorizationCodeInstalledApp( flow, receiver, browser); Credential credential = driveUploaderAuthorizationCodeInstalledApp.authorize("user"); return credential; } }; return task; } }; service.setOnSucceeded(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent t) { logger.info("Login success"); Credential ret = (Credential) t.getSource().getValue(); callback.onSuccess(ret); } }); appEvent.addObserver(service); service.start(); } catch (Exception e) { callback.onFailure(e); } }
From source file:ijfx.ui.plugin.panel.OverlayPanel.java
@EventHandler public void handleEvent(OverlaySelectedEvent event) { if (event.getOverlay() == null) { return;//from w ww . j ava2s. c o m } // task calculating the stats in a new thread Task<HashMap<String, Double>> task = new Task<HashMap<String, Double>>() { @Override protected HashMap<String, Double> call() throws Exception { return statsService.getStat(event.getDisplay(), event.getOverlay()); } @Override protected void succeeded() { super.succeeded(); tableView.getItems().clear(); this.getValue().forEach((key, value) -> { entries.add(new MyEntry(key, value)); }); } }; overlayProperty.setValue(event.getOverlay()); Platform.runLater(() -> updateChart(event.getOverlay())); ImageJFX.getThreadPool().submit(task); }
From source file:utilitybasedfx.MainGUIController.java
@FXML public void eventImportSource(ActionEvent event) { File selectedDir = Utils.dirChooser("Please choose the project source root folder"); File sourceDir = new File(Prefs.getSourcePath()); boolean shouldContinue = true; if (selectedDir != null) { if (sourceDir.isDirectory()) { Alert alert = new Alert(AlertType.CONFIRMATION); alert.setTitle("This project already exists!"); alert.setHeaderText("This project already has a src folder meaning it already has files imported"); alert.setContentText(// www . j a v a 2s. c o m "Are you sure you want to import the new source?\nPressing OK will delete the files previous imported to this project and replace them with the new files."); Optional<ButtonType> result = alert.showAndWait(); if (result.get() == ButtonType.OK) { sourceDir.delete(); } else { shouldContinue = false; } } if (shouldContinue) { shouldRefreshFileTree = true; enableWorking(new Task<String>() { @Override protected String call() throws InterruptedException { updateMessage("Copying Files..."); try { FileUtils.copyDirectory(selectedDir, sourceDir); } catch (IOException e) { Utils.stackErrorDialog(e); } updateMessage(""); return ""; //[FIXME] find a way to do this inline function without a class as return type } }); } } }
From source file:herudi.controller.productController.java
private void displayProductCode() { Service<ObservableList<ProductCode>> service = new Service<ObservableList<ProductCode>>() { @Override/*from ww w . j av a 2 s. 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:api.wiki.WikiNameApi2.java
private void processSpecific(String s, PeopleNameOption option, final ProgressCallback callback) { final TreeMap<String, String> values = getGenderNames(s); final float[] progressValues = ProgressUtil.getProgressValues(values.size()); int counter = 1; for (final String peopleName : values.values()) { final int c = counter++; callback.onProgressUpdate(progressValues[c]); Task<Void> task = new Task<Void>() { @Override//from w w w. j a v a 2s. com protected Void call() throws Exception { final File file = processName(peopleName, option); Platform.runLater(new Runnable() { @Override public void run() { callback.onProgress(processFile(peopleName, file)); } }); return null; } }; Thread thread = new Thread(task); thread.setPriority(Thread.MAX_PRIORITY); thread.start(); } }
From source file:herudi.controller.customerController.java
private void selectWithService() { Service<Integer> service = new Service<Integer>() { @Override/* w w w . ja va 2s .co 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.heliosdecompiler.helios.gui.view.editors.DisassemblerView.java
private Task<StyleSpans<Collection<String>>> computeHighlightingAsync(CodeArea codeArea) { String text = codeArea.getText(); Task<StyleSpans<Collection<String>>> task = new Task<StyleSpans<Collection<String>>>() { @Override//from ww w . j av a 2 s .c o m protected StyleSpans<Collection<String>> call() throws Exception { return computeHighlighting(text); } }; Executors.newSingleThreadExecutor().execute(task); return task; }
From source file:ui.main.MainViewController.java
@FXML public void handleTemporyButtonAction(ActionEvent event) { Task<Void> presenceWatchTask = new Task<Void>() { @Override/*w ww . ja v a 2 s . c o m*/ public Void call() throws Exception { while (true) { updateMessage(connectionManager.getMyPresence()); Thread.sleep(1000); } //return null; } }; presenceWatchTask.messageProperty() .addListener((obs, oldMessage, newMessage) -> presence.setText(newMessage)); new Thread(presenceWatchTask).start(); }
From source file:utilitybasedfx.MainGUIController.java
@FXML private void eventImportCompiled(ActionEvent event) { File selectedDir = Utils.dirChooser("Please choose the project classes root folder"); File classDir = new File(Prefs.getClassPath()); boolean shouldContinue = true; if (selectedDir != null) { if (classDir.isDirectory()) { Alert alert = new Alert(AlertType.CONFIRMATION); alert.setTitle("This project already exists!"); alert.setHeaderText(// www. j a v a 2s . c o m "This project already has a class folder meaning it already has files imported"); alert.setContentText( "Are you sure you want to import the new source?\nPressing OK will delete the files previous imported to this project and replace them with the new files."); Optional<ButtonType> result = alert.showAndWait(); if (result.get() == ButtonType.OK) { classDir.delete(); } else { shouldContinue = false; } } if (shouldContinue) { shouldRefreshFileTree = true; enableWorking(new Task<String>() { @Override protected String call() throws InterruptedException { updateMessage("Copying Files..."); try { FileUtils.copyDirectory(selectedDir, classDir); } catch (IOException e) { Utils.stackErrorDialog(e); } updateMessage(""); return ""; //[FIXME] find a way to do this inline function without a class as return type } }); } } }