I want to implement a row deletion logic in a Nebula Nattable. This is what I plan to do:
- Add context menu to the Nattable which is described in http://blog.vogella.com/2015/02/03/nattable-context-menus-with-eclipse-menus/
- Add an SWT Action to the menu which will implement the delete
my question is, which is the best way to accomplish this:
- Should I delete the corresponding value from my data model and the table view is refreshed when I execute
this.natview.refresh();
? OR - Should I get the rows from
SelectionLayer
and delete them (if so how do I do ?)? OR - is there any default support for this function through
IConfiguration
?
In NatTable you would typically do the following:
Create a command for deleting a row
Create a command handler for that command
Register the command handler to the body DataLayer
Add a menu item to your menu configuration that fires the command
Using this you don't need to call
NatTable#refresh()
because the command handler fires aRowDeleteEvent
. I also don't suggest to callNatTable#refresh()
in such a case, as it might change and refresh more than it should and would not update other states correctly, which is done correctly by firing theRowDeleteEvent
.Note that the shown example deletes the row for which the context menu is opened. If all selected rows should be deleted, you should create a command handler that knows the
SelectionLayer
and retrieve the selected rows as shown in the other answer.In our application we do the following:
Get selected row objects:
Remove them from the data provider
natTable.refresh()