Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » dynamic context menu
dynamic context menu [message #745566] Sat, 22 October 2011 22:39 Go to next message
Bumbarash  is currently offline Bumbarash Friend
Messages: 1
Registered: October 2011
Junior Member
hi,

I'm developing an Eclipse plugin with an object contribution (submenu called "New Submenu2") to a context menu of a third-party plugin. I'd like to add some menu items to my submenu dynamically. Unfortunately, I can't get my code to work. Here's my code and a part of plugin.xml. Any help would be greatly appreciated...

             //////////////////////////////////////////
             IMenuService menuService = (IMenuService)PlatformUI.getWorkbench().getService(IMenuService.class);

           AbstractContributionFactory factory = new AbstractContributionFactory(
                   //"popup:org.eclipse.ui.popup.any?after=additions",null) {
                 "popup:psu.menu2?after=additions",Activator.PLUGIN_ID) {
              
              public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) {

                 CommandContributionItemParameter itemParam = new CommandContributionItemParameter(
                       serviceLocator, "my.id","my.command",SWT.PUSH);
                 itemParam.label = "MyItem";
               
                   CommandContributionItem item = new CommandContributionItem(itemParam);
                   item.setVisible(true);
                   additions.addContributionItem(item,null);

               }

               public void releaseContributionItems(IMenuService menuService,List items) {}

           };
           menuService.addContributionFactory(factory);             
             
             //----------------------------------------------------------------------------



   <extension point="org.eclipse.ui.popupMenus">

      <objectContribution
            id="psu.contextmenu.classeditpart"
            objectClass="org.topcased.modeler.uml.classdiagram.edit.ClassEditPart">
         <menu
               id="psu.menu2"
               label="New Submenu2"
               path="additions">
            <separator
                  name="group2">
            </separator>
         </menu>
         <action
               class="psu.popup.actions.NewAction2"
               enablesFor="1"
               id="psu.newAction2"
               label="New Action2"
               menubarPath="psu.menu2/group2">
         </action>
      </objectContribution>

   </extension>
Re: dynamic context menu [message #752407 is a reply to message #745566] Wed, 26 October 2011 11:34 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

You don't generally mix objectContributions and the command menu support.

What do you see in the menu, and what do you expect to see?

PW


Previous Topic:Where are the source build scripts???
Next Topic:Parameterized commands and key bindings
Goto Forum:
  


Current Time: Sat Dec 20 13:12:04 GMT 2014

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

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