Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » problem with updating a view
problem with updating a view [message #724843] Tue, 13 September 2011 10:36 Go to next message
Wojtek.wk  is currently offline Wojtek.wk Friend
Messages: 29
Registered: September 2011
Junior Member
Hi, I've got a problem with updating a view in my application in RAP.
As I've found in RAP FAQ, I should do it by activating a call-back mechanism.
In the code of my view I have something like this:
public void myMethod() {
	UICallBack.activate("Change");
	Thread bgThread = new Thread(new Runnable() {
		public void run() {								
			display.asyncExec(new Runnable() {
				public void run() {
					//Update my UI							
				}
			});
					
			display.asyncExec(new Runnable() {
				public void run() {
					UICallBack.deactivate("Change");
				}
			});
		}
	});
	bgThread.setDaemon(true);
	bgThread.start();
}


Now, in the external class (non-UI) I have the code that calls myMethod:
UICallBack.runNonUIThreadWithFakeContext(display, new Runnable(){
	public void run() {
		view.myMethod();
	}
});


(I'm using runNonUIThreadWithFakeContext method, because it is non-UI class.)

Unfortunately, nothing happens... View doesn't change at all...
Can anyone help me, please?

[Updated on: Tue, 13 September 2011 10:58]

Report message to a moderator

Re: problem with updating a view [message #724872 is a reply to message #724843] Tue, 13 September 2011 11:48 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by:

The UI callback must only be activated within a regular request (i.e.
from the UI thread). It looks like you are trying to activate the UI
callback from a background thread.
For more information about the internal workings of the UI callback see
the server push wiki page [1].

HTH
Rüdiger

[1] http://wiki.eclipse.org/RAP/UI_Callback

On 13.09.2011 12:36, Wojtek.wk wrote:
> Hi, I've got a problem with updating a view in my application in RAP.
> As I've found in RAP FAQ, I should do it by activating a call-back
> mechanism.
> In the code of my view I have something like this:
> public void myMethod() {
> UICallBack.activate("Change");
> Thread bgThread = new Thread(new Runnable() {
> public void run() {
> display.asyncExec(new Runnable() {
> public void run() {
> //Update my UI
> }
> });
>
> display.asyncExec(new Runnable() {
> public void run() {
> UICallBack.deactivate("Change");
> }
> });
> }
> });
> bgThread.setDaemon(true);
> bgThread.start();
> }
>
> Now, in the external class (non-UI) I have the code that calls myMethod:
> UICallBack.runNonUIThreadWithFakeContext(display, new Runnable(){
> public void run() {
> view.myMethod();
> }
> });
>
> (I'm using runNonUIThreadWithFakeContext method, because it is non-UI
> class.)
>
> Unfortunately, nothing happens... View doesn't change at all...
> Can anyone help me, please?


--
Rüdiger Herrmann

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

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: problem with updating a view [message #724932 is a reply to message #724872] Tue, 13 September 2011 14:12 Go to previous messageGo to next message
Wojtek.wk  is currently offline Wojtek.wk Friend
Messages: 29
Registered: September 2011
Junior Member
Thank you very much for your reply.
So is there any possibility to refresh the view in any other way?
Some example: View class receives new information from the external class and, for example, write them on some label.
Or another example: There is a canvas in my view class. Some external class sends coordinates to the view class - how can I draw a point with given coordinates as soon as the view class receives them?
Re: problem with updating a view [message #724942 is a reply to message #724932] Tue, 13 September 2011 14:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by:

The UI callback is the only way to update the UI from a background thread.
To just get it to work, you may want to enable the UI callback
'globally', e.g. call UICallBack.activate() early your entry point.
After that, all UI updates scheduled with asyncExec() will show up.
Note that this is not unrestrained recommendable as an extra request per
client will be pending while the UI callback is active.
For a for fine grained usage, enable the UI callback just before you
start the background thread.

Rüdiger

On 13.09.2011 16:12, Wojtek.wk wrote:
> Thank you very much for your reply.
> So is there any possibility to refresh the view in any other way?
> Some example: View class receives new information from the external
> class and, for example, write them on some label.
> Or another example: There is a canvas in my view class. Some external
> class sends coordinates to the view class - how can I draw a point with
> given coordinates as soon as the view class receives them?

--
Rüdiger Herrmann

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

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: problem with updating a view [message #725060 is a reply to message #724942] Tue, 13 September 2011 20:22 Go to previous messageGo to next message
Wojtek.wk  is currently offline Wojtek.wk Friend
Messages: 29
Registered: September 2011
Junior Member
And is there any other way to update the UI (not exactly from background thread)?

[Updated on: Tue, 13 September 2011 20:23]

Report message to a moderator

Re: problem with updating a view [message #725183 is a reply to message #725060] Wed, 14 September 2011 07:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by:

I am afraid, I don't understand what you mean with "not exactly from
background thread".

If your application needs to update the UI without the aid of user
interaction, then background threads and the UI callback are the only
way to achieve this.
Did you try what I suggested in the previous post?

Rüdiger

On 13.09.2011 22:22, Wojtek.wk wrote:
> And is there any other way to update the UI (not exactly from background
> thread)?
Re: problem with updating a view [message #725240 is a reply to message #725183] Wed, 14 September 2011 10:45 Go to previous messageGo to next message
Wojtek.wk  is currently offline Wojtek.wk Friend
Messages: 29
Registered: September 2011
Junior Member
Thank you for your reply.
Yes, I tried what you suggested in the previous post and it works! Thank you very much!

[Updated on: Wed, 14 September 2011 11:32]

Report message to a moderator

Re: problem with updating a view [message #725257 is a reply to message #725240] Wed, 14 September 2011 11:32 Go to previous messageGo to next message
Wojtek.wk  is currently offline Wojtek.wk Friend
Messages: 29
Registered: September 2011
Junior Member
I've just wondered if there is any possibility to refresh the view without using background threads. And now I know that the answer is "no". Thank you!
Re: problem with updating a view [message #725356 is a reply to message #725257] Wed, 14 September 2011 15:11 Go to previous message
Cole Markham is currently offline Cole MarkhamFriend
Messages: 150
Registered: July 2009
Location: College Station, TX
Senior Member

You don't have to create a new background thread to update the UI. The examples show how to do the update from a thread other than the UI thread. Presumably that thread would already exist. If you are already in the UI thread (e.g., handling something like a button click), then you can just update the UI directly. If you are in the UI thread and have work that need to take a long time to process then you need a background thread to do that. In that case I would recommend an Eclipse Job since RAP handles the UICallback for you.

Does that answer your questions?

Cole
Previous Topic:External javascript in RAP
Next Topic:no window on startup - how to?
Goto Forum:
  


Current Time: Fri Apr 26 05:38:36 GMT 2024

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

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

Back to the top