In JavaFX 2, I want to disable a some cells in a column for edition. Something along the lines of
TableModel.isCellEditable(row, col)
in Swing. I need the item in the row to make a decision whether the cell is editable, cell value is not enough.
The code I managed to write is:
TableView<FilterItem> localTableView = new TableView<FilterItem>() {
public void edit(int paramInt, TableColumn<FilterItem, ?> paramTableColumn) {
if (paramInt >= 0) {
FilterItem item = getItems().get(paramInt); //get item in the row
if (!item.isPropagated()) { //condition
return;
}
}
super.edit(paramInt, paramTableColumn);
}
};
The problem is that there is no visual clue that certain items are disabled for editing.
Setting the cell factory was the firs thing I tried, but I have no access to row data in update cell method:
localValueCol.setCellFactory(
new Callback<TableColumn<FilterItem, String>, TableCell<FilterItem, String>>() {
@Override
public TableCell<FilterItem, String> call(TableColumn<FilterItem, String> paramTableColumn) {
return new TextFieldTableCell<FilterItem, String>() {
@Override
public void updateItem(String s, boolean b) {
super.updateItem(s, b);
// it is possible set editable property here,
// but other cells are not available to make a decision
}
};
}
});