use of javafx.scene.control.TreeTableColumn in project JFoenix by jfoenixadmin.
the class GenericEditableTreeTableCell method createEditorNode.
private void createEditorNode() {
EventHandler<KeyEvent> keyEventsHandler = new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent t) {
if (t.getCode() == KeyCode.ENTER) {
commitHelper(false);
} else if (t.getCode() == KeyCode.ESCAPE) {
cancelEdit();
} else if (t.getCode() == KeyCode.TAB) {
commitHelper(false);
TreeTableColumn nextColumn = getNextColumn(!t.isShiftDown());
if (nextColumn != null) {
getTreeTableView().edit(getIndex(), nextColumn);
}
}
}
};
ChangeListener<Boolean> focusChangeListener = new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
//of stopping the double commit.
if (!newValue && editorNode != null) {
commitHelper(true);
}
}
};
DoubleBinding minWidthBinding = Bindings.createDoubleBinding(() -> {
return this.getWidth() - this.getGraphicTextGap() * 2 - this.getBaselineOffset();
}, this.widthProperty(), this.graphicTextGapProperty());
editorNode = builder.createNode(getValue(), minWidthBinding, keyEventsHandler, focusChangeListener);
}
use of javafx.scene.control.TreeTableColumn in project jgnash by ccavanaugh.
the class BudgetTableController method buildAccountTreeTable.
/**
* Constructs the tree table.
*
* @see Stage#showAndWait() for need to push {@code handleEditAccountGoals(account)} to the platform thread
*/
private void buildAccountTreeTable() {
// empty column header is needed to match other table columns
final TreeTableColumn<Account, String> headerColumn = new TreeTableColumn<>("");
final TreeTableColumn<Account, Account> nameColumn = new TreeTableColumn<>(resources.getString("Column.Account"));
nameColumn.setCellFactory(param -> new AccountTreeTableCell());
nameColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getValue()));
nameColumn.setOnEditStart(event -> {
final Account account = event.getRowValue().getValue();
if (account != null && !account.isPlaceHolder()) {
if (Platform.isFxApplicationThread()) {
handleEditAccountGoals(account);
} else {
Platform.runLater(() -> handleEditAccountGoals(account));
}
}
});
nameColumn.setEditable(true);
headerColumn.getColumns().add(nameColumn);
accountTreeView.getColumns().add(headerColumn);
headerColumn.minWidthProperty().bind(accountTreeView.widthProperty());
headerColumn.maxWidthProperty().bind(accountTreeView.widthProperty());
}
use of javafx.scene.control.TreeTableColumn in project jgnash by ccavanaugh.
the class AccountsViewController method initializeTreeTableView.
@SuppressWarnings("unchecked")
private void initializeTreeTableView() {
// don't show the root
treeTableView.setShowRoot(false);
// required for editable columns
treeTableView.setEditable(true);
treeTableView.setTableMenuButtonVisible(true);
treeTableView.setRowFactory(ttv -> getTreeTableRow());
// force resize policy for better default appearance
treeTableView.setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY);
// hide the horizontal scrollbar and prevent ghosting
treeTableView.getStylesheets().addAll(StyleClass.HIDE_HORIZONTAL_CSS);
final TreeTableColumn<Account, String> nameColumn = new TreeTableColumn<>(resources.getString("Column.Account"));
nameColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getValue().getName()));
final TreeTableColumn<Account, Integer> entriesColumn = new TreeTableColumn<>(resources.getString("Column.Entries"));
entriesColumn.setCellValueFactory(param -> new SimpleIntegerProperty(param.getValue().getValue().getTransactionCount()).asObject());
final TreeTableColumn<Account, BigDecimal> balanceColumn = new TreeTableColumn<>(resources.getString("Column.Balance"));
balanceColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(AccountBalanceDisplayManager.convertToSelectedBalanceMode(param.getValue().getValue().getAccountType(), param.getValue().getValue().getTreeBalance())));
balanceColumn.setCellFactory(cell -> new AccountCommodityFormatTreeTableCell());
final TreeTableColumn<Account, BigDecimal> reconciledBalanceColumn = new TreeTableColumn<>(resources.getString("Column.ReconciledBalance"));
reconciledBalanceColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(AccountBalanceDisplayManager.convertToSelectedBalanceMode(param.getValue().getValue().getAccountType(), param.getValue().getValue().getReconciledTreeBalance())));
reconciledBalanceColumn.setCellFactory(cell -> new AccountCommodityFormatTreeTableCell());
final TreeTableColumn<Account, String> currencyColumn = new TreeTableColumn<>(resources.getString("Column.Currency"));
currencyColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getValue().getCurrencyNode().getSymbol()));
final TreeTableColumn<Account, String> typeColumn = new TreeTableColumn<>(resources.getString("Column.Type"));
typeColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getValue().getAccountType().toString()));
final TreeTableColumn<Account, Integer> codeColumn = new TreeTableColumn<>(resources.getString("Column.Code"));
codeColumn.setEditable(true);
codeColumn.setCellValueFactory(param -> new SimpleIntegerProperty(param.getValue().getValue().getAccountCode()).asObject());
codeColumn.setCellFactory(param -> new IntegerTreeTableCell<>());
codeColumn.setOnEditCommit(event -> updateAccountCode(event.getRowValue().getValue(), event.getNewValue()));
treeTableView.getColumns().addAll(nameColumn, codeColumn, entriesColumn, balanceColumn, reconciledBalanceColumn, currencyColumn, typeColumn);
restoreColumnVisibility();
installListeners();
}
use of javafx.scene.control.TreeTableColumn in project JFoenix by jfoenixadmin.
the class JFXTreeTableColumn method init.
private void init() {
this.setCellFactory(new Callback<TreeTableColumn<S, T>, TreeTableCell<S, T>>() {
@Override
public TreeTableCell<S, T> call(TreeTableColumn<S, T> param) {
return new JFXTreeTableCell<S, T>() {
@Override
protected void updateItem(T item, boolean empty) {
if (item == getItem())
return;
super.updateItem(item, empty);
if (item == null) {
super.setText(null);
super.setGraphic(null);
} else if (item instanceof Node) {
super.setText(null);
super.setGraphic((Node) item);
} else {
super.setText(item.toString());
super.setGraphic(null);
}
}
};
}
});
Platform.runLater(() -> {
final ContextMenu contextMenu = new ContextMenu();
// contextMenu.setOnShowing((showing)->{
// System.out.println("showing");
// });
// contextMenu.setOnShown((shown)->{
// System.out.println("shown");
// });
MenuItem item1 = new MenuItem("Group");
item1.setOnAction((action) -> {
((JFXTreeTableView) getTreeTableView()).group(this);
});
MenuItem item2 = new MenuItem("UnGroup");
item2.setOnAction((action) -> {
((JFXTreeTableView) getTreeTableView()).unGroup(this);
});
contextMenu.getItems().addAll(item1, item2);
setContextMenu(contextMenu);
});
}
use of javafx.scene.control.TreeTableColumn in project JFoenix by jfoenixadmin.
the class TreeTableDemo method start.
@Override
public void start(Stage primaryStage) throws Exception {
try {
JFXTreeTableColumn<User, String> deptColumn = new JFXTreeTableColumn<>("Department");
deptColumn.setPrefWidth(150);
deptColumn.setCellValueFactory((TreeTableColumn.CellDataFeatures<User, String> param) -> {
if (deptColumn.validateValue(param))
return param.getValue().getValue().department;
else
return deptColumn.getComputedValue(param);
});
JFXTreeTableColumn<User, String> empColumn = new JFXTreeTableColumn<>("Employee");
empColumn.setPrefWidth(150);
empColumn.setCellValueFactory((TreeTableColumn.CellDataFeatures<User, String> param) -> {
if (empColumn.validateValue(param))
return param.getValue().getValue().userName;
else
return empColumn.getComputedValue(param);
});
JFXTreeTableColumn<User, String> ageColumn = new JFXTreeTableColumn<>("Age");
ageColumn.setPrefWidth(150);
ageColumn.setCellValueFactory((TreeTableColumn.CellDataFeatures<User, String> param) -> {
if (ageColumn.validateValue(param))
return param.getValue().getValue().age;
else
return ageColumn.getComputedValue(param);
});
ageColumn.setCellFactory((TreeTableColumn<User, String> param) -> new GenericEditableTreeTableCell<User, String>(new TextFieldEditorBuilder()));
ageColumn.setOnEditCommit((CellEditEvent<User, String> t) -> {
((User) t.getTreeTableView().getTreeItem(t.getTreeTablePosition().getRow()).getValue()).age.set(t.getNewValue());
});
empColumn.setCellFactory((TreeTableColumn<User, String> param) -> new GenericEditableTreeTableCell<User, String>(new TextFieldEditorBuilder()));
empColumn.setOnEditCommit((CellEditEvent<User, String> t) -> {
((User) t.getTreeTableView().getTreeItem(t.getTreeTablePosition().getRow()).getValue()).userName.set(t.getNewValue());
});
deptColumn.setCellFactory((TreeTableColumn<User, String> param) -> new GenericEditableTreeTableCell<User, String>(new TextFieldEditorBuilder()));
deptColumn.setOnEditCommit((CellEditEvent<User, String> t) -> {
((User) t.getTreeTableView().getTreeItem(t.getTreeTablePosition().getRow()).getValue()).department.set(t.getNewValue());
});
// data
ObservableList<User> users = FXCollections.observableArrayList();
users.add(new User("Computer Department", "23", "CD 1"));
users.add(new User("Sales Department", "22", "Employee 1"));
users.add(new User("Sales Department", "22", "Employee 2"));
users.add(new User("Sales Department", "25", "Employee 4"));
users.add(new User("Sales Department", "25", "Employee 5"));
users.add(new User("IT Department", "42", "ID 2"));
users.add(new User("HR Department", "22", "HR 1"));
users.add(new User("HR Department", "22", "HR 2"));
for (int i = 0; i < 40000; i++) {
users.add(new User("HR Department", i % 10 + "", "HR 2" + i));
}
for (int i = 0; i < 40000; i++) {
users.add(new User("Computer Department", i % 20 + "", "CD 2" + i));
}
for (int i = 0; i < 40000; i++) {
users.add(new User("IT Department", i % 5 + "", "HR 2" + i));
}
// build tree
final TreeItem<User> root = new RecursiveTreeItem<User>(users, RecursiveTreeObject::getChildren);
JFXTreeTableView<User> treeView = new JFXTreeTableView<User>(root);
treeView.setShowRoot(false);
treeView.setEditable(true);
treeView.getColumns().setAll(deptColumn, ageColumn, empColumn);
FlowPane main = new FlowPane();
main.setPadding(new Insets(10));
main.getChildren().add(treeView);
JFXButton groupButton = new JFXButton("Group");
groupButton.setOnAction((action) -> {
new Thread(() -> treeView.group(empColumn)).start();
});
main.getChildren().add(groupButton);
JFXButton unGroupButton = new JFXButton("unGroup");
unGroupButton.setOnAction((action) -> treeView.unGroup(empColumn));
main.getChildren().add(unGroupButton);
JFXTextField filterField = new JFXTextField();
main.getChildren().add(filterField);
Label size = new Label();
filterField.textProperty().addListener((o, oldVal, newVal) -> {
treeView.setPredicate(user -> user.getValue().age.get().contains(newVal) || user.getValue().department.get().contains(newVal) || user.getValue().userName.get().contains(newVal));
});
size.textProperty().bind(Bindings.createStringBinding(() -> treeView.getCurrentItemsCount() + "", treeView.currentItemsCountProperty()));
main.getChildren().add(size);
Scene scene = new Scene(main, 475, 500);
scene.getStylesheets().add(TreeTableDemo.class.getResource("/resources/css/jfoenix-components.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
// ScenicView.show(scene);
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations