|
Re: How to show a MessageDialog in a web browser when an event occoured in the backround thread [message #43666 is a reply to message #43635] |
Wed, 29 August 2007 07:16   |
Eclipse User |
|
|
|
Originally posted by: fappel.innoopract.com
Hi,
as your #onMessage(Message) callback is called from a background and not a
UI thread, Display#getCurrent() doesn't find a display (will return null in
future, not throwing the illegal state exception). This difference to RCP
comes from the distributed nature of the server environment and therefore
that we have to deal with different scopes (request, session, application).
In RCP there is only one implicit scope (session), so that you normally
always get access to the display. With RAP you'll have to ensure that the
display that represents the session of interest in the callback is
available. You can do this by assigning a field with the display in
#createPartControl(Composite) and use this reference in your callback method
for the #syncExex(Runnable) call.
By the way, you should take care that you always use a unique id for
UICallBack#activate(String) as they are used to determine whether the
UICallBack control can be deactiveated or not. In your snippet the same id
is used by different ViewPart instances.
Hope that helps.
Ciao
Frank
"toolang" <toolang@gmail.com> schrieb im Newsbeitrag
news:fb2rsg$3rr$1@build.eclipse.org...
>I implements JMS MessageListener in a ViewPart
>
> public class DemoBrowserViewPart extends ViewPart implements
> MessageListener {
> ......
> public void createPartControl(final Composite parent) {
> ......
> hookEventListener();
> UICallBack.activate(DemoBrowserViewPart.class.getName());
> }
>
> private void hookEventListener() {
> String topicName = "RAP_EVENT";
> String selector = "MSG_SEL=STATUS";
>
> TopicSubscriber subscriber;
> TopicSession topicSession = EventManager.getInstance()
> .getTopicSession();
> try {
> Topic topic = topicSession.createTopic(topicName);
> subscriber = topicSession.createSubscriber(topic, selector, false);
> subscriber.setMessageListener(this);
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
> private Object oMsg = null;
>
> @Override
> public void onMessage(Message msg) {
> try {
> if (msg instanceof ObjectMessage) {
> oMsg = ((ObjectMessage) msg).getObject();
> if (oMsg instanceof String) {
> Display.getCurrent().syncExec(new Runnable() {
> public void run() {
> MessageDialog.openInformation(PlatformUI
> .getWorkbench().getActiveWorkbenchWindow()
> .getShell(), "
|
|
|
|
Powered by
FUDForum. Page generated in 0.01753 seconds