Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » AbstractContributionFactory for creating menuContributions(Clarifications on how MenuService, MenuManger, CommandContributionItem, and ContributionFactory work )
AbstractContributionFactory for creating menuContributions [message #675278] Tue, 31 May 2011 02:45
John Steele is currently offline John SteeleFriend
Messages: 33
Registered: June 2010
Location: Seattle, WA

I'm trying to understand how the MenuService, MenuManger, CommandContributionItem, and AbstractContributionFactories work together.

I am fully aware of, and understand how to add a menuContribution via the plugin.xml, and how to add commands and handlers to it.

I appreciate the extension point, but I'd like to learn how to do it programmatically, and the different ways of doing it.

Here is one scenario where I add a menu to a menu programmatically:
public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
MenuManager fileMenu;
MenuManager searchSubMenu; 
protected void fillMenuBar(IMenuManager menuBar) {
   fileMenu = new MenuManager("&File", "");
   fileMenu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));    	

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

   AbstractContributionFactory searchContribution = new AbstractContributionFactory
      ("",Activator.PLUGIN_ID)    {
         public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) {
         searchSubMenu = new MenuManager("Sea&rch", "mymenu");
	 CommandContributionItemParameter itemParam = 
            new CommandContributionItemParameter(serviceLocator, "",", 
         CommandContributionItem item =	new CommandContributionItem(itemParam);
	 additions.addContributionItem(searchSubMenu, null);

    public void dispose() {
    	 * MenuManagers are not disposed, so dispose it.
    	 * See
    	if (searchSubMenu != null) {
    		searchSubMenu = null;

        if (fileMenu != null) {
    		fileMenu = null;
} // end ApplicationActionBarAdvisor

This is my understanding so far (I would really appreciate feedback on where I go wrong):

- The IMenuService from the workbench allows me to add contribution manager factories (e.g., AbstractContributionFactory, ExtensionContributionFactory). These factories are then managed by the MenuService via their id (not sure about this, but in the above example it would be Activator.PLUGIN_ID).

- Within the ContributionFactory.createContributionItems(IServiceLocator, IContributionRoot) is where I add all the sub-menus, commands, etc, within the location-URI of the ContributionFactory.

- The IMenuManager passed to protected void fillMenuBar(IMenuManager menuBar) is reponsible for managing any ContibutionItems that are added.

When I create a AbstractContributionFactory and add contributions as I did above, is this the same thing as if I were to add the extension org.eclipse.ui.menus to the plugin.xml and add menus, etc to?

I'm still don't fully understand how the MenuManger, MenuService, ContributionFactories interact and work.

I would really appreciate feedback.

Previous Topic:New XML Editor
Next Topic:Several questions from a novice.
Goto Forum:

Current Time: Sun Jun 20 05:01:01 GMT 2021

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

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

Back to the top