public static <T> void setupEditableBooleanColumn(TableColumn<T, Boolean> column, final ColumnBooleanAccessor<T> propertyAccessor) { column.getTableView().setEditable(true); column.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<T, Boolean>, ObservableValue<Boolean>>() { @Override public ObservableValue<Boolean> call(CellDataFeatures<T, Boolean> param) { return propertyAccessor.getProperty(param.getValue()); } }); column.setOnEditCommit(new EventHandler<CellEditEvent<T, Boolean>>() { @Override public void handle(CellEditEvent<T, Boolean> t) { propertyAccessor.getProperty(t.getRowValue()).setValue(t.getNewValue()); } }); column.setCellFactory(CheckBoxTableCell.forTableColumn(column)); column.setEditable(true); }
/** * T Tableobject * Column Display Type */ public static <T> void setupEditableStringColumn(TableColumn<T, String> column, final ColumnStringAccessor<T> propertyAccessor) { column.getTableView().setEditable(true); column.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<T, String>, ObservableValue<String>>() { @Override public ObservableValue<String> call(CellDataFeatures<T, String> param) { return propertyAccessor.getProperty(param.getValue()); } }); column.setEditable(true); column.setOnEditCommit(new EventHandler<CellEditEvent<T, String>>() { @Override public void handle(CellEditEvent<T, String> t) { propertyAccessor.getProperty(t.getRowValue()).setValue(t.getNewValue()); } }); column.setCellFactory(new Callback<TableColumn<T, String>, TableCell<T, String>>() { @Override public TableCell<T, String> call(TableColumn<T, String> param) { return new EditingCell<T>(); } }); }
@Override public void updateItem(final String item, final boolean empty) { super.updateItem(item, empty); if (item == null || empty) { setText(null); setStyle(""); setBackground(null); } else { setText(item); final Todo t = column.getTableView().getItems().get(getTableRow().getIndex()); getStyleClass().add("todoCell"); if (t.done()) { getStyleClass().removeAll("undone"); getStyleClass().add("done"); } else { getStyleClass().removeAll("done"); getStyleClass().add("undone"); } } } };
@Override public void updateItem(final String item, final boolean empty) { super.updateItem(item, empty); if (item == null || empty) { setText(null); setStyle(""); setBackground(null); } else { setText(item); final Todo t = column.getTableView().getItems().get(getTableRow().getIndex()); getStyleClass().add("todoCell"); if (t.done()) { getStyleClass().removeAll("undone"); getStyleClass().add("done"); } else { getStyleClass().removeAll("done"); getStyleClass().add("undone"); } } } };