/**
  * Recursive method to create a menu from the contribute items of a manger
  *
  * @param menu actual menu
  * @param items manager contributor items
  */
 private void createMenu(Menu menu, IContributionItem[] items) {
   for (IContributionItem item : items) {
     if (item instanceof MenuManager) {
       MenuManager manager = (MenuManager) item;
       MenuItem subMenuItem = new MenuItem(menu, SWT.CASCADE);
       subMenuItem.setText(manager.getMenuText());
       Menu subMenu = new Menu(Display.getCurrent().getActiveShell(), SWT.DROP_DOWN);
       subMenuItem.setMenu(subMenu);
       createMenu(subMenu, manager.getItems());
     } else if (item instanceof ActionContributionItem) {
       ActionContributionItem actionItem = (ActionContributionItem) item;
       if (actionItem.getAction() instanceof CustomSelectionAction) {
         final CustomSelectionAction action = (CustomSelectionAction) actionItem.getAction();
         MenuItem actionEnrty = new MenuItem(menu, SWT.CHECK);
         action.setSelection(getLastRawSelection());
         actionEnrty.setText(actionItem.getAction().getText());
         actionEnrty.setSelection(action.isChecked());
         actionEnrty.setEnabled(action.canExecute());
         actionEnrty.addSelectionListener(
             new SelectionAdapter() {
               @Override
               public void widgetSelected(SelectionEvent e) {
                 action.run();
               }
             });
       }
     }
   }
 }
 /**
  * Creates a top-level menu and adds it to the Riena menu bar.
  *
  * @param menuManager
  * @param listener
  */
 private ToolItem createAndAddMenu(
     final MenuManager menuManager, final ToolBarMenuListener listener) {
   if (menuManager.isVisible()) {
     final ToolItem toolItem = new ToolItem(menuToolBar, SWT.CHECK);
     toolItem.setText(menuManager.getMenuText());
     final MenuManagerHelper helper = new MenuManagerHelper();
     final Menu menu = helper.createMenu(menuToolBar, toolItem, menuManager);
     toolItem.setData(MENU_DATA_KEY, menu);
     calcSize(menuCoolItem);
     toolItem.addSelectionListener(listener);
     return toolItem;
   }
   return null;
 }
 @Override
 protected void editorContextMenuAboutToShow(IMenuManager menu) {
   super.editorContextMenuAboutToShow(menu);
   // remove editor actions that don't work in Photon
   menu.remove(ITextEditorActionConstants.CONTEXT_PREFERENCES);
   for (IContributionItem item : menu.getItems()) {
     if (item instanceof MenuManager) {
       MenuManager subMenu = (MenuManager) item;
       // Warning: this is a best effort since the menu doesn't have an
       // id
       if (subMenu.getMenuText().startsWith("Sho&w In")) { // $NON-NLS-1$
         menu.remove(subMenu);
       }
     }
   }
 }
 /**
  * This removes from the specified <code>manager</code> all {@link
  * org.eclipse.jface.action.MenuManager}s and their {@link
  * org.eclipse.jface.action.ActionContributionItem}s based on the {@link
  * org.eclipse.jface.action.IAction}s contained in the <code>submenuActions</code> map.
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 protected void depopulateManager(
     IContributionManager manager, Map<String, Collection<IAction>> submenuActions) {
   if (submenuActions != null) {
     IContributionItem[] items = manager.getItems();
     for (int i = 0; i < items.length; i++) {
       IContributionItem contributionItem = items[i];
       if (contributionItem instanceof MenuManager) {
         MenuManager submenuManager = (MenuManager) contributionItem;
         if (submenuActions.containsKey(submenuManager.getMenuText())) {
           depopulateManager(submenuManager, submenuActions.get(contributionItem));
           manager.remove(contributionItem);
         }
       }
     }
   }
 }
 private void makeEntry(final IContributionItem item) {
   IContributionItem tempItem = null;
   if (item instanceof SubContributionItem) {
     SubContributionItem subItem = (SubContributionItem) item;
     tempItem = subItem.getInnerItem();
   } else if (item instanceof MenuManager) {
     tempItem = item;
   }
   if (tempItem != null && tempItem instanceof MenuManager) {
     final MenuManager manager = (MenuManager) tempItem;
     int style = extractStyle(manager);
     final ToolItem toolItem = new ToolItem(toolbar, style);
     toolItem.setText(manager.getMenuText());
     toolItem.setData(WidgetUtil.CUSTOM_VARIANT, MENU_BAR_VARIANT);
     createMenu(manager, toolItem);
     // needed to clear all controls in case of an update
     toolItemList.add(toolItem);
   }
 }