Eclipse: How to get the MenuManager for a specific menu id defined in plugin.xml -


i have standalone eclipse rcp application. main interaction happens through main toolbar. here relevant snippet plugin.xml:

<extension      point="org.eclipse.ui.menus">   <menucontribution         allpopups="false"         locationuri="toolbar:org.eclipse.ui.main.toolbar">      <toolbar            id="my.toolbar.id">         ...         <command               commandid="my.command.id"               id="my.connect.id"               label="connect"               style="pulldown">         </command>         ...      </toolbar>   </menucontribution>   <menucontribution         allpopups="false"         locationuri="menu:my.connect.id">   </menucontribution> 

i populate pulldown menu my.connect.id when shown, can hold different items every time opened. can done using menumanager id , add imenulistener.

how obtain instance of menumanager given id plugin.xml?

thanks lot.

ps: still e3.

i took me couple of days , research figure out. here answer own question:

give menu dyanmic contribution class handles contributions.

plugin.xml:

  <menucontribution         allpopups="false"         locationuri="menu:my.connect.id">      <dynamic            class="my.connectmenu"            id="my.connect.menu">      </dynamic>   </menucontribution> 

connectmenu.java:

public class connectmenu extends contributionitem {      private imenulistener menulistener = new imenulistener() {         public void menuabouttoshow(imenumanager manager) {             fillmenu(manager);         }     };      public connectmenu() {         this("my.connect.menu");     }      public connectmenu(string id) {         super(id);     }      @override     public void fill(menu menu, int index) {         super.fill(menu, index);          if (getparent() instanceof menumanager) {             ((menumanager) getparent()).setremoveallwhenshown(true);             ((menumanager) getparent()).addmenulistener(menulistener);         }     }      private void fillmenu(imenumanager mgr) {         mgr.add(createcontributionitem());                mgr.update();     }      private icontributionitem createcontributionitem() {         // ...     } } 

hope helps.

very helpful me: https://phisymmetry.wordpress.com/2010/01/03/eclipse-tips-how-to-create-menu-items-dynamically/


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -