Search code examples
javaeclipseeclipse-rcpjfacercp

Create Eclipse context sub-menus responsively


I'm familiar with creating Eclipse menus.

I wish to offer the user a very deep & broad set of menu actions. Creation of these context-sensitive actions takes an amount of processing time. I do not wish to generate all of them at once. I wish to generate them as the user progressively navigates deeper through the menu structure. So, for example, if a menu tier contains days of the week, and the user selects "Monday", I will then offer "AM" or "PM", then a list of two-hour periods (1200-1400, 1400-1600, 1600-1800, etc) , then finally "Create appointment", "Register as available" and "Register as unavailable". The final set of actions may incur a database round-trip to determine availability.

Clearly, the alternative to this strategy is to generate a menu tree as required with many, many actions (and many database round-trips)

[that's not the actual set of actions, it's [hopefully] and easy to understand example].

I can't find an Eclipse API that lets me create Menu/Sub-menu actions progressively as the user navigates down through the menu tree.

Can anybody point me to it?


Solution

  • If you have a MenuManager you can add a IMenuListener to the manager, this has a

    public void menuAboutToShow(IMenuManager manager)
    

    method where you can use manager.add(xxx) to add menu items to the menu when it just about to be shown. Use additional menu managers as children of the main manager for sub menus.

    You may also need to call MenuManager.setRemoveAllWhenShown(true) to tell the menu manager to start from an empty menu before calling menuAboutToShow.