vipCol.setEditable(true);
vipCol.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Person, Boolean>, ObservableValue<Boolean>>() {
@Override public ObservableValue<Boolean> call(
javafx.scene.control.TableColumn.CellDataFeatures<Person, Boolean> param) {
return new ReadOnlyBooleanWrapper(param.getValue().getVip());
}
});
vipCol.setCellFactory(CheckBoxTableCell.forTableColumn(vipCol));
vipCol.setOnEditCommit(new EventHandler<CellEditEvent<Person, Boolean>>() {
@Override public void handle(CellEditEvent<Person, Boolean> t) {
((Person) t.getTableView().getItems().get(t.getTablePosition().getRow())).setVip(t.getNewValue());
}
});
table.getColumns().addAll(firstNameCol, lastNameCol, firstEmailCol, secondEmailCol, vipCol);
table.setItems(data);
table.setTableMenuButtonVisible(true);
tableContainer.getChildren().add(table);
tabTableBox.setContent(tableContainer);
tabPane.getTabs().add(tabTableBox);
Tab tabTreeBox = new Tab();
tabTreeBox.setText("Tree");
HBox treeContainer = new HBox();
treeContainer.setPadding(new Insets(10));
TreeItem<String> rootItem = new TreeItem<String>("People");
rootItem.setExpanded(true);
for (Person person : data) {
TreeItem<String> personLeaf = new TreeItem<String>(person.getFirstName());
boolean found = false;
for (TreeItem<String> statusNode : rootItem.getChildren()) {
if (statusNode.getValue().equals((!person.getVip() ? "no " : "") + "VIP")) {
statusNode.getChildren().add(personLeaf);
found = true;
break;
}
}
if (!found) {
TreeItem<String> statusNode = new TreeItem<String>((!person.getVip() ? "no " : "") + "VIP");
rootItem.getChildren().add(statusNode);
statusNode.getChildren().add(personLeaf);
}
}
TreeView<String> tree = new TreeView<String>(rootItem);
tree.setPrefHeight(250);
tree.setPrefWidth(400);
treeContainer.getChildren().add(tree);
tabTreeBox.setContent(treeContainer);
tabPane.getTabs().add(tabTreeBox);
Tab tabTreeTableBox = new Tab();
tabTreeTableBox.setText("TreeTable");
HBox treeTableContainer = new HBox();
treeTableContainer.setPadding(new Insets(10));
TreeItem<Person> rootTreeTableItem = new TreeItem<Person>(new Person("Chef", "Chef", "chef@business.de", "chef@business.de", true));
rootTreeTableItem.setExpanded(true);
for (Person person : data) {
TreeItem<Person> personLeaf = new TreeItem<Person>(person);
boolean found = false;
for (TreeItem<Person> statusNode : rootTreeTableItem.getChildren()) {
if (statusNode.getValue().getVip() == person.getVip()) {
statusNode.getChildren().add(personLeaf);
found = true;
break;
}
}
if (!found) {
TreeItem<Person> statusNode = new TreeItem<Person>(person);
rootTreeTableItem.getChildren().add(statusNode);
statusNode.getChildren().add(personLeaf);
}
}
TreeTableView<Person> treeTable = new TreeTableView<Person>(rootTreeTableItem);
TreeTableColumn<Person, String> firstNameTreeCol = new TreeTableColumn<Person, String>("First Name");
firstNameTreeCol.setPrefWidth(100);
firstNameTreeCol.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<Person, String>, ObservableValue<String>>() {
@Override public ObservableValue<String> call(CellDataFeatures<Person, String> param) {
return new ReadOnlyStringWrapper(param.getValue().getValue().getFirstName());
}
});
TreeTableColumn<Person, String> lastNameTreeCol = new TreeTableColumn<Person, String>("Last Name");
lastNameTreeCol.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<Person, String>, ObservableValue<String>>() {
@Override public ObservableValue<String> call(CellDataFeatures<Person, String> param) {
return new ReadOnlyStringWrapper(param.getValue().getValue().getLastName());
}
});
TreeTableColumn<Person, String> primaryMailCol = new TreeTableColumn<Person, String>("primary Mail");
primaryMailCol.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<Person, String>, ObservableValue<String>>() {
@Override public ObservableValue<String> call(CellDataFeatures<Person, String> param) {
return new ReadOnlyStringWrapper(param.getValue().getValue().getPrimaryEmail());
}
});
TreeTableColumn<Person, Boolean> vipTreeTableCol = new TreeTableColumn<Person, Boolean>("VIP");
vipTreeTableCol.setCellFactory(CheckBoxTreeTableCell.forTreeTableColumn(vipTreeTableCol));
vipTreeTableCol.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<Person, Boolean>, ObservableValue<Boolean>>() {
@Override public ObservableValue<Boolean> call(CellDataFeatures<Person, Boolean> param) {
return new ReadOnlyBooleanWrapper(param.getValue().getValue().getVip());
}
});
treeTable.getColumns().setAll(firstNameTreeCol, lastNameTreeCol, primaryMailCol, vipTreeTableCol);
treeTable.setPrefHeight(250);
treeTable.setPrefWidth(600);