Disable plugin contributions in Eclipse RCP Application

Take a look at the Eclipse "Activities" API. It allows you to hide contributions based on ID.

A few links:

  • http://wiki.eclipse.org/FAQ_How_do_I_add_activities_to_my_plug-in%3F
  • http://blog.vogella.com/2009/07/13/eclipse-activities/
  • http://random-eclipse-tips.blogspot.com/2009/02/eclipse-rcp-removing-unwanted_02.html
  • http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/workbench_scalability.htm

The only method which comes close to do that would be:

IMenuService::removeContributionFactory()

Paul Webster has been calling for a IMenuService::addOverride() to change the visibility of the menu, preventing any contribution, but that idea has not been integrated yet.

You can see an example of removing a contribution in this org.eclipse.ui.tests.menus.MenuBuilder class;

public static void removeMenuContribution() {
    if (!PlatformUI.isWorkbenchRunning()) {
        return;
    }
    IMenuService menuService = (IMenuService) PlatformUI.getWorkbench()
            .getService(IMenuService.class);
    if (menuService==null) {
        return;
    }
    menuService.removeContributionFactory(viewMenuAddition);
    viewMenuAddition = null;
    menuService.removeContributionFactory(viewToolbarAddition);
    viewMenuAddition = null;
}