I’m using the MasterDetailScreen for an entity and would like to change the entity shown in the editor detail screen when selecting a new item from the DataGrid on the browse side. Currently, when an entity is being edited you cannot select a new entity from the DataGrid until the cancel button is pressed. Ideally, I’d like to be able to automatically cancel a current edit when selecting a new Entity from the browse DataGrid. I’ve attempted to accomplish this by experimenting with enabling and disabling edit controls in a method, onTableSelection(), but without any success.
@Subscribe("table")
public void onTableSelection(DataGrid.SelectionEvent<DataSource> event) {
if (this.editing) {
disableEditControls();
}
Entity selected = table.getSingleSelected();
if (selected != null) {
this.initEditComponents(true);
}
}
Unfortunately, it caused some bugs with the Create action functionality. Attempting to create a new entity, in this case DataSource, and then selecting an item from the browse list and saving instead creates a new item in the DataGrid that is always selected with its duplicate item. Signing in and out clears the duplicate item.
In the table selection listener, you can set this.creating flag to false. It affects whether the item will be added or replaced in the items collection. Also, you have to handle the InitEntityEvent because CreateAction sends selection event with empty items, and listener code may prevent creating new item.