I have the following problem: I write my app using JavaFX. I use TableView. Users should use it to observe, add and remove data. I have ID field that should be unique. So when user finishes to edit it I have to check whether result is unique or not. And if it’s unique I have to dismiss changings. Or even better I have to check it at the moment when data is updated and if necessary skip update.
I have TableView with three columns
colID.setCellValueFactory((TableColumn.CellDataFeatures<CDataType, String> cell) -> cell.getValue().getSID());
colCaption.setCellValueFactory((TableColumn.CellDataFeatures<CDataType, String> cell) -> cell.getValue().getSCaption());
colType.setCellValueFactory((TableColumn.CellDataFeatures<CDataType, String> cell) -> cell.getValue().getSType());
colID.setCellFactory(TextFieldTableCell.forTableColumn());
colCaption.setCellFactory(TextFieldTableCell.forTableColumn());
colType.setCellFactory(TextFieldTableCell.forTableColumn());
lstObservable = FXCollections.observableList(lstData, (CDataType param)->{
param.getSID().addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> {
System.out.println("getSID().ChangeListener: Changed: " + observable + ")"+ observable.getClass() + ") [" + oldValue + " -> " + newValue + "]");
}
});
return new Observable[]{param.getSID(),
param.getSCaption(),
param.getSType()
};
});
tabView.setItems(lstObservable);
What is usual practice for this? I’m sure that this problem is not new, but I can not find solution.
UPD: I mean that I don't understand what event should I handle to dimiss user changings. I suppose that it must be ChangeListener but if I change back data item value I got infinite recursion.