List of usage examples for javafx.collections ObservableList size
int size();
From source file:com.github.naoghuman.testdata.abclist.service.ExerciseService.java
@Override protected Task<Void> createTask() { return new Task<Void>() { {//from w ww. j a v a 2 s .com updateProgress(0, saveMaxEntities); } @Override protected Void call() throws Exception { LoggerFacade.getDefault().deactivate(Boolean.TRUE); final StopWatch stopWatch = new StopWatch(); stopWatch.start(); final ObservableList<Topic> topics = SqlProvider.getDefault().findAllTopics(); final int removeMaxTopics = (int) (Double.parseDouble(String.valueOf(topics.size())) * 0.001d); for (int counter = removeMaxTopics; counter > 0; counter--) { topics.remove(TestdataGenerator.RANDOM.nextInt(topics.size())); } final int sizeTopics = topics.size(); final CrudService crudService = DatabaseFacade.getDefault().getCrudService(entityName); final ETime[] times = ETime.values(); final int sizeTimes = times.length; long id = -1_000_000_000L + DatabaseFacade.getDefault().getCrudService().count(entityName); for (int index = 0; index < saveMaxEntities; index++) { final Exercise exercise = ModelProvider.getDefault().getExercise(); exercise.setChoosenTime((times[TestdataGenerator.RANDOM.nextInt(sizeTimes)]).toString()); exercise.setConsolidated(false); // TODO later ? exercise.setFinishedTime(ExerciseService.this.createGenerationTime()); exercise.setGenerationTime(ExerciseService.this.createGenerationTime()); if (exercise.getGenerationTime() > exercise.getFinishedTime()) { final long generationTime = exercise.getGenerationTime(); final long finishedTime = exercise.getFinishedTime(); exercise.setGenerationTime(finishedTime); exercise.setFinishedTime(generationTime); } exercise.setId(id++); exercise.setReady(TestdataGenerator.RANDOM.nextDouble() > 0.001d); // TODO if ready then add terms final long topicId = topics.get(TestdataGenerator.RANDOM.nextInt(sizeTopics)).getId(); exercise.setTopicId(topicId); crudService.create(exercise); updateProgress(index, saveMaxEntities); } LoggerFacade.getDefault().deactivate(Boolean.FALSE); stopWatch.split(); LoggerFacade.getDefault().debug(this.getClass(), " + " + stopWatch.toSplitString() + " for " + saveMaxEntities + " Exercises."); // NOI18N stopWatch.stop(); return null; } }; }
From source file:org.pdfsam.ui.selection.multiple.SelectionTable.java
@EventListener public void onMoveSelected(final MoveSelectedEvent event) { getSortOrder().clear();//from w w w.j ava2 s. co m ObservableList<Integer> selectedIndices = getSelectionModel().getSelectedIndices(); Integer[] selected = selectedIndices.toArray(new Integer[selectedIndices.size()]); int focus = getFocusModel().getFocusedIndex(); getSelectionModel().clearSelection(); SelectionAndFocus newSelection = event.getType().move(selected, getItems(), focus); if (!SelectionAndFocus.NULL.equals(newSelection)) { LOG.trace("Changing selection to {}", newSelection); getSelectionModel().selectIndices(newSelection.getRow(), newSelection.getRows()); getFocusModel().focus(newSelection.getFocus()); scrollTo(newSelection.getFocus()); } }
From source file:com.github.naoghuman.testdata.abclist.service.LinkMappingService.java
@Override protected Task<Void> createTask() { return new Task<Void>() { {/* w w w . j a va 2s . 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:edu.kit.trufflehog.model.configdata.FilterDataModelTest.java
/** * <p>//from w w w. jav a 2 s. c o m * Tests the database for correct null entry handling. Nothing should be added to the database when a null * element is passed into the list. * </p> * * @throws Exception Passes any errors that occurred during the test on */ @Test public void testForNullEntry() throws Exception { filterDataModel.addFilterToDatabaseAsynchronous(null); // Wait for all threads to finish Thread.sleep(1000); // Retrieve them filterDataModel = new FilterDataModel(fileSystem); ObservableList<FilterInput> filterInputFromDB = filterDataModel.getAllFilters(); assertEquals(0, filterInputFromDB.size()); }
From source file:account.management.controller.ReportLedgerController.java
@FXML private void onLedgerIdInsert(KeyEvent event) { Platform.runLater(() -> {// w w w . ja v a 2 s .co m ObservableList<Account> account_list = this.account.getItems(); Pattern p = Pattern.compile("(?:[A-Za-z 0]+)?([0-9]+).*"); Matcher m = p.matcher(this.ledger_id.getText()); if (m.find()) { System.out.println("2: " + m.group(1)); int len = account_list.size(); for (int i = 0; i < len; i++) { if (account_list.get(i).getId() == Integer.parseInt(m.group(1))) { this.account.getSelectionModel().select(i); break; } } } }); }
From source file:main.Content.java
public void setData(ObservableList<String> treeData) { temp = FXCollections.observableArrayList(); for (int i = 0; i < treeData.size(); i++) { String index = treeData.get(i).toString(); System.out.println(treeData.size()); index = index.substring(0, 4);/* ww w. j a va2 s. co m*/ int parent = Integer.parseInt(index.substring(0, 1)); int id; if (index.charAt(3) == ' ') id = Integer.parseInt(index.substring(2, 3)); else id = Integer.parseInt(index.substring(2, 4)); for (int j = 0; j < data.size(); j++) { Activity tempData = data.get(j); if (tempData.getParentValue() == parent && tempData.getID() == id) { temp.add(tempData); break; } } } }
From source file:edu.kit.trufflehog.model.configdata.FilterDataModelTest.java
/** * <p>//from w w w. ja va 2s .c o m * Tests the database for correct duplicate entry handling. The same entry is added twice, but should only * be there once. * </p> * * @throws Exception Passes any errors that occurred during the test on */ // FIXME: 15.05.16 @Test @Ignore public void testForDuplicateEntry() throws Exception { FilterInput filterInput = generateRandomFilterInput(); filterDataModel.addFilterToDatabaseAsynchronous(filterInput); filterDataModel.addFilterToDatabaseAsynchronous(filterInput); // Wait for all threads to finish Thread.sleep(1000); // Retrieve them filterDataModel = new FilterDataModel(fileSystem); ObservableList<FilterInput> filterInputFromDB = filterDataModel.getAllFilters(); Map<String, FilterInput> filterInputMap = new HashMap<>(); filterInputFromDB.stream().forEach(fIn -> filterInputMap.put(fIn.getName(), fIn)); assertEquals(1, filterInputFromDB.size()); assertEquals(true, filterInputMap.containsKey(filterInput.getName())); }
From source file:dpfmanager.shell.interfaces.gui.component.report.ReportsView.java
void refreshTable(TableView tableView) { final ObservableList items = tableView.getItems(); if (items == null || items.size() == 0) return;/*from w w w. j a v a 2 s . c om*/ Object item = tableView.getItems().get(0); items.remove(item); Platform.runLater(new Runnable() { @Override public void run() { items.add(0, item); } }); }
From source file:com.ggvaidya.scinames.tabulardata.TabularDataViewController.java
/** * Initializes the controller class.//from w ww. j a v a 2 s . c o m */ public void initialize() { tableView.itemsProperty().addListener((ObservableValue observable, Object oldValue, Object newValue) -> { ObservableList<Object> list; if (ObservableList.class.isAssignableFrom(newValue.getClass())) { list = (ObservableList<Object>) newValue; if (list.isEmpty()) { statusTextField.setText("Table contains an empty list."); } else { Object example = list.get(0); statusTextField.setText("Table contains " + list.size() + " items of " + example.getClass()); } } else { statusTextField.setText("Table contains " + newValue); } }); }
From source file:de.ifsr.adam.ImageGenerator.java
/** * Takes a snapshot of the Pane and prints it to a pdf. * * @return True if no IOException occurred *///from w w w .jav a2s .c om private boolean printToPDF(String filePath, Pane pane) { //Scene set up Group root = new Group(); Scene printScene = new Scene(root); printScene.getStylesheets().add(this.stylesheetURI.toString()); //Snapshot generation ArrayList<WritableImage> images = new ArrayList<>(); try { ObservableList<Node> panes = pane.getChildren(); for (int i = 0; i < panes.size(); i++) { GridPane gridPane = (GridPane) panes.get(i); ((Group) printScene.getRoot()).getChildren().clear(); ((Group) printScene.getRoot()).getChildren().addAll(gridPane); images.add(printScene.snapshot(null)); panes.add(i, gridPane); } } catch (Exception e) { log.error(e); return false; } //PDF Setup File outFile = new File(filePath + "." + "pdf"); Iterator<WritableImage> iterImages = images.iterator(); PDDocument doc = new PDDocument(); try { while (iterImages.hasNext()) { //Page setup PDPage page = new PDPage(); doc.addPage(page); PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, false); //Image setup BufferedImage bufImage = SwingFXUtils.fromFXImage(iterImages.next(), null); PDPixelMap pixelMap = new PDPixelMap(doc, bufImage); int width = (int) (page.getMediaBox().getWidth()); int height = (int) (page.getMediaBox().getHeight()); Dimension dim = new Dimension(width, height); contentStream.drawXObject(pixelMap, 0, 0, dim.width, dim.height); contentStream.close(); } doc.save(outFile); return true; } catch (IOException | COSVisitorException e) { log.error(e); return false; } }