Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Canonical way of clearing the content of a cell?
Canonical way of clearing the content of a cell? [message #1805296] Thu, 11 April 2019 10:46 Go to next message
na na is currently offline na naFriend
Messages: 11
Registered: November 2013
Junior Member
Hi,

I'm in the following situation. I want to remove a cells content when I press delete. The cell is in SELECTED-mode, editable and also has validation added via configuration attributes.

My take on this was as follows. I've registered a UI-Binding for the DEL-Key and the action executed checked if the selected cell is editable, fetches the validator, checks if the specific "empty-value" is valid and fires an UpdateDataCommand with this value.

To me this feels a bit cumbersome, and I'm not sure if there is a canonical way to do this stuff, so I'm looking for more info.

Thanks in advance.
Re: Canonical way of clearing the content of a cell? [message #1805300 is a reply to message #1805296] Thu, 11 April 2019 11:52 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Well, this is the way how to do this. But you actually described the default actions and bindings that are already included in NatTable itself. They are just not registered by default. To enable it you can

1. Register the DeleteSelectionCommandHandler on a layer. As the command handler constructor takes the SelectionLayer as parameter, you can even register the command handler on the NatTable or the top layer like the GridLayer itself.
layer.registerCommandHandler(new DeleteSelectionCommandHandler(this.selectionLayer));


2. Register the DeleteSelectionAction for the DEL key
uiBindingRegistry.registerFirstKeyBinding(
        new KeyEventMatcher(SWT.DEL),
        new DeleteSelectionAction());


We are doing this in the DefaultFormulaConfiguration for example.
Re: Canonical way of clearing the content of a cell? [message #1805305 is a reply to message #1805300] Thu, 11 April 2019 12:51 Go to previous messageGo to next message
na na is currently offline na naFriend
Messages: 11
Registered: November 2013
Junior Member
Ah, I see. From the user's perspective it's shorter. I looked through the classes you mentioned like DeleteSelectionCommandHandler and I recognized it skips the validation registered to the column too.

So, I probably have to write my own handler that fetches the applicable validator for the column from the config registry, right? However, with your hints I can do it in a nicer way.

PS: Is the PositionCoordinate in the DeleteSelectionCommandHandler the equivalent to the data layer coordinate? I my first implementation, I have talked about, I fetched the cells from the selection layer and transformed the col/row with the LayerUtil to the data layer.

[Updated on: Thu, 11 April 2019 13:28]

Report message to a moderator

Re: Canonical way of clearing the content of a cell? [message #1805311 is a reply to message #1805305] Thu, 11 April 2019 13:28 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
If you need the validation also, then yes you probably need an extended command handler
Re: Canonical way of clearing the content of a cell? [message #1805316 is a reply to message #1805311] Thu, 11 April 2019 14:13 Go to previous message
na na is currently offline na naFriend
Messages: 11
Registered: November 2013
Junior Member
Yeah, you were right I actually did not need the validation, but instead of only setting "null" I needed to set some sensible default values to a few colums, because they don't have the notion of an empty value, the empty value is some default value.

Nevertheless the code looks cleaner and follows more the natTable-style. So, thanks for your time. :)
Previous Topic:How to reorder multiple columns
Next Topic:Multi Value Editor in NATTable
Goto Forum:
  


Current Time: Thu Mar 28 10:32:57 GMT 2024

Powered by FUDForum. Page generated in 0.07700 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top