[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.rcp] Re: How to add a menu to a toolbar

Hi hombre,

i added a drop down box for change the author. First create an action which implements IMenuCreator and extends Action like this:

package at.healthgate.ebmrc.client.actions;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuCreator;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;

public class TestAction extends Action implements IMenuCreator {

  private Menu menu_ = null;

  public void dispose() {
    if ( this.menu_ != null ) {
      this.menu_.dispose();
      this.menu_ = null;
    }
  }

  public Menu getMenu( Control parent ) {
    if ( this.menu_ != null )
      this.menu_.dispose();
    this.menu_ = new Menu( parent );
    // FILL menu with actions
    return this.menu_;
  }

  public Menu getMenu( Menu parent ) {
    return null;
  }

}

Afterwards you add the menu to your coolbar in the ActionBarAdvisor:

protected void fillCoolBar( ICoolBarManager _cool_bar_manager ) {
super.fillCoolBar( _cool_bar_manager );
IToolBarManager tool_bar_manager = new ToolBarManager( _cool_bar_manager.getStyle() );
tool_bar_manager.add( new Separator( "user" ) );
AuthorChangeAction author_change_action = new AuthorChangeAction();
tool_bar_manager.add( author_change_action );
ToolBarContributionItem toolbar_contribution_item = new ToolBarContributionItem(tool_bar_manager );
_cool_bar_manager.add( toolbar_contribution_item );
}


For me this works.

Reinhard

hombre schrieb:
Hi,

I want to add a menu to a toolbar programmatically (like the new-menu near the new-action in the eclipse IDE).
I know that I can add an Action or an ActionContributionItem to an IToolBarManager but I don't know how to add a menu.
Can anybody give me some hints ?


Regards,
Hombre