Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How to add a menu to a toolbar
How to add a menu to a toolbar [message #437937] Fri, 07 October 2005 20:23 Go to next message
Eclipse UserFriend
Originally posted by: hombre67.gmx.at

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
Re: How to add a menu to a toolbar [message #437975 is a reply to message #437937] Mon, 10 October 2005 06:40 Go to previous message
Reinhard Moser is currently offline Reinhard MoserFriend
Messages: 43
Registered: July 2009
Member
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
Previous Topic:Can I have two menu in a workbench?
Next Topic:how to Deploy RCP through JWS
Goto Forum:
  


Current Time: Mon Dec 09 04:11:46 GMT 2024

Powered by FUDForum. Page generated in 0.02280 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top