Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Get position or triggering mouse event of MPopupMenu
Get position or triggering mouse event of MPopupMenu [message #1740198] Wed, 10 August 2016 11:12 Go to next message
Robert Onslow is currently offline Robert OnslowFriend
Messages: 27
Registered: March 2016
Junior Member
I have a popup menu defined for a part.
I register the menu for a particular control using
menuService.registerContextMenu(xrefPane, "uk.co.xbundle.assembly.xrefs.popupmenu");


The popup menu successfully opens on a right click on the control.

The handler defined for one of the menu items has signature:

@Execute
public abstract void execute(MPopupMenu menu) {
...
}


This works, because the triggering popup menu is injected from the context.

I now need to access the xy of the right mouse click which triggered the popup menu, but I can't find my way through to this.

Does anyone know how to get this, or another idiomatic way to get the riggering MouseEvent through to the handler?

Thanks

Robert

[Updated on: Wed, 10 August 2016 11:13]

Report message to a moderator

Re: Get position or triggering mouse event of MPopupMenu [message #1740201 is a reply to message #1740198] Wed, 10 August 2016 11:46 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
IIRC there's no coordinate available (even at the SWT level) because a
popup menu could also be triggered through keyboard shortcuts. The only
possible work around is to get the current cursor location.

Tom

On 10.08.16 13:12, Robert Onslow wrote:
> I have a popup menu defined for a part.
> I register the menu for a particular control using
>
> menuService.registerContextMenu(xrefPane,
> "uk.co.xbundle.assembly.xrefs.popupmenu");
>
>
> The popup menu successfully opens on a right click on the control.
>
> The handler defined for one of the menu items has signature:
>
>
> @Execute
> public abstract void execute(MPopupMenu menu) {
> ..
> }
>
>
> This works, because the triggering popup menu is injected from the context.
>
> I now need to access the xy of the right mouse click which triggered the
> popup menu, but I can't find my way through to this.
>
> Does anyone know how to get this, or another idiomatic way to get the
> riggering MouseEvent through to the handler?
>
> Thanks
>
> Robert
Re: Get position or triggering mouse event of MPopupMenu [message #1740226 is a reply to message #1740201] Wed, 10 August 2016 14:41 Go to previous messageGo to next message
Robert Onslow is currently offline Robert OnslowFriend
Messages: 27
Registered: March 2016
Junior Member
Thanks Tom
In EclipseFX I worked around using:

ContextMenu cm = (ContextMenu) ((WPopupMenu<ContextMenu>) menu.getWidget()).getWidget();
double x = cm.getX();
		


Robert
Re: Get position or triggering mouse event of MPopupMenu [message #1740252 is a reply to message #1740226] Wed, 10 August 2016 18:35 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Oh you are talking about FX? It somehow feels wrong to rely on UI
information an naturally you rely on a implementation detail of the
renderer framework (although unlikely to change any time :-).

I guess if you describe your usecase a bit more we could find a better
solution. Why do you need the x/y information?

Tom

On 10.08.16 16:41, Robert Onslow wrote:
> Thanks Tom
> In EclipseFX I worked around using:
>
>
> ContextMenu cm = (ContextMenu) ((WPopupMenu<ContextMenu>)
> menu.getWidget()).getWidget();
> double x = cm.getX();
>
>
> Robert
Re: Get position or triggering mouse event of MPopupMenu [message #1740376 is a reply to message #1740252] Fri, 12 August 2016 12:28 Go to previous message
Robert Onslow is currently offline Robert OnslowFriend
Messages: 27
Registered: March 2016
Junior Member
Hi Tom

This attached screen shot shows a cross reference on a document on the right hand side. (This is the Text control showing "trial/1/2" in the left hand margin of the document)

A new cross reference is added by clicking "End XRef" on a popup menu, also shown.

The handler needs to know where on the document the popup was triggered in order to know where to place the new cross-refererence on the document.

That means getting some info about the triggering event, or the position of the popup, into the handler attached to the End XRef menu item.

MPopupMenu at the moment has no access to the triggering mouse event, or the position of the popup. Hence the clunky workaround by getting hold of the rendered component which I agree is less than ideal.

Could MPopupMenu eventually contain some triggering data do you think? It seems to me that popups will quite often need to pass positional data to handlers - e.g. adding components to a diagram via a popup etc.

Robert
Previous Topic:MessageConsole
Next Topic:Persisted object when closing MPart ?
Goto Forum:
  


Current Time: Sat Apr 20 03:50:39 GMT 2024

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

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

Back to the top