Widget enable event [message #514533] |
Mon, 15 February 2010 17:21 |
antonio Messages: 22 Registered: July 2009 |
Junior Member |
|
|
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.
Thanks,
Julio
|
|
|
Re: Widget enable event [message #514630 is a reply to message #514533] |
Tue, 16 February 2010 06:31 |
Vijay Raj Messages: 608 Registered: July 2009 |
Senior Member |
|
|
setEnabled method is in Control class...
And enabling and disabling in most cases will only be done programmatically,
Hence where ever you do enable or disable you can also notify about the same to somebody or something...
Whats your actual requirement??
---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
|
|
|
Re: Widget enable event [message #514632 is a reply to message #514630] |
Tue, 16 February 2010 06:39 |
Vijay Raj Messages: 608 Registered: July 2009 |
Senior Member |
|
|
I think SWT.Deactivate...
is the listener you are looking for...
---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
|
|
|
|
Re: Widget enable event [message #514694 is a reply to message #514679] |
Tue, 16 February 2010 11:26 |
Vijay Raj Messages: 608 Registered: July 2009 |
Senior Member |
|
|
Why can not you do the task where ever you are desabling the control....
why to desable/enable it and then listen for the same and do your task???
---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
|
|
|
|
Re: Widget enable event [message #514762 is a reply to message #514712] |
Tue, 16 February 2010 14:59 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
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.03731 seconds