I have a table written in JavaFX, that the user has the option to edit one of its columns. When an editing of a cell takes place, I try to rename some internal object based on the new text. If that renaming fails, I issue a notification + popup an error dialog, and then I'd like to restore the original text into that field. For some reason, this gets me into an infinite loop of error popups.
The code I currently have from the original writer is as follows:
mNameColumn.setOnEditCommit(
new EventHandler<TableColumn.CellEditEvent<StateDefinition, String>>() {
@Override
public void handle(TableColumn.CellEditEvent<StateDefinition, String> event) {
try {
someObject.rename(((StateDefinition) event.getTableView().getItems().get(event.getTablePosition().getRow())).getState(), event.getNewValue());
} catch (MYException ex) {
MyNotificationCollector.addNotification("Failed renaming: " + ex.getLocalizedMessage(), NotificationType.SYSTEM_WARNING);
//popup error message code here
// Need to revert the cell's text to the previous value here...
}
}
});
Any idea on what I do wrong? How do I restore the old value without invoking the cell edit commit event again?
Thanks, Oren