Bug 149890 [Contributions] MenuManager does not properly handle dynamic submenus
3.2 RC5 I tried adding a dynamic MenuManager as a submenu of the parent MenuManager. By dynamic, I mean that I used subMenu.setRemoveAllWhenShown(true), and a menu listener on the submenu to populate it when shown. When the context menu was shown, it had no entry for the submenu. This is because MenuManager.isVisible() returns false if the menu has generated no concrete menu items (after update). If isVisible is fixed to return true if removeAllWhenShown is true, then a secondary problem occurs: the label for the submenu appears disabled, until clicked on to show the submenu. Suggested fix: In MenuManager.isVisible(), add the following before checking the items: if (removeAllWhenShown) return true; In MenuManager.updateMenuItem(), change: boolean enabled = menu.getItemCount() > 0; to: boolean enabled = removeAllWhenShown || menu.getItemCount() > 0;
bundles/org.eclipse.jface/src/org/eclipse/jface/action/MenuManager.java
*/
    public MenuManager(String text, ImageDescriptor image, String id) {
        this.menuText = text;
        this.image = image;
        this.id = id;
    }
    /* (non-Javadoc)
     * @see org.eclipse.jface.action.IMenuManager#addMenuListener(org.eclipse.jface.action.IMenuListener)
     */
    public void addMenuListener(IMenuListener listener) {
        listeners.add(listener);
    }
    /**
     * Creates and returns an SWT context menu control for this menu,
     * and installs all registered contributions.
     * Does not create a new control if one already exists.
     * <p>
     * Note that the menu is not expected to be dynamic.
     * </p>
     *
     * @param parent the parent control
     * @return the menu control
     */
    public Menu createContextMenu(Control parent) {
        if (!menuExist()) {
            menu = new Menu(parent);
            initializeMenu();
        }
        return menu;
    }