List of usage examples for javafx.beans.property ReadOnlyStringWrapper ReadOnlyStringWrapper
public ReadOnlyStringWrapper(String initialValue)
From source file:jduagui.Controller.java
private TableColumn extNameColumn() { TableColumn<Map.Entry<String, Extension>, String> col = new TableColumn<>("Extension"); col.setCellValueFactory(//from w ww.ja v a2 s .com (TableColumn.CellDataFeatures<Map.Entry<String, Extension>, String> p) -> new ReadOnlyStringWrapper( "." + p.getValue().getKey())); return col; }
From source file:jduagui.Controller.java
private TableColumn extSizeColumn() { TableColumn<Map.Entry<String, Extension>, String> col = new TableColumn<>("Size Total"); col.setCellValueFactory((TableColumn.CellDataFeatures<Map.Entry<String, Extension>, String> p) -> { return new ReadOnlyStringWrapper(getByteSize(p.getValue().getValue().getSize())); });/*from w w w . j a va 2 s. c o m*/ col.setComparator(new sizeComparator()); return col; }
From source file:jduagui.Controller.java
private TableColumn extCountColumn() { TableColumn<Map.Entry<String, Extension>, String> col = new TableColumn<>("Items"); col.setCellValueFactory((TableColumn.CellDataFeatures<Map.Entry<String, Extension>, String> p) -> { return new ReadOnlyStringWrapper("" + p.getValue().getValue().getCount()); });/* www . j av a2s. c om*/ col.setComparator(new longComparator()); return col; }
From source file:com.ggvaidya.scinames.model.Dataset.java
/** * Set up a TableView to contain the data contained in this dataset. * //from www . j ava 2 s .c om * @param tv The TableView to populate. */ public void displayInTableView(TableView<DatasetRow> tv) { // Setup table. tv.setEditable(false); //controller.setTableColumnResizeProperty(TableView.CONSTRAINED_RESIZE_POLICY); ObservableList<TableColumn<DatasetRow, ?>> cols = tv.getColumns(); cols.clear(); // We need to precalculate. ObservableList<DatasetRow> rows = this.rowsProperty(); // Set up columns. TableColumn<DatasetRow, String> colRowName = new TableColumn<>("Name"); colRowName.setCellValueFactory((TableColumn.CellDataFeatures<DatasetRow, String> features) -> { DatasetRow row = features.getValue(); Set<Name> names = getNamesInRow(row); if (names.isEmpty()) { return new ReadOnlyStringWrapper("(None)"); } else { return new ReadOnlyStringWrapper( names.stream().map(name -> name.getFullName()).collect(Collectors.joining("; "))); } }); colRowName.setPrefWidth(100.0); cols.add(colRowName); // Create a column for every column here. this.getColumns().forEach((DatasetColumn col) -> { String colName = col.getName(); TableColumn<DatasetRow, String> colColumn = new TableColumn<>(colName); colColumn.setCellValueFactory((TableColumn.CellDataFeatures<DatasetRow, String> features) -> { DatasetRow row = features.getValue(); String val = row.get(colName); return new ReadOnlyStringWrapper(val == null ? "" : val); }); colColumn.setPrefWidth(100.0); cols.add(colColumn); }); // Set table items. // tv.getItems().clear(); tv.setItems(rows); }
From source file:com.ggvaidya.scinames.dataset.DatasetSceneController.java
private AdditionalData<String, DatasetRow> createDataAdditionalData() { Map<String, List<DatasetRow>> map = new HashMap<>(); map.put("All data (" + dataset.getRowCount() + " rows)", new ArrayList<DatasetRow>(dataset.rowsProperty())); List<TableColumn<DatasetRow, String>> cols = new LinkedList<>(); for (DatasetColumn col : dataset.getColumns()) { TableColumn<DatasetRow, String> column = new TableColumn<>(col.getName()); column.setCellValueFactory(cdf -> new ReadOnlyStringWrapper(cdf.getValue().get(col))); cols.add(column);//from www. ja v a2 s . c o m } return new AdditionalData("Data", Arrays.asList("All data (" + dataset.getRowCount() + " rows)"), map, cols); }
From source file:com.ggvaidya.scinames.dataset.DatasetSceneController.java
private AdditionalData<String, Map.Entry<String, String>> createPropertiesAdditionalData() { List<Map.Entry<String, String>> datasetProperties = new ArrayList<>(dataset.getProperties().entrySet()); Map<String, List<Map.Entry<String, String>>> map = new HashMap<>(); map.put("Dataset (" + datasetProperties.size() + ")", datasetProperties); List<TableColumn<Map.Entry<String, String>, String>> cols = new ArrayList<>(); TableColumn<Map.Entry<String, String>, String> colKey = new TableColumn<>("Key"); colKey.setCellValueFactory(cdf -> new ReadOnlyStringWrapper(cdf.getValue().getKey())); cols.add(colKey);// ww w . jav a 2 s.co m TableColumn<Map.Entry<String, String>, String> colValue = new TableColumn<>("Value"); colValue.setCellValueFactory(cdf -> new ReadOnlyStringWrapper(cdf.getValue().getValue())); cols.add(colValue); return new AdditionalData("Properties", Arrays.asList("Dataset (" + datasetProperties.size() + ")"), map, cols); }
From source file:com.ggvaidya.scinames.dataset.DatasetSceneController.java
private AdditionalData<Name, Map.Entry<String, String>> createDataByNameAdditionalData() { // Which names area we interested in? List<Change> selectedChanges = changesTableView.getItems(); List<Name> names = selectedChanges.stream().flatMap(ch -> { Set<Name> allNames = ch.getAllNames(); List<Name> binomials = allNames.stream().flatMap(n -> n.asBinomial()).collect(Collectors.toList()); List<Name> genus = allNames.stream().flatMap(n -> n.asGenus()).collect(Collectors.toList()); allNames.addAll(binomials);//from w w w . j av a 2 s . c om allNames.addAll(genus); return allNames.stream(); }).distinct().sorted().collect(Collectors.toList()); Project proj = datasetView.getProjectView().getProject(); Map<Name, List<Map.Entry<String, String>>> map = new HashMap<>(); for (Name n : names) { Map<DatasetColumn, Set<String>> dataForName = proj.getDataForName(n); Map<String, String> mapForName = dataForName.entrySet().stream() .collect(Collectors.toMap( (Map.Entry<DatasetColumn, Set<String>> entry) -> entry.getKey().toString(), (Map.Entry<DatasetColumn, Set<String>> entry) -> entry.getValue().toString())); map.put(n, new ArrayList<>(mapForName.entrySet())); } List<TableColumn<Map.Entry<String, String>, String>> cols = new ArrayList<>(); TableColumn<Map.Entry<String, String>, String> colKey = new TableColumn<>("Key"); colKey.setCellValueFactory(cdf -> new ReadOnlyStringWrapper(cdf.getValue().getKey())); cols.add(colKey); TableColumn<Map.Entry<String, String>, String> colValue = new TableColumn<>("Value"); colValue.setCellValueFactory(cdf -> new ReadOnlyStringWrapper(cdf.getValue().getValue())); cols.add(colValue); return new AdditionalData<Name, Map.Entry<String, String>>("Data by name", names, map, cols, changes -> changes.stream().flatMap(ch -> ch.getAllNames().stream()).collect(Collectors.toList())); }
From source file:com.ggvaidya.scinames.dataset.BinomialChangesSceneController.java
private AdditionalData<String, Map.Entry<String, String>> createSummaryAdditionalData() { List<Map.Entry<String, String>> summary = new ArrayList<>(); // Calculate some summary values. long numChanges = potentialChanges.size(); summary.add(new AbstractMap.SimpleEntry<String, String>("Number of binomial changes", String.valueOf(potentialChanges.size()))); // How many have a note? summary.add(new AbstractMap.SimpleEntry<String, String>("Number of changes with annotations", String.valueOf(potentialChanges.stream().filter(ch -> ch.getNote().isPresent()).count()))); // Calculate overall addition and deletion. // Summarize by types of change. Map<ChangeType, List<Change>> potentialChangesByType = potentialChanges.stream() .collect(Collectors.groupingBy(ch -> ch.getType())); summary.addAll(potentialChangesByType.keySet().stream().sorted() .map(type -> new AbstractMap.SimpleEntry<String, String>( "Number of binomial changes of type '" + type + "'", String.valueOf(potentialChangesByType.get(type).size()))) .collect(Collectors.toList())); // Summarize by reason. Map<String, Long> potentialChangesByReason = potentialChanges.stream() .map(pc -> pc.getType() + " because of " + calculateReason(pc)) .collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); summary.addAll(potentialChangesByReason.keySet().stream().sorted() .map(reason -> new AbstractMap.SimpleEntry<String, String>( "Number of binomial changes for reason '" + reason + "'", potentialChangesByReason.get(reason).toString())) .collect(Collectors.toList())); // Make an additional data about it. Map<String, List<Map.Entry<String, String>>> map = new HashMap<>(); map.put("Summary", summary); List<TableColumn<Map.Entry<String, String>, String>> cols = new ArrayList<>(); TableColumn<Map.Entry<String, String>, String> colKey = new TableColumn<>("Property"); colKey.setCellValueFactory(cdf -> new ReadOnlyStringWrapper(cdf.getValue().getKey())); cols.add(colKey);/*w w w .j ava 2s. c om*/ TableColumn<Map.Entry<String, String>, String> colValue = new TableColumn<>("Value"); colValue.setCellValueFactory(cdf -> new ReadOnlyStringWrapper(cdf.getValue().getValue())); cols.add(colValue); TableColumn<Map.Entry<String, String>, String> colPercent = new TableColumn<>("Percentage"); colPercent.setCellValueFactory(cdf -> { String result = "NA"; if (cdf.getValue() != null && cdf.getValue().getValue() != null && !cdf.getValue().getValue().equals("null")) { long longVal = Long.parseLong(cdf.getValue().getValue()); result = (longVal == 0) ? "NA" : (((double) longVal / numChanges * 100) + "%"); } return new ReadOnlyStringWrapper(result); }); cols.add(colPercent); return new AdditionalData<String, Entry<String, String>>("Summary", Arrays.asList("Summary"), map, cols); }
From source file:com.ggvaidya.scinames.dataset.BinomialChangesSceneController.java
private AdditionalData<Name, Map.Entry<String, String>> createDataByNameAdditionalData() { // Which names area we interested in? List<PotentialChange> selectedChanges = changesTableView.getItems(); List<Name> names = selectedChanges.stream().flatMap(ch -> { Set<Name> allNames = ch.getAllNames(); List<Name> binomials = allNames.stream().flatMap(n -> n.asBinomial()).collect(Collectors.toList()); List<Name> genus = allNames.stream().flatMap(n -> n.asGenus()).collect(Collectors.toList()); allNames.addAll(binomials);/*w w w. j ava 2 s. co m*/ allNames.addAll(genus); return allNames.stream(); }).distinct().sorted().collect(Collectors.toList()); Project proj = binomialChangesView.getProjectView().getProject(); Map<Name, List<Map.Entry<String, String>>> map = new HashMap<>(); for (Name n : names) { Map<DatasetColumn, Set<String>> dataForName = proj.getDataForName(n); Map<String, String> mapForName = dataForName.entrySet().stream() .collect(Collectors.toMap( (Map.Entry<DatasetColumn, Set<String>> entry) -> entry.getKey().toString(), (Map.Entry<DatasetColumn, Set<String>> entry) -> entry.getValue().toString())); map.put(n, new ArrayList<>(mapForName.entrySet())); } List<TableColumn<Map.Entry<String, String>, String>> cols = new ArrayList<>(); TableColumn<Map.Entry<String, String>, String> colKey = new TableColumn<>("Key"); colKey.setCellValueFactory(cdf -> new ReadOnlyStringWrapper(cdf.getValue().getKey())); cols.add(colKey); TableColumn<Map.Entry<String, String>, String> colValue = new TableColumn<>("Value"); colValue.setCellValueFactory(cdf -> new ReadOnlyStringWrapper(cdf.getValue().getValue())); cols.add(colValue); return new AdditionalData<Name, Map.Entry<String, String>>("Data by name", names, map, cols, changes -> changes.stream().flatMap(ch -> ch.getAllNames().stream()).collect(Collectors.toList())); }
From source file:com.ggvaidya.scinames.dataset.BinomialChangesSceneController.java
private TableColumn<Change, String> getChangeTableColumn(String colName, Function<Change, String> func) { TableColumn<Change, String> col = new TableColumn<>(colName); col.setCellValueFactory(cdf -> new ReadOnlyStringWrapper(func.apply(cdf.getValue()))); return col;//from w w w .ja va 2s. c o m }