Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Re: How to show a MessageDialog in a web browser when an event occoured in the backround thread
Re: How to show a MessageDialog in a web browser when an event occoured in the backround thread [message #43635] Wed, 29 August 2007 04:15 Go to next message
No real name is currently offline No real nameFriend
Messages: 9
Registered: July 2009
Junior Member
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(), "
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 Go to previous messageGo to next message
Eclipse UserFriend
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(), "
Re: How to show a MessageDialog in a web browser when an event occoured in the backround thread [message #43808 is a reply to message #43666] Wed, 29 August 2007 08:00 Go to previous message
No real name is currently offline No real nameFriend
Messages: 9
Registered: July 2009
Junior Member
Thanks for your help. I get the display in #createPartControl(Composite) and
it works fine.

Thanks in advance

"Frank Appel" <fappel@innoopract.com> д
Previous Topic:Problem with Label.setText() and StackLayout
Next Topic:Installation problem
Goto Forum:
  


Current Time: Tue Apr 23 16:15:34 GMT 2024

Powered by FUDForum. Page generated in 0.03520 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top