2

I'm using data binding for synchronizing b/w two button. If one is enable then other should be disable or vise-versa. In my code at starting time it works fine but when I'm changing button2 to disable other is not changing to enable.

Question: What I'm missing here.?

Button button1 = new Button(parent, SWT.NONE);
button1.setText("hello");
final Button button2 = new Button(parent, SWT.NONE);
button2.addSelectionListener(new SelectionAdapter() {
    @Override
    public void widgetSelected(SelectionEvent e) {
         button2.setEnabled(false);
    }
});
button2.setText("world");
ISWTObservableValue observeEnabledButton1 = SWTObservables.observeEnabled(button1);
ISWTObservableValue observeEnabledButton2 = SWTObservables.observeEnabled(button2);
UpdateValueStrategy updateValueStrategy = new UpdateValueStrategy();
updateValueStrategy.setConverter(new IConverter() {
@Override
public Object getToType() {
    return Boolean.TYPE;
}
   @Override
public Object getFromType() {
    return Boolean.TYPE;
}
@Override
    public Object convert(Object fromObject) {
    if (fromObject instanceof Boolean) {
   // return inverse to disable the other button
        return ((Boolean) fromObject).booleanValue() ? Boolean.FALSE : Boolean.TRUE;
        }
  return Boolean.FALSE;
}
});
dbc.bindValue(observeEnabledButton1, observeEnabledButton2, updateValueStrategy, updateValueStrategy);

Thanks

Sumit Singh
  • 15,743
  • 6
  • 59
  • 89
  • In the widgetSelected method, don't you want to add a button1.setEnabled(true)? Or am I misunderstanding your problem? – nbz Oct 07 '13 at 14:52

0 Answers0