Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » how bind commands to buttons with enabled state
how bind commands to buttons with enabled state [message #645894] Tue, 21 December 2010 00:59 Go to next message
Thomas F is currently offline Thomas FFriend
Messages: 7
Registered: December 2010
Junior Member
Hi,

I've got the issue to add buttons in views - not just in toolbars, but e.g. next to input fields... Those buttons might be enabled if any input is given or not... In traditional programming I would enable/disable the buttons out of listeners of other fields. Currently I use properties like "isMyButtonEnabled" which return the value via getIsMyButtonEnabled(). If I do any changes I fire a prop change and the binding of button.enabled to this property does the update automatically. The action listeners of button perform the exectuable. Not fairly nice but works.

Nevertheless there is RCP and a framework with commands. I found how to execute commands out of buttons. BUT how to bind the enabled or visible state of a button to the command handler. For toolbar contributions e.g. the button becomes disabled if the handler is deactivated (activeWhen) or invisible (visibleWhen). How can I do this with traditional SWT buttons? And maybe how can I do this using WindowBuilder ?

Thx

Thomas
Re: how bind commands to buttons with enabled state [message #645905 is a reply to message #645894] Tue, 21 December 2010 06:23 Go to previous messageGo to next message
Prakash G.R. is currently offline Prakash G.R.Friend
Messages: 621
Registered: July 2009
Senior Member
On 21/12/10 6:29 AM, Thomas F wrote:
> I've got the issue to add buttons in views - not just in toolbars, but
> e.g. next to input fields... Those buttons might be enabled if any input
> is given or not... In traditional programming I would enable/disable the
> buttons out of listeners of other fields. Currently I use properties
> like "isMyButtonEnabled" which return the value via
> getIsMyButtonEnabled(). If I do any changes I fire a prop change and the
> binding of button.enabled to this property does the update
> automatically. The action listeners of button perform the exectuable.
> Not fairly nice but works.
>
> Nevertheless there is RCP and a framework with commands. I found how to
> execute commands out of buttons. BUT how to bind the enabled or visible
> state of a button to the command handler. For toolbar contributions e.g.
> the button becomes disabled if the handler is deactivated (activeWhen)
> or invisible (visibleWhen). How can I do this with traditional SWT
> buttons? And maybe how can I do this using WindowBuilder ?


You can use property testers/contexts in the visibleWhen & enabledWhen
elements in the plugin.xml and then update the visibility/enablement of
a contribution.

Commands are more of a metadata. They suit well when you need to
abstract the actual work from the representation (think of Copy/Paste
and how the implementations will be differ in various views & editor,
yet its presented as the same operation to the user) If you all need is
a button to be visible and enabled in a view/form, then you could
consider doing it without commands.

--
- Prakash
Platform UI Team, IBM

www.eclipse-tips.com
Re: how bind commands to buttons with enabled state [message #645990 is a reply to message #645894] Tue, 21 December 2010 13:45 Go to previous message
Davy Meers is currently offline Davy MeersFriend
Messages: 2
Registered: December 2010
Junior Member
As Prakash stated, there is no need to use commands.

The jface databinding framework is better suited for what you want to achieve.

Have a look at the jface data binding framework.

The following tutorial might give you a head start:

http://community.jboss.org/wiki/Eclipsewizardswithjfacedatab indinginDeltacloudTools1
Previous Topic:Intercepting the ProjectExplorer's Open action
Next Topic:Enable and disable Command Menu item programmatically
Goto Forum:
  


Current Time: Thu Dec 18 18:29:36 GMT 2014

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

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