List of usage examples for javafx.scene.control TableColumn setCellValueFactory
public final void setCellValueFactory(Callback<CellDataFeatures<S, T>, ObservableValue<T>> value)
From source file:com.github.drbookings.ui.controller.MainController.java
private void addDateColumn() { final TableColumn<DateBean, LocalDate> col = new TableColumn<>("Date"); col.setCellValueFactory(new PropertyValueFactory<>("date")); col.setCellFactory(column -> {//from w ww . j a v a 2 s.c om return new TableCell<DateBean, LocalDate>() { @Override protected void updateItem(final LocalDate item, final boolean empty) { super.updateItem(item, empty); if (item == null || empty) { setText(null); setStyle(""); } else { setText(DrBookingsApplication.DATE_FORMATTER.format(item)); } } }; }); col.getStyleClass().addAll("center-left"); tableView.getColumns().add(col); }
From source file:com.github.drbookings.ui.controller.MainController.java
private void setTableColumns() { addDateColumn();/*from w ww . j av a 2 s. c o m*/ final int numberRooms = SettingsManager.getInstance().getNumberOfRooms(); final String prefix = SettingsManager.getInstance().getRoomNamePrefix(); for (int i = 1; i <= numberRooms; i++) { final TableColumn<DateBean, DateBean> col1 = new TableColumn<>(prefix + i); col1.setCellValueFactory(new PropertyValueFactory<>("self")); col1.setCellFactory(new StudioCellFactory("" + i)); tableView.getColumns().add(col1); } addOccupancyRateColumn(); addEarningsColumn(); }
From source file:com.github.drbookings.ui.controller.MainController.java
private void addEarningsColumn() { final TableColumn<DateBean, Number> col = new TableColumn<>("TotalEarnings"); col.setCellValueFactory(new PropertyValueFactory<>("totalEarnings")); col.setCellFactory(column -> {//w ww. j a va2 s.c o m return new TableCell<DateBean, Number>() { @Override protected void updateItem(final Number item, final boolean empty) { super.updateItem(item, empty); if (item == null || empty) { setText(null); } else { setText(decimalFormat.format(item)); } } }; }); col.getStyleClass().add("opace"); tableView.getColumns().add(col); }
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 ww . ja va 2 s. co m }
From source file:com.github.drbookings.ui.controller.MainController.java
private void addOccupancyRateColumn() { final TableColumn<DateBean, Number> col = new TableColumn<>("OccupancyRate"); col.setCellFactory(new OccupancyCellFactory()); col.setCellValueFactory(new OccupancyCellValueFactory()); tableView.getColumns().add(col);//from ww w . j ava2 s . c o m }
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. jav a2 s . c om 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 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);/*from w w 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); 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.DatasetSceneController.java
private void setupTableWithChanges(TableView<Change> tv, Dataset tp) { tv.setEditable(true);/*ww w.j av a 2 s.co m*/ tv.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); tv.getColumns().clear(); TableColumn<Change, ChangeType> colChangeType = new TableColumn<>("Type"); colChangeType.setCellFactory(ComboBoxTableCell.forTableColumn(new ChangeTypeStringConverter(), ChangeType.ADDITION, ChangeType.DELETION, ChangeType.RENAME, ChangeType.LUMP, ChangeType.SPLIT, ChangeType.COMPLEX, ChangeType.ERROR)); colChangeType.setCellValueFactory(new PropertyValueFactory<>("type")); colChangeType.setPrefWidth(100.0); colChangeType.setEditable(true); tv.getColumns().add(colChangeType); TableColumn<Change, ObservableSet<Name>> colChangeFrom = new TableColumn<>("From"); colChangeFrom.setCellFactory(TextFieldTableCell.forTableColumn(new NameSetStringConverter())); colChangeFrom.setCellValueFactory(new PropertyValueFactory<>("from")); colChangeFrom.setPrefWidth(200.0); colChangeFrom.setEditable(true); tv.getColumns().add(colChangeFrom); TableColumn<Change, ObservableSet<Name>> colChangeTo = new TableColumn<>("To"); colChangeTo.setCellFactory(TextFieldTableCell.forTableColumn(new NameSetStringConverter())); colChangeTo.setCellValueFactory(new PropertyValueFactory<>("to")); colChangeTo.setPrefWidth(200.0); colChangeTo.setEditable(true); tv.getColumns().add(colChangeTo); TableColumn<Change, String> colExplicit = new TableColumn<>("Explicit or implicit?"); colExplicit.setCellValueFactory( (TableColumn.CellDataFeatures<Change, String> features) -> new ReadOnlyStringWrapper( features.getValue().getDataset().isChangeImplicit(features.getValue()) ? "Implicit" : "Explicit")); tv.getColumns().add(colExplicit); ChangeFilter cf = datasetView.getProjectView().getProject().getChangeFilter(); TableColumn<Change, String> colFiltered = new TableColumn<>("Eliminated by filter?"); colFiltered.setCellValueFactory( (TableColumn.CellDataFeatures<Change, String> features) -> new ReadOnlyStringWrapper( cf.test(features.getValue()) ? "Allowed" : "Eliminated")); tv.getColumns().add(colFiltered); TableColumn<Change, String> colNote = new TableColumn<>("Note"); colNote.setCellFactory(TextFieldTableCell.forTableColumn()); colNote.setCellValueFactory(new PropertyValueFactory<>("note")); colNote.setPrefWidth(100.0); colNote.setEditable(true); tv.getColumns().add(colNote); TableColumn<Change, String> colCitations = new TableColumn<>("Citations"); colCitations.setCellValueFactory( (TableColumn.CellDataFeatures<Change, String> features) -> new ReadOnlyStringWrapper( features.getValue().getCitationStream().map(citation -> citation.getCitation()).sorted() .collect(Collectors.joining("; ")))); tv.getColumns().add(colCitations); TableColumn<Change, String> colGenera = new TableColumn<>("Genera"); colGenera.setCellValueFactory( (TableColumn.CellDataFeatures<Change, String> features) -> new ReadOnlyStringWrapper( String.join(", ", features.getValue().getAllNames().stream().map(n -> n.getGenus()) .distinct().sorted().collect(Collectors.toList())))); tv.getColumns().add(colGenera); TableColumn<Change, String> colSpecificEpithet = new TableColumn<>("Specific epithets"); colSpecificEpithet.setCellValueFactory( (TableColumn.CellDataFeatures<Change, String> features) -> new ReadOnlyStringWrapper(String .join(", ", features.getValue().getAllNames().stream().map(n -> n.getSpecificEpithet()) .filter(s -> s != null).distinct().sorted().collect(Collectors.toList())))); tv.getColumns().add(colSpecificEpithet); // The infraspecific string. TableColumn<Change, String> colInfraspecificEpithet = new TableColumn<>("Infraspecific epithets"); colInfraspecificEpithet.setCellValueFactory( (TableColumn.CellDataFeatures<Change, String> features) -> new ReadOnlyStringWrapper( String.join(", ", features.getValue().getAllNames().stream() .map(n -> n.getInfraspecificEpithetsAsString()).filter(s -> s != null) .distinct().sorted().collect(Collectors.toList())))); tv.getColumns().add(colInfraspecificEpithet); // The very last epithet of all TableColumn<Change, String> colTerminalEpithet = new TableColumn<>("Terminal epithet"); colTerminalEpithet.setCellValueFactory( (TableColumn.CellDataFeatures<Change, String> features) -> new ReadOnlyStringWrapper( String.join(", ", features.getValue().getAllNames().stream().map(n -> { List<Name.InfraspecificEpithet> infraspecificEpithets = n.getInfraspecificEpithets(); if (!infraspecificEpithets.isEmpty()) { return infraspecificEpithets.get(infraspecificEpithets.size() - 1).getValue(); } else { return n.getSpecificEpithet(); } }).filter(s -> s != null).distinct().sorted().collect(Collectors.toList())))); tv.getColumns().add(colTerminalEpithet); // Properties TableColumn<Change, String> colProperties = new TableColumn<>("Properties"); colProperties.setCellValueFactory( (TableColumn.CellDataFeatures<Change, String> features) -> new ReadOnlyStringWrapper( features.getValue().getProperties().entrySet().stream() .map(entry -> entry.getKey() + ": " + entry.getValue()).sorted() .collect(Collectors.joining("; ")))); tv.getColumns().add(colProperties); fillTableWithChanges(tv, tp); // When someone selects a cell in the Table, try to select the appropriate data in the // additional data view. tv.getSelectionModel().getSelectedItems().addListener((ListChangeListener<Change>) lcl -> { AdditionalData aData = additionalDataCombobox.getSelectionModel().getSelectedItem(); if (aData != null) { aData.onSelectChange(tv.getSelectionModel().getSelectedItems()); } }); // Create a right-click menu for table rows. changesTableView.setRowFactory(table -> { TableRow<Change> row = new TableRow<>(); row.setOnContextMenuRequested(event -> { if (row.isEmpty()) return; // We don't currently use the clicked change, since currently all options // change *all* the selected changes, but this may change in the future. Change change = row.getItem(); ContextMenu changeMenu = new ContextMenu(); Menu searchForName = new Menu("Search for name"); searchForName.getItems().addAll( change.getAllNames().stream().sorted().map(n -> createMenuItem(n.getFullName(), action -> { datasetView.getProjectView().openDetailedView(n); })).collect(Collectors.toList())); changeMenu.getItems().add(searchForName); changeMenu.getItems().add(new SeparatorMenuItem()); changeMenu.getItems().add(createMenuItem("Edit note", action -> { List<Change> changes = new ArrayList<>(changesTableView.getSelectionModel().getSelectedItems()); String combinedNotes = changes.stream().map(ch -> ch.getNote().orElse("").trim()).distinct() .collect(Collectors.joining("\n")).trim(); Optional<String> result = askUserForTextArea( "Modify the note for these " + changes.size() + " changes:", combinedNotes); if (result.isPresent()) { String note = result.get().trim(); LOGGER.info("Using 'Edit note' to set note to '" + note + "' on changes " + changes); changes.forEach(ch -> ch.noteProperty().set(note)); } })); changeMenu.getItems().add(new SeparatorMenuItem()); // Create a submenu for tags and urls. String note = change.noteProperty().get(); Menu removeTags = new Menu("Tags"); removeTags.getItems().addAll(change.getTags().stream().sorted() .map(tag -> new MenuItem(tag.getName())).collect(Collectors.toList())); Menu lookupURLs = new Menu("Lookup URL"); change.getURIs().stream().sorted().map(uri -> { return createMenuItem(uri.toString(), evt -> { try { Desktop.getDesktop().browse(uri); } catch (IOException ex) { LOGGER.warning("Could not open URL '" + uri + "': " + ex); } }); }).forEach(mi -> lookupURLs.getItems().add(mi)); changeMenu.getItems().add(lookupURLs); changeMenu.getItems().add(new SeparatorMenuItem()); changeMenu.getItems().add(createMenuItem("Prepend text to all notes", action -> { List<Change> changes = new ArrayList<>(changesTableView.getSelectionModel().getSelectedItems()); Optional<String> result = askUserForTextField( "Enter tags to prepend to notes in " + changes.size() + " changes:"); if (result.isPresent()) { String tags = result.get().trim(); changes.forEach(ch -> { String prevValue = change.getNote().orElse("").trim(); LOGGER.info("Prepending tags '" + tags + "' to previous value '" + prevValue + "' for change " + ch); ch.noteProperty().set((tags + " " + prevValue).trim()); }); } })); changeMenu.getItems().add(createMenuItem("Append text to all notes", action -> { List<Change> changes = new ArrayList<>(changesTableView.getSelectionModel().getSelectedItems()); Optional<String> result = askUserForTextField( "Enter tags to append to notes in " + changes.size() + " changes:"); if (result.isPresent()) { String tags = result.get().trim(); changes.forEach(ch -> { String prevValue = ch.getNote().orElse("").trim(); LOGGER.info("Appending tags '" + tags + "' to previous value '" + prevValue + "' for change " + ch); ch.noteProperty().setValue((prevValue + " " + tags).trim()); }); } })); changeMenu.show(datasetView.getScene().getWindow(), event.getScreenX(), event.getScreenY()); }); return row; }); LOGGER.info("setupTableWithChanges() completed"); }
From source file:com.ggvaidya.scinames.dataset.BinomialChangesSceneController.java
private void setupTableWithBinomialChanges() { changesTableView.setEditable(false); changesTableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); changesTableView.setItems(potentialChanges); changesTableView.getColumns().clear(); TableColumn<PotentialChange, ChangeType> colChangeType = new TableColumn<>("Type"); colChangeType.setCellFactory(ComboBoxTableCell.forTableColumn(new ChangeTypeStringConverter(), ChangeType.ADDITION, ChangeType.DELETION, ChangeType.RENAME, ChangeType.LUMP, ChangeType.SPLIT, ChangeType.COMPLEX, ChangeType.ERROR)); colChangeType.setCellValueFactory(new PropertyValueFactory<>("type")); colChangeType.setPrefWidth(100.0);//from w w w.j a va2 s . com colChangeType.setEditable(true); changesTableView.getColumns().add(colChangeType); TableColumn<PotentialChange, ObservableSet<Name>> colChangeFrom = new TableColumn<>("From"); colChangeFrom.setCellFactory(TextFieldTableCell.forTableColumn(new NameSetStringConverter())); colChangeFrom.setCellValueFactory(new PropertyValueFactory<>("from")); colChangeFrom.setPrefWidth(200.0); colChangeFrom.setEditable(true); changesTableView.getColumns().add(colChangeFrom); TableColumn<PotentialChange, ObservableSet<Name>> colChangeTo = new TableColumn<>("To"); colChangeTo.setCellFactory(TextFieldTableCell.forTableColumn(new NameSetStringConverter())); colChangeTo.setCellValueFactory(new PropertyValueFactory<>("to")); colChangeTo.setPrefWidth(200.0); colChangeTo.setEditable(true); changesTableView.getColumns().add(colChangeTo); TableColumn<PotentialChange, String> colDataset = new TableColumn<>("Dataset"); colDataset.setCellValueFactory(cvf -> { return new ReadOnlyStringWrapper(cvf.getValue().getDataset().toString()); }); colDataset.setPrefWidth(150.0); changesTableView.getColumns().add(colDataset); TableColumn<PotentialChange, SimplifiedDate> dateCol = new TableColumn<>("Date"); dateCol.setCellFactory( TextFieldTableCell.forTableColumn(new SimplifiedDate.SimplifiedDateStringConverter())); dateCol.setCellValueFactory(cvf -> new ReadOnlyObjectWrapper<>(cvf.getValue().getDataset().getDate())); dateCol.setPrefWidth(150); dateCol.setSortable(true); dateCol.setSortType(SortType.ASCENDING); changesTableView.getColumns().add(dateCol); changesTableView.getSortOrder().add(dateCol); TableColumn<PotentialChange, String> colChangeSummary = new TableColumn<>("Changes summary"); colChangeSummary.setCellValueFactory(cvf -> { Set<Change> changes = changesByPotentialChange.get(cvf.getValue()); return new ReadOnlyStringWrapper(changes.size() + ": " + changes.stream().map(ch -> ch.toString()).collect(Collectors.joining("; "))); }); colChangeSummary.setPrefWidth(200.0); changesTableView.getColumns().add(colChangeSummary); /* TableColumn<PotentialChange, String> colExplicit = new TableColumn<>("Explicit or implicit?"); colExplicit.setCellValueFactory( (TableColumn.CellDataFeatures<Change, String> features) -> new ReadOnlyStringWrapper( features.getValue().getDataset().isChangeImplicit(features.getValue()) ? "Implicit" : "Explicit" ) ); tv.getColumns().add(colExplicit); ChangeFilter cf = binomialChangesView.getProjectView().getProject().getChangeFilter(); TableColumn<Change, String> colFiltered = new TableColumn<>("Eliminated by filter?"); colFiltered.setCellValueFactory( (TableColumn.CellDataFeatures<Change, String> features) -> new ReadOnlyStringWrapper( cf.test(features.getValue()) ? "Allowed" : "Eliminated" ) ); tv.getColumns().add(colFiltered); */ TableColumn<PotentialChange, String> colNote = new TableColumn<>("Note"); colNote.setCellFactory(TextFieldTableCell.forTableColumn()); colNote.setCellValueFactory(new PropertyValueFactory<>("note")); colNote.setPrefWidth(100.0); changesTableView.getColumns().add(colNote); TableColumn<PotentialChange, String> colReason = new TableColumn<>("Reason"); colReason.setCellValueFactory(cvf -> new ReadOnlyStringWrapper(calculateReason(cvf.getValue()))); colReason.setPrefWidth(100.0); changesTableView.getColumns().add(colReason); TableColumn<PotentialChange, String> colReasonDate = new TableColumn<>("ReasonDate"); colReasonDate.setCellValueFactory(cvf -> { String result; Set<SimplifiedDate> dates = calculateReasonDate(cvf.getValue()); if (dates.size() > 1) { result = "(" + dates.size() + ") " + dates.stream().distinct().sorted() .map(sd -> sd.asYYYYmmDD("-")).collect(Collectors.joining("|")); } else if (dates.size() == 1) { result = dates.iterator().next().asYYYYmmDD("-"); } else { result = "NA"; } return new ReadOnlyStringWrapper(result); }); colReasonDate.setPrefWidth(100.0); changesTableView.getColumns().add(colReasonDate); TableColumn<PotentialChange, String> colCitations = new TableColumn<>("Citations"); colCitations.setCellValueFactory( (TableColumn.CellDataFeatures<PotentialChange, String> features) -> new ReadOnlyStringWrapper( features.getValue().getCitationStream().map(citation -> citation.getCitation()).sorted() .collect(Collectors.joining("; ")))); changesTableView.getColumns().add(colCitations); TableColumn<PotentialChange, String> colGenera = new TableColumn<>("Genera"); colGenera.setCellValueFactory( (TableColumn.CellDataFeatures<PotentialChange, String> features) -> new ReadOnlyStringWrapper( String.join(", ", features.getValue().getAllNames().stream().map(n -> n.getGenus()) .distinct().sorted().collect(Collectors.toList())))); changesTableView.getColumns().add(colGenera); TableColumn<PotentialChange, String> colSpecificEpithet = new TableColumn<>("Specific epithets"); colSpecificEpithet.setCellValueFactory( (TableColumn.CellDataFeatures<PotentialChange, String> features) -> new ReadOnlyStringWrapper(String .join(", ", features.getValue().getAllNames().stream().map(n -> n.getSpecificEpithet()) .filter(s -> s != null).distinct().sorted().collect(Collectors.toList())))); changesTableView.getColumns().add(colSpecificEpithet); // The infraspecific string. TableColumn<PotentialChange, String> colInfraspecificEpithet = new TableColumn<>("Infraspecific epithets"); colInfraspecificEpithet.setCellValueFactory( (TableColumn.CellDataFeatures<PotentialChange, String> features) -> new ReadOnlyStringWrapper( String.join(", ", features.getValue().getAllNames().stream() .map(n -> n.getInfraspecificEpithetsAsString()).filter(s -> s != null) .distinct().sorted().collect(Collectors.toList())))); changesTableView.getColumns().add(colInfraspecificEpithet); // The very last epithet of all TableColumn<PotentialChange, String> colTerminalEpithet = new TableColumn<>("Terminal epithet"); colTerminalEpithet.setCellValueFactory( (TableColumn.CellDataFeatures<PotentialChange, String> features) -> new ReadOnlyStringWrapper( String.join(", ", features.getValue().getAllNames().stream().map(n -> { List<Name.InfraspecificEpithet> infraspecificEpithets = n.getInfraspecificEpithets(); if (!infraspecificEpithets.isEmpty()) { return infraspecificEpithets.get(infraspecificEpithets.size() - 1).getValue(); } else { return n.getSpecificEpithet(); } }).filter(s -> s != null).distinct().sorted().collect(Collectors.toList())))); changesTableView.getColumns().add(colTerminalEpithet); TableColumn<PotentialChange, String> dateForRCol = new TableColumn<>("DateYMD"); dateForRCol.setCellValueFactory( cvf -> new ReadOnlyObjectWrapper<>(cvf.getValue().getDataset().getDate().asYYYYmmDD("-"))); changesTableView.getColumns().add(dateForRCol); // Properties TableColumn<PotentialChange, String> colProperties = new TableColumn<>("Properties"); colProperties.setCellValueFactory( (TableColumn.CellDataFeatures<PotentialChange, String> features) -> new ReadOnlyStringWrapper( features.getValue().getProperties().entrySet().stream() .map(entry -> entry.getKey() + ": " + entry.getValue()).sorted() .collect(Collectors.joining("; ")))); changesTableView.getColumns().add(colProperties); fillTableWithBinomialChanges(); // When someone selects a cell in the Table, try to select the appropriate data in the // additional data view. changesTableView.getSelectionModel().getSelectedItems() .addListener((ListChangeListener<PotentialChange>) lcl -> { AdditionalData aData = additionalDataCombobox.getSelectionModel().getSelectedItem(); if (aData != null) { aData.onSelectChange(changesTableView.getSelectionModel().getSelectedItems()); } }); // Create a right-click menu for table rows. changesTableView.setRowFactory(table -> { TableRow<PotentialChange> row = new TableRow<>(); row.setOnContextMenuRequested(event -> { if (row.isEmpty()) return; // We don't currently use the clicked change, since currently all options // change *all* the selected changes, but this may change in the future. PotentialChange change = row.getItem(); ContextMenu changeMenu = new ContextMenu(); Menu lookupChange = new Menu("Look up change"); lookupChange.getItems().addAll(changesByPotentialChange.getOrDefault(change, new HashSet<>()) .stream() .map(ch -> createMenuItem(ch.toString() + " in " + ch.getDataset().toString(), action -> { binomialChangesView.getProjectView().openDetailedView(ch); })).collect(Collectors.toList())); changeMenu.getItems().add(lookupChange); changeMenu.getItems().add(new SeparatorMenuItem()); Menu searchForName = new Menu("Search for name"); searchForName.getItems().addAll( change.getAllNames().stream().sorted().map(n -> createMenuItem(n.getFullName(), action -> { binomialChangesView.getProjectView().openDetailedView(n); })).collect(Collectors.toList())); changeMenu.getItems().add(searchForName); changeMenu.getItems().add(new SeparatorMenuItem()); // Create a submenu for tags and urls. String note = change.noteProperty().get(); Menu removeTags = new Menu("Tags"); removeTags.getItems().addAll(change.getTags().stream().sorted() .map(tag -> new MenuItem(tag.getName())).collect(Collectors.toList())); Menu lookupURLs = new Menu("Lookup URL"); change.getURIs().stream().sorted().map(uri -> { return createMenuItem(uri.toString(), evt -> { try { Desktop.getDesktop().browse(uri); } catch (IOException ex) { LOGGER.warning("Could not open URL '" + uri + "': " + ex); } }); }).forEach(mi -> lookupURLs.getItems().add(mi)); changeMenu.getItems().add(lookupURLs); changeMenu.show(binomialChangesView.getScene().getWindow(), event.getScreenX(), event.getScreenY()); }); return row; }); LOGGER.info("setupTableWithChanges() completed"); }
From source file:UI.MainStageController.java
/** * shows the correlation table in the analysis view *///w w w. j a v a 2s . c o m @FXML private void displayCorrelationTable() { //Delete whatever's been in the table before TableView<String[]> analysisTable = new TableView<>(); //We want to display correlations and p-Values of every node combination double[][] correlationMatrix = AnalysisData.getCorrelationMatrix().getData(); double[][] pValueMatrix = AnalysisData.getPValueMatrix().getData(); LinkedList<TaxonNode> taxonList = SampleComparison.getUnifiedTaxonList(LoadedData.getSamplesToAnalyze(), AnalysisData.getLevelOfAnalysis()); //Table will consist of strings String[][] tableValues = new String[correlationMatrix.length][correlationMatrix[0].length + 1]; //Add the values as formatted strings for (int i = 0; i < tableValues.length; i++) { tableValues[i][0] = taxonList.get(i).getName(); for (int j = 1; j < tableValues[0].length; j++) { tableValues[i][j] = String.format("%.3f", correlationMatrix[i][j - 1]).replace(",", ".") + "\n(" + String.format("%.2f", pValueMatrix[i][j - 1]).replace(",", ".") + ")"; } } for (int i = 0; i < tableValues[0].length; i++) { String columnTitle; if (i > 0) { columnTitle = taxonList.get(i - 1).getName(); } else { columnTitle = ""; } TableColumn<String[], String> column = new TableColumn<>(columnTitle); final int columnIndex = i; column.setCellValueFactory(cellData -> { String[] row = cellData.getValue(); return new SimpleStringProperty(row[columnIndex]); }); analysisTable.getColumns().add(column); //First column contains taxon names and should be italic if (i == 0) column.setStyle("-fx-font-style:italic;"); } for (int i = 0; i < tableValues.length; i++) { analysisTable.getItems().add(tableValues[i]); } //Display table on a new stage Stage tableStage = new Stage(); tableStage.setTitle("Correlation Table"); BorderPane tablePane = new BorderPane(); Button exportCorrelationsButton = new Button("Save correlation table to CSV"); Button exportPValuesButton = new Button("Save p-value table to CSV"); exportCorrelationsButton.setOnAction(e -> exportTableToCSV(tableValues, false)); exportPValuesButton.setOnAction(e -> exportTableToCSV(tableValues, true)); HBox exportBox = new HBox(exportCorrelationsButton, exportPValuesButton); exportBox.setPadding(new Insets(10)); exportBox.setSpacing(10); tablePane.setTop(exportBox); tablePane.setCenter(analysisTable); Scene tableScene = new Scene(tablePane); tableStage.setScene(tableScene); tableStage.show(); }