Curt Arnold
19 Jun 2009, 11:19 AM
I've been using RowEditor in the milestones and had to do a very hacky extension of RowEditor to get notification that the user has closed the row editor when they either pressed Cancel or pressed Save with no changes. I've looked at the code in M3 and the situation does not look changed.
In my app, I have a button to add a new record with default values to the grid and calls RowEditor.startEditing to invoke the editor. If the user does not make any changes or presses the Cancel button, I need to remove the new record from the grid.
p.s. stopEditing(true) can trigger a call to stopEditing(false), so you have to be careful to only send CancelEdit when the RowEditor is visible.
I did my hack as an extension, but something like the following changes would address the issue in the base implementation:
/grid
$ diff -c4 RowEditor.java RowEditor.hack
*** RowEditor.java Thu Jun 11 17:58:58 2009
--- RowEditor.hack Fri Jun 19 14:14:08 2009
***************
*** 240,247 ****
--- 240,248 ----
return;
}
if (!saveChanges || !isValid()) {
hide();
+ fireEvent(Events.CancelEdit, new RowEditorEvent(this, rowIndex));
return;
}
Map<String, Object> data = new FastMap<Object>();
***************
*** 274,281 ****
--- 275,284 ----
record.endEdit();
ree.setRecord(record);
fireEvent(Events.AfterEdit, ree);
+ } else {
+ fireEvent(Events.CancelEdit, ree);
}
hide();
}
In my app, I have a button to add a new record with default values to the grid and calls RowEditor.startEditing to invoke the editor. If the user does not make any changes or presses the Cancel button, I need to remove the new record from the grid.
p.s. stopEditing(true) can trigger a call to stopEditing(false), so you have to be careful to only send CancelEdit when the RowEditor is visible.
I did my hack as an extension, but something like the following changes would address the issue in the base implementation:
/grid
$ diff -c4 RowEditor.java RowEditor.hack
*** RowEditor.java Thu Jun 11 17:58:58 2009
--- RowEditor.hack Fri Jun 19 14:14:08 2009
***************
*** 240,247 ****
--- 240,248 ----
return;
}
if (!saveChanges || !isValid()) {
hide();
+ fireEvent(Events.CancelEdit, new RowEditorEvent(this, rowIndex));
return;
}
Map<String, Object> data = new FastMap<Object>();
***************
*** 274,281 ****
--- 275,284 ----
record.endEdit();
ree.setRecord(record);
fireEvent(Events.AfterEdit, ree);
+ } else {
+ fireEvent(Events.CancelEdit, ree);
}
hide();
}