List of usage examples for javafx.concurrent WorkerStateEvent getSource
@Override
public Worker getSource()
From source file:io.uploader.drive.DriveUploader.java
private static void authorize(final Browser browser, final Callback<Credential> callback) { try {//from w w w.j ava 2 s . c o m // 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:caillou.company.clonemanager.gui.handler.AfterStatisticsComputedHandler.java
@Override public void handle(WorkerStateEvent event) { StatisticAnalyse statisticAnalyse = (StatisticAnalyse) event.getSource().getValue(); StatisticsModel searchStatisticsModel = mainModel.getSearchStatisticsModel(); TaskModel.TASK currentTask = mainModel.getTaskModel().getCurrentTask(); searchStatisticsModel.setNbScannedFiles(statisticAnalyse.getNbFileScanned()); switch (currentTask) { case DETECT_DOUBLONS: if (searchStatisticsModel.getInitialSpaceWasted().equals(new Long(-1))) { searchStatisticsModel.setInitialSpaceWasted(statisticAnalyse.getWastedSpace()); }//from w ww . j av a 2 s .c om searchStatisticsModel.setNbDuplicateFiles(statisticAnalyse.getNumberOfDuplicateFiles()); searchStatisticsModel.setSpaceWasted(statisticAnalyse.getWastedSpace()); break; case DETECT_MISSING: searchStatisticsModel.setSpaceToDuplicate(statisticAnalyse.getSpaceToDuplicate()); searchStatisticsModel.setNbFileToDuplicate(statisticAnalyse.getNbFileToDuplicate()); break; } }
From source file:caillou.company.clonemanager.gui.handler.AfterEnqueueHandler.java
@Override public void handle(WorkerStateEvent event) { VisitDirectoriesResult visitDirectoriesResult = (VisitDirectoriesResult) event.getSource().getValue(); Long byteToTreat = visitDirectoriesResult.getByteToTreat(); FilterStrategy<String, ApplicationFile> partialHashStrategy = null; final LocationsModel locationsModel = mainModel.getLocationsModel(); final TaskModel.TASK currentTask = mainModel.getTaskModel().getCurrentTask(); switch (currentTask) { case DETECT_DOUBLONS: if (locationsModel.isDetectsIdentiqueFilesWithinALocation()) { partialHashStrategy = new DoublonsPartialHashStrategy(); } else {//from ww w .j a v a2 s. c o m partialHashStrategy = new DoublonsPlusGroupPartialHashStrategy(); } break; case DETECT_MISSING: partialHashStrategy = new MissingPartialHashStrategy(); break; } partialHashTask.setFilterStrategy(partialHashStrategy); partialHashTask.setBytesToTreat(byteToTreat); partialHashTask.setMyFilesToTreat(visitDirectoriesResult.getFilesToTreat()); // Attach the progress bar to that task ProgressIndicator partialTaskProgress = transitionController.getProgressBarPartialHashId(); partialTaskProgress.progressProperty().bind(partialHashTask.progressProperty()); afterPartialHashTaskHandler.setTransitionController(transitionController); partialHashTask.setOnSucceeded(afterPartialHashTaskHandler); new Thread(partialHashTask).start(); }
From source file:caillou.company.clonemanager.gui.handler.PreSuppressionEventHandler.java
@Override public void handle(WorkerStateEvent event) { List<GUIApplicationFile> fileToDelete = new ArrayList<>( (Set<GUIApplicationFile>) event.getSource().getValue()); handleEvent(fileToDelete);//from w w w. jav a2s .c om }
From source file:com.QuarkLabs.BTCeClientJavaFX.OrdersBookController.java
@FXML void initialize() { assert asksTable != null : "fx:id=\"asksTable\" was not injected: check your FXML file 'ordersbooklayout.fxml'."; assert asksTablePriceColumn != null : "fx:id=\"asksTablePriceColumn\" was not injected: check your FXML file 'ordersbooklayout.fxml'."; assert asksTableVolumeColumn != null : "fx:id=\"asksTableVolumeColumn\" was not injected: check your FXML file 'ordersbooklayout.fxml'."; assert bidsTable != null : "fx:id=\"bidsTable\" was not injected: check your FXML file 'ordersbooklayout.fxml'."; assert bidsTablePriceColumn != null : "fx:id=\"bidsTablePriceColumn\" was not injected: check your FXML file 'ordersbooklayout.fxml'."; assert bidsTableVolumeColumn != null : "fx:id=\"bidsTableVolumeColumn\" was not injected: check your FXML file 'ordersbooklayout.fxml'."; asksTable.setItems(asks);/* w ww.j a v a 2s. co m*/ bidsTable.setItems(bids); asksTablePriceColumn.setCellValueFactory(new PropertyValueFactory<OrdersBookEntry, Double>("price")); asksTableVolumeColumn.setCellValueFactory(new PropertyValueFactory<OrdersBookEntry, Double>("volume")); asksTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); bidsTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); bidsTablePriceColumn.setCellValueFactory(new PropertyValueFactory<OrdersBookEntry, Double>("price")); bidsTableVolumeColumn.setCellValueFactory(new PropertyValueFactory<OrdersBookEntry, Double>("volume")); Task<JSONObject> loadOrdersBook = new Task<JSONObject>() { @Override protected JSONObject call() throws Exception { return App.getOrdersBook(pair); } }; loadOrdersBook.setOnSucceeded(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent workerStateEvent) { JSONObject jsonObject = (JSONObject) workerStateEvent.getSource().getValue(); JSONArray asksArray = jsonObject.optJSONArray("asks"); JSONArray bidsArray = jsonObject.optJSONArray("bids"); for (int i = 0; i < asksArray.length(); i++) { JSONArray item = asksArray.optJSONArray(i); OrdersBookEntry ordersBookEntry = new OrdersBookEntry(); ordersBookEntry.setPrice(item.optDouble(0)); ordersBookEntry.setVolume(item.optDouble(1)); asks.add(ordersBookEntry); } for (int i = 0; i < bidsArray.length(); i++) { JSONArray item = bidsArray.optJSONArray(i); OrdersBookEntry ordersBookEntry = new OrdersBookEntry(); ordersBookEntry.setPrice(item.optDouble(0)); ordersBookEntry.setVolume(item.optDouble(1)); bids.add(ordersBookEntry); } } }); Thread thread = new Thread(loadOrdersBook); thread.start(); }
From source file:com.QuarkLabs.BTCeClientJavaFX.PublicTradesController.java
@FXML void initialize() { assert publicTradesTable != null : "fx:id=\"publicTradesTable\" was not injected: check your FXML file 'markettrades.fxml'."; assert publicTradesTableAmountColumn != null : "fx:id=\"publicTradesTableAmountColumn\" was not injected: check your FXML file 'markettrades.fxml'."; assert publicTradesTableDateColumn != null : "fx:id=\"publicTradesTableDateColumn\" was not injected: check your FXML file 'markettrades.fxml'."; assert publicTradesTableItemColumn != null : "fx:id=\"publicTradesTableItemColumn\" was not injected: check your FXML file 'markettrades.fxml'."; assert publicTradesTablePriceColumn != null : "fx:id=\"publicTradesTablePriceColumn\" was not injected: check your FXML file 'markettrades.fxml'."; assert publicTradesTablePriceCurrencyColumn != null : "fx:id=\"publicTradesTablePriceCurrencyColumn\" was not injected: check your FXML file 'markettrades.fxml'."; assert publicTradesTableTIDColumn != null : "fx:id=\"publicTradesTableTIDColumn\" was not injected: check your FXML file 'markettrades.fxml'."; assert publicTradesTableTradeTypeColumn != null : "fx:id=\"publicTradesTableTradeTypeColumn\" was not injected: check your FXML file 'markettrades.fxml'."; publicTradesTable.setItems(publicTrades); publicTradesTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); publicTradesTableAmountColumn.setCellValueFactory(new PropertyValueFactory<PublicTrade, Double>("amount")); publicTradesTableDateColumn.setCellValueFactory( new Callback<TableColumn.CellDataFeatures<PublicTrade, String>, ObservableValue<String>>() { @Override//from w w w. j a va2 s.c o m public ObservableValue<String> call( TableColumn.CellDataFeatures<PublicTrade, String> publicTradeStringCellDataFeatures) { PublicTrade publicTrade = publicTradeStringCellDataFeatures.getValue(); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(publicTrade.getDate() * 1000); DateFormat dateFormat = DateFormat.getDateTimeInstance(); return new SimpleStringProperty(dateFormat.format(calendar.getTime())); } }); publicTradesTableItemColumn.setCellValueFactory(new PropertyValueFactory<PublicTrade, String>("item")); publicTradesTablePriceColumn.setCellValueFactory(new PropertyValueFactory<PublicTrade, Double>("price")); publicTradesTablePriceCurrencyColumn .setCellValueFactory(new PropertyValueFactory<PublicTrade, String>("priceCurrency")); publicTradesTableTIDColumn.setCellValueFactory(new PropertyValueFactory<PublicTrade, Long>("tid")); publicTradesTableTradeTypeColumn .setCellValueFactory(new PropertyValueFactory<PublicTrade, String>("tradeType")); Task<JSONArray> loadPublicTrades = new Task<JSONArray>() { @Override protected JSONArray call() throws Exception { return App.getPublicTrades(pair); } }; loadPublicTrades.setOnSucceeded(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent workerStateEvent) { JSONArray jsonArray = (JSONArray) workerStateEvent.getSource().getValue(); publicTrades.clear(); for (int i = 0; i < jsonArray.length(); i++) { JSONObject item = jsonArray.getJSONObject(i); PublicTrade publicTrade = new PublicTrade(); publicTrade.setDate(item.getLong("date")); publicTrade.setAmount(item.getDouble("amount")); publicTrade.setItem(item.getString("item")); publicTrade.setPrice(item.getDouble("price")); publicTrade.setPriceCurrency(item.getString("price_currency")); publicTrade.setTid(item.getLong("tid")); publicTrade.setTradeType(item.getString("trade_type")); publicTrades.add(publicTrade); } } }); Thread thread = new Thread(loadPublicTrades); thread.start(); }
From source file:caillou.company.clonemanager.gui.handler.RemoveFromViewHandler.java
@Override public void handle(WorkerStateEvent event) { List<GUIApplicationFile> fileToReinject = new ArrayList<>(); List<GUIApplicationFile> deletedFiles = (List<GUIApplicationFile>) event.getSource().getValue(); for (GUIApplicationFile myFileFX : deletedFiles) { List<GUIApplicationFile> listFromTableView = suppressOnlyOnSelected ? tableView.getSelectionModel().getSelectedItems() : tableView.getItems();/*w ww .ja v a2 s. c o m*/ for (GUIApplicationFile selectedFile : listFromTableView) { if (selectedFile.getAbsolutePath().equals(myFileFX.getAbsolutePath())) { guiApplicationFileList.remove(selectedFile); if (fileToReinject.contains(selectedFile)) { fileToReinject.remove(selectedFile); } GUIApplicationFile myFileAlone = GUIApplicationFileUtil.isolateSingleFile(tableView.getItems(), selectedFile); if (myFileAlone != null) { fileToReinject.add(myFileAlone); } break; } } } for (GUIApplicationFile myFileFX : fileToReinject) { guiApplicationFileList.remove(myFileFX); guiApplicationFileList.add(myFileFX); } StatisticToCompute statisticToCompute = SpringFxmlLoader.getBean(null, StatisticToCompute.class); ComputeStatisticTask computeStatisticTask = SpringFxmlLoader.getBean(ComputeStatisticTask.class); computeStatisticTask.setStatisticToCompute(statisticToCompute); computeStatisticTask.setResultingList(guiApplicationFileList); AfterStatisticsComputedHandler afterStatisticsComputedHandler = SpringFxmlLoader .getBean(AfterStatisticsComputedHandler.class); computeStatisticTask.setOnSucceeded(afterStatisticsComputedHandler); new Thread(computeStatisticTask).start(); }
From source file:com.QuarkLabs.BTCeClientJavaFX.MainController.java
/** * Gets funds data from server, displays error message at the Log field in case of any Exception *//*from www . java 2 s . c o m*/ @FXML private void updateFunds() { Task<JSONObject> task = new Task<JSONObject>() { @Override protected JSONObject call() throws Exception { try { return app.getAccountInfo(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return new JSONObject(); } }; task.setOnSucceeded(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent workerStateEvent) { JSONObject jsonObject = (JSONObject) workerStateEvent.getSource().getValue(); //TODO make a check for errors if (jsonObject.optInt("success", 0) == 1) { parseFundsObject(jsonObject.optJSONObject("return").optJSONObject("funds")); } else { logField.appendText(ERROR_TITLE + jsonObject.optString("error", SOMETHING_WENT_WRONG) + "\r\n"); } } }); task.setOnFailed(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent workerStateEvent) { logField.appendText(workerStateEvent.getSource().getException().getMessage() + "\r\n"); } }); Thread thread = new Thread(task); thread.start(); }
From source file:com.QuarkLabs.BTCeClientJavaFX.MainController.java
/** * Reads data from Trading section, sends trade request to server * Displays error message at the Log field in case of any Exception * * @param event Source fired an event (either "Buy" or "Sell" button) *///from ww w . j a v a 2 s . co m @FXML private void makeTradeRequest(final ActionEvent event) { Task<JSONObject> task = new Task<JSONObject>() { @Override protected JSONObject call() throws Exception { String type; String idOfSource = ((Button) event.getSource()).getId(); if (buyButton.getId().equals(idOfSource)) { type = "buy"; } else { type = "sell"; } String pair = tradeCurrencyType.getValue().toLowerCase() + "_" + tradePriceCurrencyType.getValue().toLowerCase(); String rate = tradePriceValue.getText(); String amount = tradeAmountValue.getText(); return app.trade(pair, type, rate, amount); } }; task.setOnSucceeded(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent workerStateEvent) { JSONObject jsonObject = (JSONObject) workerStateEvent.getSource().getValue(); if (jsonObject.optInt("success") == 1) { parseFundsObject(jsonObject.optJSONObject("return").optJSONObject("funds")); logField.appendText("Order ID = " + jsonObject.optJSONObject("return").optString("order_id") + " was registered successfully" + "\r\n"); } else { logField.appendText(ERROR_TITLE + jsonObject.optString("error", SOMETHING_WENT_WRONG) + "\r\n"); } } }); task.setOnFailed(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent workerStateEvent) { logField.appendText(workerStateEvent.getSource().getException().getMessage() + "\r\n"); } }); Thread thread = new Thread(task); thread.start(); }
From source file:com.QuarkLabs.BTCeClientJavaFX.MainController.java
/** * Gets Active Orders data from server, displays error message at the Log field in case of any Exception *//*from w w w . j a v a 2 s .c om*/ @FXML private void showActiveOrders() { Task<JSONObject> task = new Task<JSONObject>() { @Override protected JSONObject call() throws Exception { try { return app.getActiveOrders(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return new JSONObject(); } }; task.setOnSucceeded(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent workerStateEvent) { JSONObject jsonObject = (JSONObject) workerStateEvent.getSource().getValue(); if (jsonObject.optInt("success") == 1) { JSONObject data = jsonObject.getJSONObject("return"); for (Iterator iterator = data.keys(); iterator.hasNext();) { String key = (String) iterator.next(); ActiveOrder activeOrder = new ActiveOrder(); activeOrder.setId(Long.parseLong(key)); activeOrder.setAmount(data.optJSONObject(key).optDouble("amount")); activeOrder.setRate(data.optJSONObject(key).optDouble("rate")); activeOrder.setStatus(data.optJSONObject(key).optInt("status")); activeOrder.setTimestamp(data.optJSONObject(key).optLong("timestamp_created")); activeOrder.setPair(data.optJSONObject(key).optString("pair")); activeOrder.setType(data.optJSONObject(key).optString("type")); activeOrders.add(activeOrder); } activeOrdersTable.setItems(activeOrders); } else { logField.appendText(ERROR_TITLE + jsonObject.optString("error", SOMETHING_WENT_WRONG) + "\r\n"); } } }); task.setOnFailed(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent workerStateEvent) { logField.appendText(workerStateEvent.getSource().getException().getMessage() + "\r\n"); } }); Thread thread = new Thread(task); thread.start(); }