tags:

views:

38

answers:

2

I'm working on an EclipsePluginProject. I don't have much(nearly nothing) experience with UIs under java. I added a View Option Menu and some actions following this post.

IMenuManager dropDownMenu = getViewSite().getActionBars().getMenuManager();
dropDownMenu.add(new Action("Action1") {
    @Override
    public void run() {
        //do something
    }});
dropDownMenu.add(new Action("Action2") {
    @Override
    public void run() {
        //do something
    }});

This works great and gives me the following menu:

-Action1
-Action2

How do i build a submenu which looks like this?

-Action > -1
          -2
+1  A: 

You can add menus to other menus:

IMenuManager rootMenu = getViewSite().getActionBars().getMenuManager();
MenuManager menu = new MenuManager("Menu &2", "2");
menu.add(new Action("Action1") {
    @Override
    public void run() {
        //do something
    }});
menu.add(new Action("Action2") {
    @Override
    public void run() {
        //do something
    }});
rootMenu.add(menu);
GaryF
pretty easy ... Thanks
Marcel Benthin
A: 

You have to create a new MenuManager...

IMenuManager dropDownMenu = new MenuManager( "Some text", "id" );

... add it to your menu ...

menuManager.appendToGroup( "yourSection", dropDownMenu );

... and add your actions to your new subMenu:

dropDownMenu.add(new Action("Action1") {
@Override
public void run() {
    //do something
}});
dropDownMenu.add(new Action("Action2") {
@Override
public void run() {
    //do something
}});
Mario Marinato -br-