Dynamically create new row on commit last row's last cell's CellEditor [message #1769473] |
Mon, 31 July 2017 22:05 |
|
I'm trying to achieve the following:
I have a data model with a fixed no. of columns. Whenever a user edits the last column of the last row in the NatTable, and commits the edit, a new row should be created dynamically, with some prefilled values.
I'm trying to achieve this via a custom edit config on the NatTable object, extending AbstractRegistryConfiguration, and registering a custom cell editor extending nattable.edit.editor.TextCellEditor.
In this custom cell editor's public boolean commit(MoveDirectionEnum direction, boolean closeAfterCommit, boolean skipValidation) method which overrides the super type method, I create a new object in the data model which is basically a list of objects of just one custom type, i.e., I create a new instance of CustomType and add it to the list. (code snippets below).
For some reason, however, commit() is called twice, and thus two new objects are added to the list.
I'm not quite sure *why* commit() is called twice (perhaps the AbstractCellEditor's commit() method calling doCommand(new EditSelectionCommand)?), but I'd like to be able to hook into the edit lifecycle somehow to manually add an entry to the data model.
How can I achieve this? Many thanks!
public class NewValueCreatingTextCellEditor extends TextCellEditor {
private String originalCanonicalValue;
@Override
protected Control activateCell(final Composite parent, Object originalCanonicalValue) {
this.originalCanonicalValue = String.valueOf(originalCanonicalValue);
return super.activateCell(parent, originalCanonicalValue);
}
@Override
public boolean commit(MoveDirectionEnum direction, boolean closeAfterCommit, boolean skipValidation) {
if (getCanonicalValue() != null) {
if (!getCanonicalValue().equals(originalCanonicalValue)) {
MyEditorConfiguration.this.editor.setDirty(true);
}
}
else if (originalCanonicalValue != null) {
MyEditorConfiguration.this.editor.setDirty(true);
}
int thisRowIndex = MyEditorConfiguration.this.editor.getBodyLayer().getSelectionLayer().getSelectedRowPositions().iterator().next().end;
boolean committed = super.commit(MoveDirectionEnum.NONE, true, true);
MyEditorConfiguration.this.editor.getMyModel().addValue(thisRowIndex, MyFactory.createMyValue("XXX", null, "YYY", "ZZZ", "AAA", false, null));
return committed;
}
}
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03053 seconds