problem with updating a view [message #724843] |
Tue, 13 September 2011 10:36 |
Wojtek.wk 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 |
Eclipse User |
|
|
|
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 #724942 is a reply to message #724932] |
Tue, 13 September 2011 14:38 |
Eclipse User |
|
|
|
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 #725183 is a reply to message #725060] |
Wed, 14 September 2011 07:19 |
Eclipse User |
|
|
|
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 #725356 is a reply to message #725257] |
Wed, 14 September 2011 15:11 |
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.03670 seconds