|
|
|
|
| Re: How enable and disable buttons using event in SWT. [message #1006653 is a reply to message #1006586] |
Fri, 01 February 2013 05:34   |
sumit singh Messages: 73 Registered: October 2012 Location: Bangalore |
Member |

|
|
Hi Simon,
Sorry for asking you again.
I tried your code, at starting time it works means button1 is disable and button2 is enable. But if i click button2 and its listener am disabling it but other button is still in disable mode . I'm putting my code:
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);
[Updated on: Fri, 01 February 2013 05:34] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.02181 seconds