Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » view action delegate with sub menu ...
view action delegate with sub menu ... [message #332277] Thu, 16 October 2008 12:22 Go to next message
Carmelo  is currently offline Carmelo Friend
Messages: 224
Registered: July 2009
Senior Member
Hi all,

I need to implement a view action that will display, as a submenu, a list of
actions when selected ... the action comes from extension point (view action
delegate)

VIEW CONTEXT MENU
________________
- Action 1
- Action 2
- List Action
- sub action a
- sub action b
- sub action c
- sub action d
- Action 3

I'll try to describe what I need to do ...

I have a list of names that I know at runtime ...
When I select an item in my view I would like to see in the context menu my
"List Action" action with a submenu that will list the actions (each one
named with the name I read when the application when it starts ...)

I have found a way to do this via a normal action (jface.action) where I can
override the setMenuCreator (with IMenuCreator) ...
But what shall I do here ...

This action is contributed to my view from a fragment so I cannot directly
add the action to the context menu and I cannot create in the

Any suggestion, or a better approach will be appreciated.

Thanks
Kar


<fragment>
<extension
point="org.eclipse.ui.popupMenus">
<viewerContribution
id="org.eclipse.ui.articles.action.contribution.popup.navigator "
targetID="com.xxx..views.DBView">
<action
class=" org.eclipse.ui.articles.action.contribution.ViewAction1Deleg ate "
icon="icons/command.gif"
menubarPath="additions"
id=" org.eclipse.ui.articles.action.contribution.navigator.action 1 "
label="View Action 1">
</action>
<menu
id=" org.eclipse.ui.articles.action.contribution.navigator.subMen u "
label="View Sub Menu"
path="additions">
<separator
name="group1">
</separator>
</menu>
....
....
Re: view action delegate with sub menu ... [message #332278 is a reply to message #332277] Thu, 16 October 2008 13:51 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Yes, don't use actions.

You can use org.eclipse.ui.menus to create a view submenu that contains
a dynamic contribution ... implement CompoundContributionItem and you
can return your dynamic list (I'd still suggest commands and
CommandContributionItems, but you can return ActionContributionItems if
you are so inclined).

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/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm


Re: view action delegate with sub menu ... [message #332291 is a reply to message #332277] Fri, 17 October 2008 09:43 Go to previous messageGo to next message
Carmelo  is currently offline Carmelo Friend
Messages: 224
Registered: July 2009
Senior Member
Thanks Paul . it worked .

One more question if I can .

The example works fine when I add the dynamic actions to the context menu
but I would love to create a sub menu (SUB ACTION) that will be populated
with the dynamic actions.

I have tried:

a) Adding in the plugin C (the one that will display the dynamic actions) a
popup menu extension point that will just create a new menu separator .
I have tried to set the menu contribution uri to
"my.project.menu3/subseparator" with no luck (I can only see the the action2
in the sub menu) - the example works fine if I use additions in the uri.

b) Or shall I put the popup menus extension point in the plugin B - the one
where is present the db view .

c) I have even tried to create a sub menu ( in the bit of code that will
fill the context menu . ) but still I cannot add the dynamic action plus the
context menu start acting weirdly (separator appears and disappear each time
the context menu is displayed)

MenuManager viewMenu = new MenuManager("Local View", "locals");
viewMenu.add(new Separator("popuplactions"));
viewMenu.add (actionExecEomdbAction);
manager.add(viewMenu);

What am I doing wrong?
Thanks Kar


<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>
<extension
point="org.eclipse.ui.popupMenus">
<viewerContribution
id="my.project.viewerContribution2"
targetID="com.utils.views.DBView">
<menu
id="my.project.menu3"
label="SUB MENU"
path="additions">
<separator
name="subseparator">
</separator>
</menu>
<action
class="my.project.Action2"
id="my.project.action2"
label="label"
menubarPath="my.project.menu3/subseparator">
</action>
</viewerContribution>
</extension>

