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
/**
     * Creates and returns an SWT menu bar control for this menu,
     * for use in the given <code>Decorations</code>, and installs all registered
     * contributions. Does not create a new control if one already exists.
     *
     * @param parent the parent decorations
     * @return the menu control
     * @since 2.1
     */
    public Menu createMenuBar(Decorations parent) {
        if (!menuExist()) {
            menu = new Menu(parent, SWT.BAR);
            update(false);
        }
        return menu;
    }
    /**
     * Creates and returns an SWT menu bar control for this menu, for use in the
     * given <code>Shell</code>, and installs all registered contributions. Does not
     * create a new control if one already exists. This implementation simply calls
     * the <code>createMenuBar(Decorations)</code> method
     *
     * @param parent the parent decorations
     * @return the menu control
     * @deprecated use <code>createMenuBar(Decorations)</code> instead.
     */
    public Menu createMenuBar(Shell parent) {
        return createMenuBar((Decorations) parent);
    }
    /**