Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Need reference to Display in RAP app(Needed when running UICallback.runNonUIThreadWithFakeContext())
Need reference to Display in RAP app [message #665751] Fri, 15 April 2011 17:58 Go to next message
Mark Leone is currently offline Mark LeoneFriend
Messages: 123
Registered: July 2009
Senior Member
I understand that when I need to touch UI objects from a non-UI thread, I need to wrap the call in a runnable provided as an argument to UICallBack.runNonUIThreadWithFakeContext().

However, that method also requires a reference to the Display. I can't call the static methods I would in an RCP app (e.g. PlatformUI.getDisplay()) because this call itself would need to be made through UICallBack.

So how do I get a reference to the Display? The only thing I found that works is to create a static accessor to it in my entry point bundle, where the Display is created and then used to create the workbench. But this gives me a dependency on my entry point from my application code, which I don't want. Besides the general opinion that this is a bad design, I can't create the war file with this dependency present. Equinox complains that it's an unsatisfied dependency even though the entry point plug-in is present and has an entry in config.ini.

So is there a way to get a reference to the workbench Display object from any of the user sessions? Is there in fact only one Display created for the application, or does one get created for each user session?
Re: Need reference to Display in RAP app [message #666059 is a reply to message #665751] Mon, 18 April 2011 20:01 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf SternbergFriend
Messages: 1313
Registered: July 2009
Senior Member

Hi,

> I understand that when I need to touch UI objects from a non-UI thread,
> I need to wrap the call in a runnable provided as an argument to
> UICallBack.runNonUIThreadWithFakeContext().

That's not true. If you need to access widgets from any thread that is
not the UI thread of this widget's display, you have to wrap the call in
a runnable and hand it over to Display#asyncExec(). The code will be
executed in the next request.

The method you mentioned is only needed when you have to run non-UI code
in a background thread that requires access to the session context, e.g.
when accessing a session singleton.

If you're accessing a widget, you can always get the reference to the
display by calling Widget#getDisplay() on this widget. You can also get
the display from the workbench by calling IWorkbench#getDisplay().

> So how do I get a reference to the Display? The only thing I found that
> works is to create a static accessor to it in my entry point bundle,
> where the Display is created and then used to create the workbench.

Beware! Every user session has its own display. So if you want to serve
more than a single user with your application, you must not keep any
session specific state in a static field.

Does this help?

Regards, Ralf

--
Ralf Sternberg

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Need reference to Display in RAP app [message #666086 is a reply to message #666059] Tue, 19 April 2011 03:51 Go to previous message
Mark Leone is currently offline Mark LeoneFriend
Messages: 123
Registered: July 2009
Senior Member
Thanks for setting me straight on that, Ralf. Display#asycExec() takes care of what I'm doing currently. I can get the Display from the Control I'm working with, but I don't see a way to get a Display from the Workbench. When I tried it, it threw the same IllegalStateException that led me to UICallback in the first place.

I thought I needed a reference to Display in a class that had no references to UI objects. It seemed I was getting an IllegalStateException while calling DeferredTreeContentManager#startFetchingDeferredChildren(). But I just re-ran the code without using UICallback or Display#asyncExec, and it ran fine. So I must have been mistaken about the source of that Exception.

My code is working properly now, without the static reference to Display. But I don't think I can get a reference to a Display in RAP where I don't have a reference to a UI object. And I see now that UICallback is how I would get access to session state.
Previous Topic:Providing a public "JSExecuter" API
Next Topic:SWT.RIGHT_TO_LEFT style
Goto Forum:
  


Current Time: Wed Apr 24 19:16:32 GMT 2024

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

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

Back to the top