<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI=" popup:com.eidosmedia.eomutils.views.EomDBView?after=addition s ">
<dynamic
class="my.project.MyCompoundContributionItem"
id="my.project.myCompoundContributionItem">
</dynamic>
</menuContribution>
</extension>

<extension
point="org.eclipse.ui.commands">
<category
id="my.project.myCategory"
name="My Category">
</category>
<command
categoryId="my.project.myCategory"
id="my.project.myCommand"
name="Do Something ">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="my.project.MyHandler"
commandId="my.project.myCommand">
</handler>
</extension>
</plugin>



"Kar" <carmeloscala@hotmail.com> wrote in message
news:gd7blr$fud$1@build.eclipse.org...
> Hi all,
>
> I need to implement a view action that will display, as a submenu, a list
> of actions when selected ... the action comes from extension point (view
> action delegate)
>
> VIEW CONTEXT MENU
> ________________
> - Action 1
> - Action 2
> - List Action
> - sub action a
> - sub action b
> - sub action c
> - sub action d
> - Action 3
>
> I'll try to describe what I need to do ...
>
> I have a list of names that I know at runtime ...
> When I select an item in my view I would like to see in the context menu
> my "List Action" action with a submenu that will list the actions (each
> one named with the name I read when the application when it starts ...)
>
> I have found a way to do this via a normal action (jface.action) where I
> can override the setMenuCreator (with IMenuCreator) ...
> But what shall I do here ...
>
> This action is contributed to my view from a fragment so I cannot directly
> add the action to the context menu and I cannot create in the
>
> Any suggestion, or a better approach will be appreciated.
>
> Thanks
> Kar
>
>
> <fragment>
> <extension
> point="org.eclipse.ui.popupMenus">
> <viewerContribution
>
> id="org.eclipse.ui.articles.action.contribution.popup.navigator "
> targetID="com.xxx..views.DBView">
> <action
>
> class=" org.eclipse.ui.articles.action.contribution.ViewAction1Deleg ate "
> icon="icons/command.gif"
> menubarPath="additions"
>
> id=" org.eclipse.ui.articles.action.contribution.navigator.action 1 "
> label="View Action 1">
> </action>
> <menu
>
> id=" org.eclipse.ui.articles.action.contribution.navigator.subMen u "
> label="View Sub Menu"
> path="additions">
> <separator
> name="group1">
> </separator>
> </menu>
> ...
> ...
Re: view action delegate with sub menu ... [message #332300 is a reply to message #332278] Fri, 17 October 2008 14:48 Go to previous messageGo to next message
Carmelo  is currently offline Carmelo Friend
Messages: 224
Registered: July 2009
Senior Member
Paul sorry ... one more question ...

in the previous post I told you I was using the View Action Delegate to
perform my action ...
now, using the CommandContributionItem and the command handler how can I
know (or at least from where) the selected item in the view ... can I do
something similar selectionChanged ...

thanks
kar




"Paul Webster" <pwebster@ca.ibm.com> wrote in message
news:gd7h92$b80$1@build.eclipse.org...
> Yes, don't use actions.
>
> You can use org.eclipse.ui.menus to create a view submenu that contains a
> dynamic contribution ... implement CompoundContributionItem and you can
> return your dynamic list (I'd still suggest commands and
> CommandContributionItems, but you can return ActionContributionItems if
> you are so inclined).
>
> 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/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm
Re: view action delegate with sub menu ... [message #332301 is a reply to message #332291] Fri, 17 October 2008 14:57 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Kar wrote:

>
> <?xml version="1.0" encoding="UTF-8"?>
> <?eclipse version="3.2"?>
> <plugin>
> <extension
> point="org.eclipse.ui.popupMenus">
> <viewerContribution
> id="my.project.viewerContribution2"
> targetID="com.utils.views.DBView">
> <menu
> id="my.project.menu3"
> label="SUB MENU"
> path="additions">
> <separator
> name="subseparator">
> </separator>
> </menu>

This needs to be in your menu contribution, since org.eclipse.ui.menus
can't see popupMenus

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/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm


Re: view action delegate with sub menu ... [message #332302 is a reply to message #332300] Fri, 17 October 2008 14:59 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Kar wrote:
> Paul sorry ... one more question ...
>
> in the previous post I told you I was using the View Action Delegate to
> perform my action ...
> now, using the CommandContributionItem and the command handler how can I
> know (or at least from where) the selected item in the view ... can I do
> something similar selectionChanged ...

With a subclass of AbstractHandler the execution event contains the
current selection and the active part. You can use the helper methods
on HandlerUtil to get them. For popup menus, check out active menu
selection and then selection.

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/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm


Re: view action delegate with sub menu ... [message #332305 is a reply to message #332302] Fri, 17 October 2008 15:41 Go to previous messageGo to next message
Carmelo  is currently offline Carmelo Friend
Messages: 224
Registered: July 2009
Senior Member
Hi Paul
hi have tried both the

HandlerUtil.getActiveMenuSelection(event)
HandlerUtil.getCurrentSelection(event)

but both are null ...

I will try to debug on Monday so I can see if I'm missing something ...
thanks again
kar



"Paul Webster" <pwebster@ca.ibm.com> wrote in message
news:gda9kj$r6b$2@build.eclipse.org...
> Kar wrote:
>> Paul sorry ... one more question ...
>>
>> in the previous post I told you I was using the View Action Delegate to
>> perform my action ...
>> now, using the CommandContributionItem and the command handler how can I
>> know (or at least from where) the selected item in the view ... can I do
>> something similar selectionChanged ...
>
> With a subclass of AbstractHandler the execution event contains the
> current selection and the active part. You can use the helper methods on
> HandlerUtil to get them. For popup menus, check out active menu selection
> and then selection.
>
> 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/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm
Re: view action delegate with sub menu ... [message #332306 is a reply to message #332301] Fri, 17 October 2008 15:44 Go to previous messageGo to next message
Carmelo  is currently offline Carmelo Friend
Messages: 224
Registered: July 2009
Senior Member
could u please be more specific ...
in the org.eclipse.ui.menus ext point I can add just MENU / WIDGET and
Group ...

ciao
kar



<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI=" popup:com.eidosmedia.eomutils.views.EomDBView?after=addition s ">
<dynamic
class="my.project.MyCompoundContributionItem"
id="my.project.myCompoundContributionItem">
</dynamic>

</menuContribution>
</extension>

"Paul Webster" <pwebster@ca.ibm.com> wrote in message
news:gda9gp$r6b$1@build.eclipse.org...
> Kar wrote:
>
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <?eclipse version="3.2"?>
>> <plugin>
>> <extension
>> point="org.eclipse.ui.popupMenus">
>> <viewerContribution
>> id="my.project.viewerContribution2"
>> targetID="com.utils.views.DBView">
>> <menu
>> id="my.project.menu3"
>> label="SUB MENU"
>> path="additions">
>> <separator
>> name="subseparator">
>> </separator>
>> </menu>
>
> This needs to be in your menu contribution, since org.eclipse.ui.menus
> can't see popupMenus
>
> 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/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm
Re: view action delegate with sub menu ... [message #332357 is a reply to message #332306] Mon, 20 October 2008 11:38 Go to previous messageGo to next message
Carmelo  is currently offline Carmelo Friend
Messages: 224
Registered: July 2009
Senior Member
Hi Paul . solved problem about command parameters and selected item .
I still need to create the sub menu with the dynamic actions on the view
context menu .

I have tried adding the following bit to the main plugin (the one with the
view):

<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:com.utils.views.DBView?after=additions">
<menu
id="myid"
label="MyLocalAct">
<separator
name="Utils.separator1"
visible="true">
</separator>
</menu>
</menuContribution>
</extension>


And in the extending plugin use:

<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:com.utils.views.DBView?after=myid/Utils.separator1 ">

<dynamic
class="my.project.MyCompoundContributionItem"
id="my.project.myCompoundContributionItem">
</dynamic>

....

This did not worked . (if I use just after=myid I can see the list of
commands listed in the main level of the context menu).

-----

I did tried to put all the bit of code in the extending plugin .


<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:com.utils.views.DBView?after=addition">
<menu
id="idtest"
label="TESTTEST">
<dynamic
class="my.project.MyCompoundContributionItem"
id="my.project.myCompoundContributionItem">
</dynamic>
</menu>

</menuContribution>
</extension>


No action is displayed at all.

Could u please help me
Thanks in advance
Kar



"Kar" <carmeloscala@hotmail.com> wrote in message
news:gdabth$5mk$1@build.eclipse.org...
> could u please be more specific ...
> in the org.eclipse.ui.menus ext point I can add just MENU / WIDGET and
> Group ...
>
> ciao
> kar
>
>
>
> <extension
> point="org.eclipse.ui.menus">
> <menuContribution
>
> locationURI=" popup:com.eidosmedia.eomutils.views.EomDBView?after=addition s ">
> <dynamic
> class="my.project.MyCompoundContributionItem"
> id="my.project.myCompoundContributionItem">
> </dynamic>
>
> </menuContribution>
> </extension>
>
> "Paul Webster" <pwebster@ca.ibm.com> wrote in message
> news:gda9gp$r6b$1@build.eclipse.org...
>> Kar wrote:
>>
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <?eclipse version="3.2"?>
>>> <plugin>
>>> <extension
>>> point="org.eclipse.ui.popupMenus">
>>> <viewerContribution
>>> id="my.project.viewerContribution2"
>>> targetID="com.utils.views.DBView">
>>> <menu
>>> id="my.project.menu3"
>>> label="SUB MENU"
>>> path="additions">
>>> <separator
>>> name="subseparator">
>>> </separator>
>>> </menu>
>>
>> This needs to be in your menu contribution, since org.eclipse.ui.menus
>> can't see popupMenus
>>
>> 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/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm
>
Re: view action delegate with sub menu ... [message #332359 is a reply to message #332305] Mon, 20 October 2008 11:52 Go to previous message
Carmelo  is currently offline Carmelo Friend
Messages: 224
Registered: July 2009
Senior Member
Done ... thanks :-)

http://wiki.eclipse.org/Menu_Contributions/Problems_View_Exa mple


<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:com.utils.views.EomDBView">
<separator name="group.showIn"
visible="true" />
<menu id="org.eclipse.ui.views.problems.showIn.menu"
label="ProblemView.ShowIn.label"
mnemonic="ProblemView.ShowIn.mnemonic">
<dynamic class="my.project.MyCompoundContributionItem"
id="my.project.myCompoundContributionItem"/>
</menu>
</menuContribution>
</extension>

"Kar" <carmeloscala@hotmail.com> wrote in message
news:gdabnf$534$1@build.eclipse.org...
> Hi Paul
> hi have tried both the
>
> HandlerUtil.getActiveMenuSelection(event)
> HandlerUtil.getCurrentSelection(event)
>
> but both are null ...
>
> I will try to debug on Monday so I can see if I'm missing something ...
> thanks again
> kar
>
>
>
> "Paul Webster" <pwebster@ca.ibm.com> wrote in message
> news:gda9kj$r6b$2@build.eclipse.org...
>> Kar wrote:
>>> Paul sorry ... one more question ...
>>>
>>> in the previous post I told you I was using the View Action Delegate to
>>> perform my action ...
>>> now, using the CommandContributionItem and the command handler how can I
>>> know (or at least from where) the selected item in the view ... can I do
>>> something similar selectionChanged ...
>>
>> With a subclass of AbstractHandler the execution event contains the
>> current selection and the active part. You can use the helper methods on
>> HandlerUtil to get them. For popup menus, check out active menu
>> selection and then selection.
>>
>> 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/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm
>
Previous Topic:How do I automatically add certain *.jars to ALL projects?
Next Topic:Re: JFace Table Viewer Editor
Goto Forum:
  


Current Time: Sat Apr 20 16:23:41 GMT 2024

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

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

Back to the top