Skip to main content



      Home
Home » Eclipse Projects » NatTable » Get original mouse coordinates when opening context menu in headers
Get original mouse coordinates when opening context menu in headers [message #1862874] Wed, 03 January 2024 05:57 Go to next message
Eclipse UserFriend
Hey there,

I have followed the excellent tutorial at https://vogella.com/blog/nattable-context-menus-with-eclipse-menus/ to create a context menu for my row and column headers. However, my context menu has a sub menu which needs to be populated with menu items depending on the concrete header cell the user clicked on. My problem is that I cannot find a way to determine which cell that is.

My current workaround is to get the cursor position from Display and use that to find the cell. The problem is that once I call
Point cursorLocation = Display.getCurrent().getCursorLocation();
Point relativeCursorLocation = Display.getCurrent().getFocusControl().toControl(cursorLocation);

in my custom MenuContribution, the user has already moved the cursor over to open the context menu and I can no longer reliably use the mouse coordinates to locate the original header cell.

I have also tried using the SelectionProvider, but I also want this to work if the user clicks on a header cell that is not selected.

My hunch is that I could fix this by getting to the coordinates in the MouseEvent that triggered the context menu, but I cannot find a way to get there.

Any ideas how to achieve this?

Thanks,
Jan-Philipp
Re: Get original mouse coordinates when opening context menu in headers [message #1862882 is a reply to message #1862874] Thu, 04 January 2024 01:19 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

First, the forum is going to be shut down AFAIK and the project was moved to GitHub. We have enabled GitHub Discussions, so please ask questions there.

Second, we recently added support for adding sub menus via the PopupMenuBuilder. This is available in the latest SNAPSHOT builds and will be published with the upcoming 2.3 release.

Third, the information about the click the triggered the context menu is stored in the NatEventData object that is set as data to the created menu under the key MenuItemProviders.NAT_EVENT_DATA_KEY. Have a look at the PopupMenuAction to see where it is set. The NatEventData contains the clicked column and row position and even the original mouse event in case you really need to use the information from there.
Re: Get original mouse coordinates when opening context menu in headers [message #1862886 is a reply to message #1862882] Thu, 04 January 2024 06:10 Go to previous message
Eclipse UserFriend
Hey Dirk,

Thanks for your quick response. Good to see that support for this will be added in the next version.

Your third piece of information got me there. I had actually tried to retrieve the NatEventData on the menu that I get in the run() method of the contribution item and it is not contained there (obviously in retrospect since that is the submenu that I am working in). But once I used menu.getParentMenu() to get to the menu that NatTable actually opens rather than to my submenu, there it was. Awesome!

All the best,
Jan-Philipp
Previous Topic:NatTable 2.2.1 released
Next Topic:How to paint cell background for Nattable based one RichtextPainter,
Goto Forum:
  


Current Time: Sun May 18 00:18:53 EDT 2025

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

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

Back to the top