Widget enable event [message #514533] |
Mon, 15 February 2010 12:21  |
Eclipse User |
|
|
|
Hi,
is it possible get event when a widget is enabled/disabled (it becomes "gray" and not clickable):
widget.addListener(SWT.XXX, new Listener() {
public void handleEvent(Event event) {
if (event==YYY) do something();
});
//somewhere...
widget.setEnabled(false);
Eventually I would like to know what are XXX and YYY (for false/true enable) in the code.
|
|
|
|
|
|
|
|
Re: Widget enable event [message #514762 is a reply to message #514712] |
Tue, 16 February 2010 09:59   |
Eclipse User |
|
|
|
SWT does not send notification when a control is enabled/disabled. If you
want the participants to be decoupled then you can use swt's event mechanism
to send events of your own, like in the snippet below. You would define two
new event types (make them large enough to not collide with current or
future swt event types), and every invocation of Control.setEnabled(...)
would be followed by Control.notifyListeners(...).
public static void main(String[] args) {
final int CUSTOM_EVENT_TYPE = 1234567890;
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setBounds(10,10,200,200);
shell.addListener(CUSTOM_EVENT_TYPE, new Listener() {
public void handleEvent(Event event) {
System.out.println("notified!");
}
});
shell.open();
Runnable runnable = new Runnable() {
public void run() {
Event event = new Event();
event.widget = shell;
event.type = CUSTOM_EVENT_TYPE;
shell.notifyListeners(CUSTOM_EVENT_TYPE, event);
display.timerExec(999, this);
}
};
runnable.run();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
HTH,
Grant
"antonio" <antongiulio05@gmail.com> wrote in message
news:hle3e7$evn$1@build.eclipse.org...
> cos it need to do something when is enabled/disabled and to avoid coupling
class
> --
> Thanks,
> Julio
|
|
|
|
Powered by
FUDForum. Page generated in 0.09406 seconds