Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » SWT Button as a command
SWT Button as a command [message #892452] Thu, 28 June 2012 09:38 Go to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Hi,

is it possible to have a button that represents a command? Like in the menu or toolbar?
I mean it should have an active handler and would be enabled when the handler is enabled, all contributed declarativelly like normal command menu contribution.
Re: SWT Button as a command [message #892475 is a reply to message #892452] Thu, 28 June 2012 11:34 Go to previous messageGo to next message
Simon Scholz is currently offline Simon ScholzFriend
Messages: 73
Registered: April 2012
Location: Germany
Member
Hi Jan,

How to execute a command programmatically can be found here:
wiki.eclipse.org/Platform_Command_Framework#Executing_a_command_with_parameters

But by just invoking the command in i.e. a SelectionListener of the Button you would have manage the active and enabled state yourself.

The easiest solution for that is to use a Toolbarmanager, which is populated by the IMenuService :

IMenuService menuService = (IMenuService) PlatformUI.getWorkbench()
                .getActiveWorkbenchWindow().getService(IMenuService.class);

ToolBar toolbar = new ToolBar(composite, SWT.NONE);

ToolBarManager tBManager = new ToolBarManager(toolbar);

menuService.populateContributionManager(tBManager,":::locationURI of your menuContribution:::");

tBManager.update(true);


Best regards,

Simon

[Updated on: Thu, 28 June 2012 11:36]

Report message to a moderator

Re: SWT Button as a command [message #892493 is a reply to message #892475] Thu, 28 June 2012 12:52 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Hi Simon,

thanks for your reply.

The code you have posted means, that I can contribute commands to the created ToolBar, right?
And the ToolItems will be updated automatically when the active handler for that commands change?
Re: SWT Button as a command [message #892497 is a reply to message #892452] Thu, 28 June 2012 13:10 Go to previous messageGo to next message
Simon Scholz is currently offline Simon ScholzFriend
Messages: 73
Registered: April 2012
Location: Germany
Member
Hi Jan,

this is correct Smile

But please consider the update mechanism of the Command Contributions in a toolbar for which yuta kobayashi asked in the following post last friday...
www.eclipse.org/forums/index.php/t/365261/
In this post I described how to request an update concerning the state of the Contributions in a toolbar.

Best regards,

Simon
Re: SWT Button as a command [message #892499 is a reply to message #892497] Thu, 28 June 2012 13:16 Go to previous message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Yes, I have looked at this. Thanks again.
Previous Topic:Install/Update
Next Topic:How to update view Secondary Id
Goto Forum:
  


Current Time: Sat Nov 09 02:55:08 GMT 2024

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

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

Back to the top