List of usage examples for javafx.concurrent Task Task
public Task()
From source file:com.github.naoghuman.testdata.abclist.service.LinkMappingService.java
@Override protected Task<Void> createTask() { return new Task<Void>() { {/* ww w . j a v a 2 s. c o m*/ updateProgress(0, saveMaxEntities); } @Override protected Void call() throws Exception { LoggerFacade.getDefault().deactivate(Boolean.TRUE); final StopWatch stopWatch = new StopWatch(); stopWatch.start(); /* 1) over all links 2) if random > 0.005d then do 3) otherwise create a link without parent 4) get 1-10 terms, create LinkMapping foreach of them - means a link is mapped to 1-10 terms 5) get 0-10 topics, create LinkMapping foreach of them - means a link is mapped to 0-10 topics */ final ObservableList<Link> links = SqlProvider.getDefault().findAllLinks(); final ObservableList<Term> terms = SqlProvider.getDefault().findAllTerms(); final int sizeTerms = terms.size(); final ObservableList<Topic> topics = SqlProvider.getDefault().findAllTopics(); final int sizeTopics = topics.size(); final AtomicInteger index = new AtomicInteger(0); final CrudService crudService = DatabaseFacade.getDefault().getCrudService(entityName); final AtomicLong id = new AtomicLong( -1_000_000_000L + DatabaseFacade.getDefault().getCrudService().count(entityName)); links.stream() // 1 .forEach(link -> { // 2) Should the [Link] have a parent final double random = TestdataGenerator.RANDOM.nextDouble(); if (random > 0.005d) { // 4) Create [Link]s with parent [Term] final int maxTerms = TestdataGenerator.RANDOM.nextInt(10) + 1; for (int i = 0; i < maxTerms; i++) { final LinkMapping lm = ModelProvider.getDefault().getLinkMapping(); lm.setId(id.getAndIncrement()); final Term term = terms.get(TestdataGenerator.RANDOM.nextInt(sizeTerms)); lm.setParentId(term.getId()); lm.setParentType(LinkMappingType.TERM); lm.setChildId(link.getId()); lm.setChildType(LinkMappingType.LINK); crudService.create(lm); } // 5) Create [Link]s with parent [Topic] final int maxTopics = TestdataGenerator.RANDOM.nextInt(11); for (int i = 0; i < maxTopics; i++) { final LinkMapping lm = ModelProvider.getDefault().getLinkMapping(); lm.setId(id.getAndIncrement()); final Topic topic = topics.get(TestdataGenerator.RANDOM.nextInt(sizeTopics)); lm.setParentId(topic.getId()); lm.setParentType(LinkMappingType.TOPIC); lm.setChildId(link.getId()); lm.setChildType(LinkMappingType.LINK); crudService.create(lm); } } else { // 3) Some [Link]s havn't a parent final LinkMapping lm = ModelProvider.getDefault().getLinkMapping(); lm.setId(id.getAndIncrement()); lm.setParentId(IDefaultConfiguration.DEFAULT_ID); lm.setParentType(LinkMappingType.NOT_DEFINED); lm.setChildId(link.getId()); lm.setChildType(LinkMappingType.LINK); crudService.create(lm); } updateProgress(index.getAndIncrement(), saveMaxEntities); }); LoggerFacade.getDefault().deactivate(Boolean.FALSE); stopWatch.split(); LoggerFacade.getDefault().debug(this.getClass(), " + " + stopWatch.toSplitString() + " for " + saveMaxEntities + " LinkMappings."); // NOI18N stopWatch.stop(); return null; } }; }
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);/*www.j a v a2 s.c om*/ 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.kotcrab.vis.editor.CrashReporter.java
private void sendReport() { progressBox.setVisible(true);/*from w ww . j a v a 2 s . com*/ Task<Void> task = new Task<Void>() { @Override public Void call() { try { HttpURLConnection connection = (HttpURLConnection) new URL( REPORT_URL + "?filename=" + reportFile.getName()).openConnection(); connection.setDoOutput(true); connection.setRequestMethod("POST"); OutputStream os = connection.getOutputStream(); if (detailsTextArea.getText().equals("") == false) { os.write(("Details: " + detailsTextArea.getText()).getBytes()); os.write('\n'); } os.write(report.getBytes()); os.flush(); os.close(); BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); String s; while ((s = in.readLine()) != null) System.out.println("Server response: " + s); in.close(); System.out.println("Crash report sent"); } catch (IOException e) { e.printStackTrace(); } return null; } @Override protected void succeeded() { Platform.exit(); } @Override protected void failed() { Platform.exit(); } }; new Thread(task).start(); }
From source file:com.github.naoghuman.testdata.abclist.service.TermService.java
@Override protected Task<Void> createTask() { return new Task<Void>() { {//from w w w . jav a 2s . co m updateProgress(0, saveMaxEntities); } @Override protected Void call() throws Exception { LoggerFacade.getDefault().deactivate(Boolean.TRUE); final StopWatch stopWatch = new StopWatch(); stopWatch.start(); final CrudService crudService = DatabaseFacade.getDefault().getCrudService(entityName); long id = -1_000_000_000L + DatabaseFacade.getDefault().getCrudService().count(entityName); for (int index = 0; index < saveMaxEntities; index++) { final Term term = ModelProvider.getDefault() .getTerm(TestdataGenerator.getDefault().getUniqueTitles(index)); term.setId(id++); term.setDescription(TestdataGenerator.getDefault().getDescription()); term.setGenerationTime(TermService.this.createGenerationTime()); crudService.create(term); updateProgress(index, saveMaxEntities); } LoggerFacade.getDefault().deactivate(Boolean.FALSE); stopWatch.split(); LoggerFacade.getDefault().debug(this.getClass(), " + " + stopWatch.toSplitString() + " for " + saveMaxEntities + " Terms."); // NOI18N stopWatch.stop(); return null; } }; }
From source file:de.pro.dbw.application.testdata.service.DreamService.java
@Override protected Task<Void> createTask() { return new Task<Void>() { {//from w w w .j a v a 2 s . co m updateProgress(0, saveMaxEntities); } @Override protected Void call() throws Exception { LoggerFacade.INSTANCE.deactivate(Boolean.TRUE); final StopWatch stopWatch = new StopWatch(); stopWatch.start(); final ICrudService crudService = DatabaseFacade.INSTANCE.getCrudService(entityName); long id = -1_000_000_000L + DatabaseFacade.INSTANCE.getCrudService().count(entityName); for (int i = 1; i <= saveMaxEntities; i++) { crudService.beginTransaction(); final DreamModel model = new DreamModel(); model.setGenerationTime(DreamService.this.createGenerationTime()); model.setDescription(LoremIpsum.getDefault().getDescription()); model.setId(id++); model.setTitle(LoremIpsum.getDefault().getTitle()); model.setText(LoremIpsum.getDefault().getText()); crudService.create(model, false); updateProgress(i - 1, saveMaxEntities); crudService.commitTransaction(); } LoggerFacade.INSTANCE.deactivate(Boolean.FALSE); stopWatch.split(); LoggerFacade.INSTANCE.debug(this.getClass(), " + " + stopWatch.toSplitString() + " for " + saveMaxEntities + " Dreams."); // NOI18N stopWatch.stop(); return null; } }; }
From source file:com.github.naoghuman.testdata.abclist.service.TopicService.java
@Override protected Task<Void> createTask() { return new Task<Void>() { {//from w w w.j ava 2 s . c o m updateProgress(0, saveMaxEntities); } @Override protected Void call() throws Exception { LoggerFacade.getDefault().deactivate(Boolean.TRUE); final StopWatch stopWatch = new StopWatch(); stopWatch.start(); final CrudService crudService = DatabaseFacade.getDefault().getCrudService(entityName); long id = -1_000_000_000L + DatabaseFacade.getDefault().getCrudService().count(entityName); for (int index = 0; index < saveMaxEntities; index++) { final Topic topic = ModelProvider.getDefault().getTopic(id++, TestdataGenerator.getDefault().getUniqueTitles(index)); topic.setDescription(TestdataGenerator.getDefault().getDescription()); topic.setGenerationTime(TopicService.this.createGenerationTime()); crudService.create(topic); updateProgress(index, saveMaxEntities); } LoggerFacade.getDefault().deactivate(Boolean.FALSE); stopWatch.split(); LoggerFacade.getDefault().debug(this.getClass(), " + " + stopWatch.toSplitString() + " for " + saveMaxEntities + " Topics."); // NOI18N stopWatch.stop(); return null; } }; }
From source file:com.mycompany.pfinanzaspersonales.BuscadorController.java
@FXML private void btnBuscar(ActionEvent event) throws IOException { String desde_t = "", hasta_t = ""; if (input_desde.getValue() != null) { desde_t = input_desde.getValue().toString(); }/* w w w .j a v a 2 s.co m*/ if (input_hasta.getValue() != null) { hasta_t = input_hasta.getValue().toString(); } final String desde = desde_t; final String hasta = hasta_t; final Task<Void> tarea = new Task<Void>() { @Override protected Void call() throws Exception { HttpResponse response; List<NameValuePair> parametros = new ArrayList<NameValuePair>(); parametros.add(new BasicNameValuePair("tipo", cbb_tipo.getValue().toString())); parametros.add(new BasicNameValuePair("pago", cbb_pago.getValue().toString())); parametros.add(new BasicNameValuePair("desde", desde)); parametros.add(new BasicNameValuePair("hasta", hasta)); System.out.println(desde); response = JSON.request(Config.URL + "usuarios/buscar.json", parametros); JSONObject jObject = JSON.JSON(response); tabla_json = new ArrayList<TablaBuscar>(); try { editar.setCellValueFactory(new PropertyValueFactory<TablaBuscar, String>("editar")); eliminar.setCellValueFactory(new PropertyValueFactory<TablaBuscar, String>("eliminar")); fecha.setCellValueFactory(new PropertyValueFactory<TablaBuscar, String>("fecha")); categoria.setCellValueFactory(new PropertyValueFactory<TablaBuscar, String>("categoria")); tpago.setCellValueFactory(new PropertyValueFactory<TablaBuscar, String>("pago")); tmonto.setCellValueFactory(new PropertyValueFactory<TablaBuscar, String>("monto")); ttipo.setCellValueFactory(new PropertyValueFactory<TablaBuscar, String>("tipo")); tabla_json = new ArrayList<TablaBuscar>(); if (!jObject.get("data").equals(null)) { JSONArray jsonArr = jObject.getJSONArray("data"); for (int i = 0; i < jsonArr.length(); i++) { JSONObject data_json = jsonArr.getJSONObject(i); tabla_json.add(new TablaBuscar(data_json.get("idgastos").toString(), data_json.get("idgastos").toString(), data_json.get("idgastos").toString(), data_json.get("monto").toString(), data_json.get("fecha").toString(), data_json.get("nom_mediopago").toString(), data_json.get("categoria").toString(), data_json.get("tipo").toString())); } } tabla_buscador.setItems(FXCollections.observableArrayList(tabla_json)); } catch (Exception e) { e.printStackTrace(); } return null; } @Override protected void succeeded() { super.succeeded(); eliminar.setCellFactory(new Callback<TableColumn<String, String>, TableCell<String, String>>() { @Override public TableCell<String, String> call(TableColumn<String, String> p) { return new TableCell<String, String>() { @Override public void updateItem(String item, boolean empty) { super.updateItem(item, empty); if (!isEmpty() && !empty) { final VBox vbox = new VBox(5); Image image = new Image(getClass().getResourceAsStream("/Imagenes/delete.png")); final Button boton = new Button("", new ImageView(image)); boton.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { Action response = Dialogs.create().title("Eliminar Gasto") .message("Ests seguro que desaeas eliminar el gasto?") .showConfirm(); if (response == Dialog.ACTION_YES) { TablaBuscar tabla = tabla_json.get(getTableRow().getIndex()); List<NameValuePair> parametros = new ArrayList<NameValuePair>(); String url = ""; if (tabla.getTipo() == "Gastos") { parametros .add(new BasicNameValuePair("idgastos", tabla.getId())); url = Config.URL + "gastos/eliminar.json"; } else { parametros.add( new BasicNameValuePair("idingresos", tabla.getId())); url = Config.URL + "ingresos/eliminar.json"; } HttpResponse responseJSON = JSON.request(url, parametros); JSONObject jObject = JSON.JSON(responseJSON); int code = Integer.parseInt(jObject.get("code").toString()); if (code == 201) { int selectdIndex = getTableRow().getIndex(); tabla_json.remove(selectdIndex); tabla_buscador.getItems().remove(selectdIndex); } else { Dialogs.create().title("Error sincronizacin").message( "Hubo un error al intentar eliminar . ERROR: 301") .showInformation(); } } } }); vbox.getChildren().add(boton); setGraphic(vbox); } else { setGraphic(null); } } }; } }); editar.setCellFactory(new Callback<TableColumn<String, String>, TableCell<String, String>>() { @Override public TableCell<String, String> call(TableColumn<String, String> p) { return new TableCell<String, String>() { @Override public void updateItem(String item, boolean empty) { super.updateItem(item, empty); if (!isEmpty() && !empty) { final VBox vbox = new VBox(5); Image image = new Image(getClass().getResourceAsStream("/Imagenes/edit.png")); final Button boton = new Button("", new ImageView(image)); boton.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { TablaBuscar tabla = tabla_json.get(getTableRow().getIndex()); Parent parent = null; if (tabla.getTipo() == "Gastos") { AgregarGastos AG = AgregarGastos.getInstance(); AG.setID(tabla.getId()); AG.setMonto(tabla.getMonto()); AG.setCategoria(tabla.getCategoria()); AG.setPago(tabla.getPago()); AG.setActualizacion(true); try { parent = FXMLLoader.load(this.getClass() .getResource("/fxml/AgregarGastos.fxml")); } catch (IOException ex) { Logger.getLogger(FXMLController.class.getName()) .log(Level.SEVERE, null, ex); } } else { AgregarIngresos AI = AgregarIngresos.getInstance(); AI.setID(tabla.getId()); AI.setMonto(tabla.getMonto()); AI.setCategoria(tabla.getCategoria()); AI.setPago(tabla.getPago()); AI.setActualizar(true); try { parent = FXMLLoader.load(this.getClass() .getResource("/fxml/AgregarIngresos.fxml")); } catch (IOException ex) { Logger.getLogger(FXMLController.class.getName()) .log(Level.SEVERE, null, ex); } } Stage stage = new Stage(); Scene scene = new Scene(parent); stage.setScene(scene); stage.show(); } }); vbox.getChildren().add(boton); setGraphic(vbox); } else { setGraphic(null); } } }; } }); } }; new Thread(tarea).start(); }
From source file:com.github.naoghuman.testdata.abclist.service.LinkService.java
@Override protected Task<Void> createTask() { return new Task<Void>() { {/*from w ww .ja va 2 s .co m*/ updateProgress(0, saveMaxEntities); } @Override protected Void call() throws Exception { LoggerFacade.getDefault().deactivate(Boolean.TRUE); final StopWatch stopWatch = new StopWatch(); stopWatch.start(); final CrudService crudService = DatabaseFacade.getDefault().getCrudService(entityName); long id = -1_000_000_000L + DatabaseFacade.getDefault().getCrudService().count(entityName); for (int index = 0; index < saveMaxEntities; index++) { final Link link = ModelProvider.getDefault().getLink(); link.setAlias("Google " + id); // NOI18N link.setDescription(TestdataGenerator.getDefault().getDescription()); link.setFavorite(TestdataGenerator.RANDOM.nextDouble() < 0.01d); link.setGenerationTime(LinkService.this.createGenerationTime()); link.setId(id++); link.setImage("image-name"); // NOI18N // TODO add real image name link.setMarkAsChanged(false); link.setUrl("https:////www.google.com"); // NOI18N crudService.create(link); updateProgress(index, saveMaxEntities); } LoggerFacade.getDefault().deactivate(Boolean.FALSE); stopWatch.split(); LoggerFacade.getDefault().debug(this.getClass(), " + " + stopWatch.toSplitString() + " for " + saveMaxEntities + " Links."); // NOI18N stopWatch.stop(); return null; } }; }
From source file:de.pro.dbw.application.testdata.service.ReflectionService.java
@Override protected Task<Void> createTask() { return new Task<Void>() { {/*from w w w .ja v a2 s . c o m*/ updateProgress(0, saveMaxEntities); } @Override protected Void call() throws Exception { LoggerFacade.INSTANCE.deactivate(Boolean.TRUE); final StopWatch stopWatch = new StopWatch(); stopWatch.start(); final ICrudService crudService = DatabaseFacade.INSTANCE.getCrudService(entityName); long id = -1_000_000_000L + DatabaseFacade.INSTANCE.getCrudService().count(entityName); for (int i = 1; i <= saveMaxEntities; i++) { crudService.beginTransaction(); final ReflectionModel model = new ReflectionModel(); model.setGenerationTime(ReflectionService.this.createGenerationTime()); model.setId(id++); model.setTitle(LoremIpsum.getDefault().getTitle()); model.setText(LoremIpsum.getDefault().getText()); crudService.create(model, false); updateProgress(i - 1, saveMaxEntities); crudService.commitTransaction(); } LoggerFacade.INSTANCE.deactivate(Boolean.FALSE); stopWatch.split(); LoggerFacade.INSTANCE.debug(this.getClass(), " + " + stopWatch.toSplitString() + " for " + saveMaxEntities + " Reflections."); // NOI18N stopWatch.stop(); return null; } }; }
From source file:caillou.company.clonemanager.gui.customComponent.search.SearchController.java
private void buildTransitionPopup() { LoadingMojo loadingMojo = SpringFxmlLoader.load(Navigation.TRANSITION_POPUP); transitionController = (TransitionController) loadingMojo.getController(); transitionController.getEventBus().register(this); transitionFxml = loadingMojo.getParent(); final Dialog dialogTransition = new Dialog(MainApp.getInstance().getStage(), SpringFxmlLoader.getResourceBundle().getString("title.processingData")); dialogTransition.getStylesheets().add(StyleSheet.DIALOG_CSS); transitionController.setWrappingDialog(dialogTransition); dialogTransition.setContent(transitionFxml); Platform.runLater(new Task<Void>() { @Override/*from w w w .j a v a 2 s . c om*/ protected Void call() throws Exception { transitionController.getWrappingDialog().show(); return null; } }); }