Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Right-Click-Selection-Update with open Context Menu
Right-Click-Selection-Update with open Context Menu [message #1830312] Thu, 23 July 2020 08:33 Go to next message
Stefan T is currently offline Stefan TFriend
Messages: 4
Registered: November 2019
Junior Member
Hello everyone! I am trying to convince my NatTable to update the currently selected cell on a right click before opening the context menu, since the menu's content and actions are dependant on the selected cell.

In the general case, this can be accomplished by adding the following UiBindingConfiguration:

getNatTable().addConfiguration(new AbstractUiBindingConfiguration() {
      @Override
      public void configureUiBindings(UiBindingRegistry pUiBindingRegistry) {
        pUiBindingRegistry.registerMouseDownBinding(new MouseEventMatcher(SWT.NONE, null, MouseEventMatcher.RIGHT_BUTTON),
            new SelectCellAction());
      }
    });


However, this approach does not always work when the context menu is already open (i.e. by repeating right mouse clicks on an open table). My current best guess is that the statemask, specified as SWT.NONE, doesn't match in this specific case.

This theory is supported by the fact that holding down any control key(ctrl/alt/shift) while right clicking, which does mutate the statemask, also causes the selection to not update. If there was a way to register a MouseEventMatcher with no regard to the statemask, that may solve the issue. Alternatively, if the value of the statemask during my edge-case was known, i could register this edge-case and work around the issue that way.

The matter is made more complicated by the fact that the actual context menu is handled through the eclipse e4 framework, otherwise i could've just hardwired the Action for opening a context menu to do a SelectCellCommand first.

Any ideas?

[Updated on: Thu, 23 July 2020 09:09]

Report message to a moderator

Re: Right-Click-Selection-Update with open Context Menu [message #1830317 is a reply to message #1830312] Thu, 23 July 2020 09:37 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 47
Registered: March 2020
Member
1. The statemask defines what control keys are currently pressed. You have to provide one either as NONE or the corresponding control keys you want to react on. This is because a pressed control key typically means a different behavior.
2. There is no action on right click while a control key is pressed, because there is no binding for this. Not even a selection update, because there are no default bindings for the right clicks on the body.
3. The design of the actions registered is not stacking. That means if you register multiple actions for the same binding, only the first one found will be executed. At least IIRC.

The DataModificationExample [1] shows how to attach a body menu on right click by performing a row selection first. By adapting that to your use case you should be able to get your stuff working. But you will also need to register bindings for CTRL+Right Click, SHIFT+Right Click and ALT+Right Click if you want the same behavior regardless of the state mask.

[1] https://github.com/eclipse/nebula.widgets.nattable/blob/master/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_300_Data/_308_DataModificationExample.java
Re: Right-Click-Selection-Update with open Context Menu [message #1830320 is a reply to message #1830317] Thu, 23 July 2020 10:40 Go to previous messageGo to next message
Stefan T is currently offline Stefan TFriend
Messages: 4
Registered: November 2019
Junior Member
Thanks for the quick reply! It appears I have misunderstood the usage of the statemask.

To reiterate, the issue of NatTables occasionally not "noticing" a right click when a context menu is already open is reproducable on multiple of my editors, and should in principle also show up in context menu examples (although i haven't checked).

To anyone curious, the strange behavior of a context menu opening without a selection-update occuring was due to the fact that the context menu was handled through the eclipse framework, while the selection was handled through NatTable.

The workaround i found skips the usage of NatTables addConfiguration-function and uses a lower level approach:

      getNatTable().addMouseListener(new MouseAdapter() {
        
        @Override
        public void mouseDown(MouseEvent e) {
          new SelectCellAction().run(getNatTable(), e);
        }
      }); 
Re: Right-Click-Selection-Update with open Context Menu [message #1830326 is a reply to message #1830320] Thu, 23 July 2020 11:59 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 47
Registered: March 2020
Member
Not sure if you are already aware, but context menus on NatTable where you need context information should NOT be added using the default Eclipse approach. You can of course configure your context menu like this, but the recommendation is to use the NatTable framework for context menus.

I wrote about the possibilities here: http://blog.vogella.com/2015/02/03/nattable-context-menus-with-eclipse-menus/

BTW, using your approach you probably break several NatTable functions or at least cause some side effects. I really recommend to get familiar with the NatTable framework before adding low level code without knowing the implications here. But of course this is only a recommendation.

For anyone else reading the suggested workaround: DON'T DO IT!

[Updated on: Thu, 23 July 2020 12:11]

Report message to a moderator

Previous Topic:FormText in Cell
Next Topic:Nattable compatibility with OpenJDK
Goto Forum:
  


Current Time: Thu Apr 25 13:41:29 GMT 2024

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

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

Back to the top