Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Action into Submenu Context Menu Java JFace SWT Eclipse

I'm having a slight problem with an Eclipse Plug-In in development.

There is a view which is comparabe to a roster. There is a list of users in there. My problem is, that I'd like to add an context menu.
The idea is to perform a right-click on a user and the menu should pop up. So far so good... but the problem is that I don't want a single menu. I'd like to have an entry "set status" to that context menu and when one hovers over this entry the menu should be extended to show stuff like "away" "busy" "invisible" and so on...
Could anyone help me out to achieve this?

I have already implemented the corresponding action and made the addition to the MenuManager.

public SessionViewContextMenu(ViewPart sessionView, TableViewer viewer,
    final Action action) {

    MenuManager manager = new MenuManager("#PopupMenu");

    manager.setRemoveAllWhenShown(true);
    manager.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            manager.add(action);
        }
    });

The correspodning action looks like this:

public Action(...) {

    super(provider, "Bla Bla");

    // some fancy picture
    setImageDescriptor(...);

    // setId(ACTION_ID);

    setToolTipText("Bla Bla");

    update();
}

Everything is working fine (at least the context menu shows the entry). Now I'd like to extend the menu when one hovers over / selects the corresponding action. So the menu should extend and show some more possibilites here...
Any help on how to create a recursive context menu is highly appreciated!

Hope, you understand the problem and don't hesitate to ask dor clarification!

like image 489
user445218 Avatar asked Sep 11 '10 18:09

user445218


1 Answers

Just create a sub-menu and add the actions to this sub-menu.
Here is a quick snippet which should clarify the usage:

            // submenu for a specific user
            MenuManager subMenu = new MenuManager("Change Status", null);

            // Actions for the sub menu
            subMenu.add(someAction);

            // add the action to the submenu
            manager.add(subMenu);

Hope that helps!

Put together:

public SessionViewContextMenu(ViewPart sessionView, TableViewer viewer,
final Action action) {

MenuManager manager = new MenuManager("#PopupMenu");

manager.setRemoveAllWhenShown(true);
manager.addMenuListener(new IMenuListener() {

    public void menuAboutToShow(IMenuManager manager) {
        manager.add(action);

        // submenu for a specific user
        MenuManager subMenu = new MenuManager("Change Status", null);

        // Actions for the sub menu
        subMenu.add(someAction);

        // add the action to the submenu
        manager.add(subMenu);
    }
});
like image 163
Gnark Avatar answered Nov 14 '22 23:11

Gnark