Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » using command handlers to enable/disable push buttons
using command handlers to enable/disable push buttons [message #332158] Tue, 07 October 2008 17:35 Go to next message
Eric Geordi is currently offline Eric GeordiFriend
Messages: 3
Registered: July 2009
Junior Member
Hi,

I am a beginner at using the commands and commands expressions framework.
It seems pretty straightforward to setup handlers to enable/disable
buttons on the toolbar using the extensions. However, how would I go about
enabling/disabling regular SWT push buttons? Is there some way to access
the handler I've declared in the extension point programmatically and
evaluate the handler's expression? Or can it even be done through
extension points ?

Thanks,
Eric
Re: using command handlers to enable/disable push buttons [message #332171 is a reply to message #332158] Wed, 08 October 2008 12:20 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

You would like to create SWT Buttons (instead of menu items or tool items)?

If that's the case, you can create a CommandContributionItem yourself
and call cci.fill(parentComposite)

That will create a button and hook it up so it calls the command when
pushed. It should also keep the button enabled state up to date,
although that might need a little help from a ContributionManager. Try
it out with the cci.fill(*) and see if that helps.

If that's not what you were after, is there some other way you could
describe it?

PW


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


Re: using command handlers to enable/disable push buttons [message #332175 is a reply to message #332171] Wed, 08 October 2008 12:43 Go to previous messageGo to next message
Eric Geordi is currently offline Eric GeordiFriend
Messages: 3
Registered: July 2009
Junior Member
Paul Webster wrote:

> You would like to create SWT Buttons (instead of menu items or tool items)?

> If that's the case, you can create a CommandContributionItem yourself
> and call cci.fill(parentComposite)

> That will create a button and hook it up so it calls the command when
> pushed. It should also keep the button enabled state up to date,
> although that might need a little help from a ContributionManager. Try
> it out with the cci.fill(*) and see if that helps.

> If that's not what you were after, is there some other way you could
> describe it?

> PW

Currently, I am calling the command from the button by simply finding the
command using the IHandlerService and then executing it. I thought there
might be something similar for accessing the command's handler and tying
the button's enablement state to the handler's expression from the
extension point.

I am not familiar with creating a CommandContributionItem, so I will look
into this. It sounds like this may be what I need to do to tie the SWT
button's enabled state to the handler's expression.

Thanks!
Eric

Thanks,
Eric
Re: using command handlers to enable/disable push buttons [message #332187 is a reply to message #332175] Thu, 09 October 2008 01:15 Go to previous messageGo to next message
Eric Geordi is currently offline Eric GeordiFriend
Messages: 3
Registered: July 2009
Junior Member
Is there a good tutorial somewhere that explains the
CommandContributionItem and how to create a custom one?

Thanks,
Eric
Re: using command handlers to enable/disable push buttons [message #332188 is a reply to message #332187] Thu, 09 October 2008 02:21 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Eric Geordi wrote:
> Is there a good tutorial somewhere that explains the
> CommandContributionItem and how to create a custom one?

There isn't that much to it. Say I was in a view:

CommandContributionItemParameter parms
= new CommandContributionItemParameter(getSite(),
"org.eclipse.ui.file.refresh", "org.eclipse.ui.file.refresh",
CommandContributionItem.STYLE_PUSH)
CommandContributionItem cci = new CommandContributionItem(parms);

In a workbench window, you would use the IWorkbenchWindow as your
service locator, in a dialog you would probably just use the workbench
itself.

There are more fields available in the CommandContributionItemParameter
that allow you to provide specific menu/tool item attributes if they are
not already provided by the command definition.

PW

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


Previous Topic:Is there an event for generating getters/setters?
Next Topic:(ganymede) Differenting "SDK" from "Platform SDK" in Software Update dialog
Goto Forum:
  


Current Time: Wed Jul 17 10:41:39 GMT 2024

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

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

Back to the top