Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » One Handler for multiple MenutItem
One Handler for multiple MenutItem [message #513826] Thu, 11 February 2010 07:29 Go to next message
Walter Mising name is currently offline Walter Mising name
Messages: 126
Registered: July 2009
Senior Member
How do I get the control of a menu item that was clicked ?

<children xsi:type="application:DirectToolItem" id="Btn1"
URI="platform:/plugin/test/handler.ClickHandler" label="Test_1"
iconURI="platform:/plugin/test/icons/Test_1.png"/>
<children xsi:type="application:DirectToolItem" id="Btn2"
URI="platform:/plugin/test/handler.ClickHandler" label="Test_2"
iconURI="platform:/plugin/test/icons/Test_2.png"/>

The objective is to have 1 ClickHandler and then take action based on the
button clicked.
I would prefer to use "id" to differentiate the button clicked.

Any pointers would help.

Thanks,
Best Regards,
Walter G. Prabhakar.
Re: One Handler for multiple MenutItem [message #513840 is a reply to message #513826] Thu, 11 February 2010 08:31 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

That wouldn't work at the moment, and certainly not with DirectMenuItem.
It's only reason to exist is to allow an object to be instantiated and
respond directly to the SWT.Selection event.

You would create a command with a parameter (buttonId) and have your
handler examine the incoming parameter for your ID. Each
HandledMenuItem can then specify a different ID. That's your exact usecase.


Note: In theory the model element that caused the execution or the SWT
event could be included by somehow updating and cleaning up the
execution context ... probably hooked in
org.eclipse.e4.workbench.ui.renderers.swt.MenuItemRenderer.h ookControllerLogic(MUIElement)

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: One Handler for multiple MenutItem [message #513884 is a reply to message #513840] Thu, 11 February 2010 10:10 Go to previous messageGo to next message
Walter Mising name is currently offline Walter Mising name
Messages: 126
Registered: July 2009
Senior Member
Actually I was referring to DirectToolItem. Apologize for the confusion.


"Paul Webster" <pwebster@ca.ibm.com> wrote in message
news:hl10qo$ddp$1@build.eclipse.org...
> That wouldn't work at the moment, and certainly not with DirectMenuItem.
> It's only reason to exist is to allow an object to be instantiated and
> respond directly to the SWT.Selection event.
>
> You would create a command with a parameter (buttonId) and have your
> handler examine the incoming parameter for your ID. Each HandledMenuItem
> can then specify a different ID. That's your exact usecase.
>
>
> Note: In theory the model element that caused the execution or the SWT
> event could be included by somehow updating and cleaning up the execution
> context ... probably hooked in
> org.eclipse.e4.workbench.ui.renderers.swt.MenuItemRenderer.h ookControllerLogic(MUIElement)
>
> PW
>
>
> --
> Paul Webster
> http://wiki.eclipse.org/Platform_Command_Framework
> http://wiki.eclipse.org/Command_Core_Expressions
> http://wiki.eclipse.org/Menu_Contributions
> http://wiki.eclipse.org/Menus_Extension_Mapping
> http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm
Re: One Handler for multiple MenutItem [message #513911 is a reply to message #513884] Thu, 11 February 2010 11:16 Go to previous message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Walter Prabhakar wrote:
> Actually I was referring to DirectToolItem. Apologize for the confusion.
>

Swap everywhere I said *Menu* with *Tool* and my statements still hold :-)

You can't do it with a Direct*Item. You should use a parameterized
command and its matching Handled*Item which can specify the parameter.

Some kind of trigger (matching model element or widget) could in theory
be handed to the execute(*) method, potentially from
org.eclipse.e4.workbench.ui.renderers.swt.ToolItemRenderer.h ookControllerLogic(MUIElement)
but we don't do that and no one is looking into it.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: One Handler for multiple MenutItem [message #568623 is a reply to message #513826] Thu, 11 February 2010 08:31 Go to previous message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

That wouldn't work at the moment, and certainly not with DirectMenuItem.
It's only reason to exist is to allow an object to be instantiated and
respond directly to the SWT.Selection event.

You would create a command with a parameter (buttonId) and have your
handler examine the incoming parameter for your ID. Each
HandledMenuItem can then specify a different ID. That's your exact usecase.


Note: In theory the model element that caused the execution or the SWT
event could be included by somehow updating and cleaning up the
execution context ... probably hooked in
org.eclipse.e4.workbench.ui.renderers.swt.MenuItemRenderer.h ookControllerLogic(MUIElement)

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: One Handler for multiple MenutItem [message #568651 is a reply to message #513840] Thu, 11 February 2010 10:10 Go to previous message
Walter Mising name is currently offline Walter Mising name
Messages: 126
Registered: July 2009
Senior Member
Actually I was referring to DirectToolItem. Apologize for the confusion.


"Paul Webster" <pwebster@ca.ibm.com> wrote in message
news:hl10qo$ddp$1@build.eclipse.org...
> That wouldn't work at the moment, and certainly not with DirectMenuItem.
> It's only reason to exist is to allow an object to be instantiated and
> respond directly to the SWT.Selection event.
>
> You would create a command with a parameter (buttonId) and have your
> handler examine the incoming parameter for your ID. Each HandledMenuItem
> can then specify a different ID. That's your exact usecase.
>
>
> Note: In theory the model element that caused the execution or the SWT
> event could be included by somehow updating and cleaning up the execution
> context ... probably hooked in
> org.eclipse.e4.workbench.ui.renderers.swt.MenuItemRenderer.h ookControllerLogic(MUIElement)
>
> PW
>
>
> --
> Paul Webster
> http://wiki.eclipse.org/Platform_Command_Framework
> http://wiki.eclipse.org/Command_Core_Expressions
> http://wiki.eclipse.org/Menu_Contributions
> http://wiki.eclipse.org/Menus_Extension_Mapping
> http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm
Re: One Handler for multiple MenutItem [message #568669 is a reply to message #513884] Thu, 11 February 2010 11:16 Go to previous message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Walter Prabhakar wrote:
> Actually I was referring to DirectToolItem. Apologize for the confusion.
>

Swap everywhere I said *Menu* with *Tool* and my statements still hold :-)

You can't do it with a Direct*Item. You should use a parameterized
command and its matching Handled*Item which can specify the parameter.

Some kind of trigger (matching model element or widget) could in theory
be handed to the execute(*) method, potentially from
org.eclipse.e4.workbench.ui.renderers.swt.ToolItemRenderer.h ookControllerLogic(MUIElement)
but we don't do that and no one is looking into it.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Previous Topic:One Handler for multiple MenutItem
Next Topic:How to add a statusbar to an e4 application?
Goto Forum:
  


Current Time: Fri Jul 25 12:03:34 EDT 2014

Powered by FUDForum. Page generated in 0.03090 seconds