Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Programmatically add Buttons to Toolbar during runtime
Programmatically add Buttons to Toolbar during runtime [message #646194] Wed, 22 December 2010 10:53 Go to next message
Hauke Fuhrmann is currently offline Hauke Fuhrmann
Messages: 322
Registered: July 2009
Senior Member
Dear RCP folks,

I try to add Buttons programmatically during runtime to the Toolbar. Is
there a common way to do this? I cannot do it statically by giving
menuContributions in the plugin.xml.

My first try:

Added a "dynamic" menuContribution in my plugin.xml and implemented a
ContributionItem. I first tried to use CompoundContributionItem, but
this seems only to support menus and no toolbars.
Hence, I subclassed CompoundContributionItem and implemented
fill(ToolBarManager) instead of fill(MenuManager).
Is this a right way to do it?

Still I need to create the required CommandContributionItem objects.
However, I don't know how to create the corresponding Command
programmatically. API says I should use the CommandManager to
instantiate a Command. How do I get that manager?

Cheers,
Hauke
Re: Programmatically add Buttons to Toolbar during runtime [message #647171 is a reply to message #646194] Tue, 04 January 2011 15:18 Go to previous message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

On 12/22/2010 10:53 AM, Hauke Fuhrmann wrote:
> Hence, I subclassed CompoundContributionItem and implemented
> fill(ToolBarManager) instead of fill(MenuManager).
> Is this a right way to do it?

There might be layout problems with this approach. I also don't believe
the framework will try and re-create your dynamic item except at random
toolbarmanager updates. With Menus they can be updated on an SWT.Show
event, which is why CompoundContributionItem only applies to Menus.

>
> Still I need to create the required CommandContributionItem objects.
> However, I don't know how to create the corresponding Command
> programmatically. API says I should use the CommandManager to
> instantiate a Command. How do I get that manager?


You can generate CommandContributionItemParameters and CCIs just as
easily in your ContributionItem ... but what do you mean, generate
commands. You really don't know what commands you support until you
read a config file?

They can still be defined via:
org.eclipse.ui.commands.ICommandService.getCommand(String) but it's
generally not a good idea ... where are you going to activate a handler
for that command?

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Previous Topic:What is difference between parameters defined for Commands and Menu Contribs
Next Topic:ConfigurationScope is not working
Goto Forum:
  


Current Time: Tue Jul 29 12:59:03 EDT 2014

Powered by FUDForum. Page generated in 0.02094 seconds