if (!isEditing()) {
throw new IllegalStateException();
}
// Save local reference to members variables before they get cleared
TableView tableView = this.tableView;
int rowIndex = this.rowIndex;
int columnIndex = this.columnIndex;
// Get the changes
String text = textInput.getText();
String columnName = tableView.getColumns().get(columnIndex).getName();
// Preview the changes
HashMap<String, Object> changes = new HashMap<String, Object>();
changes.put(columnName, text);
Vote vote = rowEditorListeners.previewSaveChanges(this, tableView, rowIndex,
columnIndex, changes);
if (vote == Vote.APPROVE) {
List<Object> tableData = (List<Object>)tableView.getTableData();
// Get the row data, represented as a Dictionary
Object tableRow = tableData.get(rowIndex);
Dictionary<String, Object> rowData;
if (tableRow instanceof Dictionary<?, ?>) {
rowData = (Dictionary<String, Object>)tableRow;
} else {
rowData = new BeanDictionary(tableRow);
}
// Update the cell data
rowData.put(columnName, text);
// Notifying the parent will close the popup
if (tableData.getComparator() == null) {
tableData.update(rowIndex, tableRow);
} else {
tableData.remove(rowIndex, 1);
tableData.add(tableRow);
// Re-select the row, and make sure it's visible
rowIndex = tableData.indexOf(tableRow);
tableView.setSelectedIndex(rowIndex);
tableView.scrollAreaToVisible(tableView.getRowBounds(rowIndex));
}
rowEditorListeners.changesSaved(this, tableView, rowIndex, columnIndex);
} else if (vote == Vote.DENY) {
rowEditorListeners.saveChangesVetoed(this, vote);