@Override public void init() { // allow multiple rows selection tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); // listener for items selection change tableView .getSelectionModel() .getSelectedIndices() .addListener( (ListChangeListener<Integer>) change -> { if (change.getList().size() > 0) { setContextMenuState(true, true, true, true); } else { setContextMenuState(false, false, false, false); } }); // prevent table columns reordering tableView .getColumns() .addListener( (ListChangeListener<TableColumn<FileItem, ?>>) change -> { change.next(); if (change.wasReplaced()) { tableView.getColumns().clear(); tableView.getColumns().addAll(selectColumn, filenameColumn, filepathColumn); } }); // set column as a CheckBox column selectColumn.setCellFactory( cellData -> { CheckBoxTableCell<FileItem, Boolean> checkBoxTableCell = new CheckBoxTableCell<>(); // set value changed listener checkBoxTableCell.setSelectedStateCallback( index -> tableView.getItems().get(index).selectedProperty()); return checkBoxTableCell; }); // add checkbox to column heading selectFilesCheckBox = new CheckBox(); selectFilesCheckBox.setDisable(true); selectColumn.setGraphic(selectFilesCheckBox); selectFilesCheckBox .selectedProperty() .addListener( (observable, oldValue, newValue) -> { synchronized (LOCK) { tableView.getItems().forEach(fileItem -> fileItem.setSelected(newValue)); } }); // set value of cells in column selectColumn.setCellValueFactory(cellData -> cellData.getValue().selectedProperty()); filenameColumn.setCellValueFactory(cellData -> cellData.getValue().filenameProperty()); filepathColumn.setCellValueFactory(cellData -> cellData.getValue().filepathProperty()); }
public void setFddObjectModel(FddObjectModel fddObjectModel) { logger.entry(); if (fddObjectModel != null) { fddObjectModel .getInteractionClasses() .values() .stream() .forEach( (value) -> { interactions.add(new InteractionState(value)); }); InteractionTableView.setItems(interactions); interactions.forEach( (interaction) -> { interaction .onProperty() .addListener( (observable, oldValue, newValue) -> { if (!newValue) { cb.setSelected(false); } else if (interactions.stream().allMatch(a -> a.isOn())) { cb.setSelected(true); } }); }); InteractionTableColumn.setCellValueFactory(new PropertyValueFactory<>("interactionName")); CheckTableColumn.setCellValueFactory( new Callback< TableColumn.CellDataFeatures<InteractionState, Boolean>, ObservableValue<Boolean>>() { @Override public ObservableValue<Boolean> call( TableColumn.CellDataFeatures<InteractionState, Boolean> param) { return param.getValue().onProperty(); } }); CheckTableColumn.setCellFactory(CheckBoxTableCell.forTableColumn(CheckTableColumn)); cb.setUserData(CheckTableColumn); cb.setOnAction( (ActionEvent event) -> { CheckBox cb1 = (CheckBox) event.getSource(); TableColumn tc = (TableColumn) cb1.getUserData(); InteractionTableView.getItems() .stream() .forEach( (item) -> { item.setOn(cb1.isSelected()); }); }); CheckTableColumn.setGraphic(cb); } logger.exit(); }
@Override @SuppressWarnings("unchecked") public void updateItem(Boolean checked, boolean empty) { super.updateItem(checked, empty); if (checked != null && getTableRow() != null) { checkBox.setSelected(checked); checkBox .selectedProperty() .addListener( (check, oldValue, newValue) -> { Object item = getTableRow().getItem(); setBoolean((S) item, newValue); }); setGraphic(checkBox); setStyle("-fx-alignment: CENTER;"); } }
/** * Create the active column, which holds the activity state and also creates a callback to the * string property behind it. */ private void setUpActiveColumn(TableView<FilterInput> tableView) { // Set up active column final TableColumn<FilterInput, Boolean> activeColumn = new TableColumn<>("Active"); activeColumn.setMinWidth(50); activeColumn.setPrefWidth(50); tableView.getColumns().add(activeColumn); activeColumn.setSortable(false); activeColumn.setCellFactory( CheckBoxTableCell.forTableColumn( (Callback<Integer, ObservableValue<Boolean>>) param -> { final FilterInput input = tableView.getItems().get(param); input .getActiveProperty() .addListener( l -> { notifyUpdateCommand(input); }); return input.getActiveProperty(); })); }
@Override public void initialize(URL location, ResourceBundle resources) { // cellvaluefactory checkedColumn.setCellValueFactory(new PropertyValueFactory<>("checked")); columnNameColumn.setCellValueFactory(new PropertyValueFactory<>("columnName")); jdbcTypeColumn.setCellValueFactory(new PropertyValueFactory<>("jdbcType")); propertyNameColumn.setCellValueFactory(new PropertyValueFactory<>("propertyName")); typeHandlerColumn.setCellValueFactory(new PropertyValueFactory<>("typeHandler")); // Cell Factory that customize how the cell should render checkedColumn.setCellFactory(CheckBoxTableCell.forTableColumn(checkedColumn)); javaTypeColumn.setCellFactory(TextFieldTableCell.forTableColumn()); // handle commit event to save the user input data javaTypeColumn.setOnEditCommit( event -> { event .getTableView() .getItems() .get(event.getTablePosition().getRow()) .setJavaType(event.getNewValue()); }); propertyNameColumn.setCellFactory(TextFieldTableCell.forTableColumn()); propertyNameColumn.setOnEditCommit( event -> { event .getTableView() .getItems() .get(event.getTablePosition().getRow()) .setPropertyName(event.getNewValue()); }); typeHandlerColumn.setCellFactory(TextFieldTableCell.forTableColumn()); typeHandlerColumn.setOnEditCommit( event -> { event .getTableView() .getItems() .get(event.getTablePosition().getRow()) .setTypeHandle(event.getNewValue()); }); }