Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Binding checkbutton to text enabled property(Problem trying to bind a checkbutton to the 'enabled' property of a text widget)
Binding checkbutton to text enabled property [message #688386] Fri, 24 June 2011 15:39 Go to next message
Gianni Paglia is currently offline Gianni Paglia
Messages: 3
Registered: May 2011
Junior Member
Hello,

I have the following use case:
- a checkbutton widget (btnButton in the source file)
- a text widget (txtText)

I am trying to have the checkbutton control the 'enabled' property of the text widget,
i.e. when the button is checked the text is enabled and viceversa.

I bind the two properties with the following code:

protected DataBindingContext initDataBindings() {
DataBindingContext bindingContext = new DataBindingContext();
//
IObservableValue btnButtonObserveSelectionObserveWidget =
SWTObservables.observeSelection(btnButton);
IObservableValue txtTextObserveEnabledObserveWidget =
SWTObservables.observeEnabled(txtText);
bindingContext.bindValue(btnButtonObserveSelectionObserveWidget,
txtTextObserveEnabledObserveWidget, null, null);
//
return bindingContext;
}

This works OK when the checkbutton is checked on the UI, and the text widget is enabled or disabled accordingly.

But when I change the status of the checkbutton programmatically, using btnButton.setSelection(), the change is reflected on the gui but is ignored by the binding, and the text widget is not enabled/disabled accordingly.

I attach a simple program that has two menu actions, called Enable adn Disable, which set programmatically the selection of the checkbutton, and demonstrates this behaviour.

Is there something I am missing in the way this widget-to-widget binding should work, or is by design or is it a bug?

Any help is greatly appreciated,

regards,

Gianni

Re: Binding checkbutton to text enabled property [message #688407 is a reply to message #688386] Fri, 24 June 2011 16:13 Go to previous message
Gianni Paglia is currently offline Gianni Paglia
Messages: 3
Registered: May 2011
Junior Member
Hello,

in effect I found that, when the setSelection() is called on the checkbutton, the change listeners are not triggered.

Here's the additional code I used:

protected DataBindingContext initDataBindings() {
DataBindingContext bindingContext = new DataBindingContext();
//
IObservableValue btnButtonObserveSelectionObserveWidget =
SWTObservables.observeSelection(btnButton);
IObservableValue txtTextObserveEnabledObserveWidget =
SWTObservables.observeEnabled(txtText);
bindingContext.bindValue(btnButtonObserveSelectionObserveWidget,
txtTextObserveEnabledObserveWidget, null, null);
IObservableValue btnButtonObserveSelectionObserveWidget2 =
SWTObservables.observeSelection(btnButton);
btnButtonObserveSelectionObserveWidget2.addChangeListener(new IChangeListener() {
@Override
public void handleChange(ChangeEvent event) {
// TODO Auto-generated method stub
System.err.println("Event: " + event.toString());
}
});
//
return bindingContext;
}
Previous Topic:observeImage
Next Topic:Databinging - Writable and the opposite path.
Goto Forum:
  


Current Time: Sat Sep 20 02:14:37 GMT 2014

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

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