Custom event listeners in views [message #541734] |
Tue, 22 June 2010 07:26  |
Eclipse User |
|
|
|
Hi,
currently I am being thrown into the development of a RAP Application
while I have no experience with RCP/RAP. Instead I was doing Swing
development before.
Now my task is writing an event-listener/-handler which receives events
from a non-GUI component. Now Gui-components (views) should be notified
if events occcur.
In swing I would start doing something like this:
public class EventListeningComponent extends Component {
public void handleEvent(String event) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JOptionPane.showMessageDialog(event);
}
}
}
}
Of course this is oversimplified, but I hope you get the point: Handling
non-gui-events within the gui and in the right context
(EventDispatchThread).
Could somebody please give m some advice on best practices to do
something like this in RAP.
How does the event-system work in RAP? Is there something like an
EventDispatchThread? How is the component in the browser notified, if a
java-event occurs?
Regards,
Philipp
|
|
|
Re: Custom event listeners in views [message #541830 is a reply to message #541734] |
Tue, 22 June 2010 12:26  |
Eclipse User |
|
|
|
Hi Philipp,
There are various web resources to help get you started:
Just search for : SWT tutorial
Also, the RAP FAQ:
http://wiki.eclipse.org/RAP/FAQ
is very useful and has many helpful examples.
But in reference to your specific task:
public class EventListener {
Display display;
public void handleEvent(String event) {
if (display != null)
display.asyncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(null, "Message", event);
}
}
}
public void setDisplay (Display disp) {
display = disp;
}
}
will get you started... First you need a reference to the display. You can obtain that from any widget that you have a reference to.... or from the workbench.... or from Display.getCurrent() if you are already in the "ui" thread.
With that reference, you can from a "non-ui" thread, queue a runnable to be executed in the display thread using async().
Hope this helps.
|
|
|
Powered by
FUDForum. Page generated in 0.06199 seconds