Binding checkbutton to text enabled property [message #688386] |
Fri, 24 June 2011 11:39  |
Eclipse User |
|
|
|
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 12:13  |
Eclipse User |
|
|
|
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;
}
|
|
|
Powered by
FUDForum. Page generated in 0.02794 seconds