Get original mouse coordinates when opening context menu in headers [message #1862874] |
Wed, 03 January 2024 05:57  |
Eclipse User |
|
|
|
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 #1862886 is a reply to message #1862882] |
Thu, 04 January 2024 06:10  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.04581 seconds