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
/* (non-Javadoc)
     * @see org.eclipse.jface.action.IContributionItem#setVisible(boolean)
     */
    public void setVisible(boolean visible) {
        this.visible = visible;
    }
    /* (non-Javadoc)
     * @see org.eclipse.jface.action.IContributionItem#update()
     */
    public void update() {
        updateMenuItem();
    }
    /**
     * The <code>MenuManager</code> implementation of this <code>IContributionManager</code>
     * updates this menu, but not any of its submenus.
     *
     * @see #updateAll
     */
    public void update(boolean force) {
        update(force, false);
    }
    /**
     * Incrementally builds the menu from the contribution items.
     * This method leaves out double separators and separators in the first 
     * or last position.
     *
     * @param force <code>true</code> means update even if not dirty,
     *   and <code>false</code> for normal incremental updating
     * @param recursive <code>true</code> means recursively update 
     *   all submenus, and <code>false</code> means just this menu