Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » [Display].timerExec() not executed when expected (as RCP does)
[Display].timerExec() not executed when expected (as RCP does) [message #546397] Mon, 12 July 2010 15:59 Go to next message
Bogdan B. is currently offline Bogdan B.Friend
Messages: 50
Registered: July 2009
Member
In my TreeViewer I add the following:
addPostSelectionChangedListener(new ISelectionChangedListener() {
    public void selectionChanged(final SelectionChangedEvent e) {
        System.out.println("schedule");
        Display display = Display.getDefault();
        display.timerExec(500, new Runnable() {
            public void run() {
                System.out.println("run");
            }
        }
    }
});


The problem is that if I change the selection (SWT.FULL_SELECTION) I get to see "schedule", but "run" doesn't show up after 500ms. But if I click somewhere in the GUI (no matter where), then it actually runs, as if it would have waited for that click event.

In the RCP version of my app I get to see "run" like expected after 500ms, without needing to fire an extra event.

Does anyone know why this happens and how I could make it run like in RCP?

[Updated on: Mon, 12 July 2010 16:37]

Report message to a moderator

Re: [Display].timerExec() not executed when expected (as RCP does) [message #546432 is a reply to message #546397] Mon, 12 July 2010 17:49 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2359
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi Bogdan,

I'm not sure if this is related or not, but currently Tree (TreeViewer)
does not support SWT.FULL_SELECTION style flag (see bug 206780).

Best,
Ivan

On 07/12/2010 6:59 PM, Bogdan B. wrote:
> In my TreeViewer I add the following:
> addPostSelectionChangedListener(new ISelectionChangedListener() {
> public void selectionChanged(final SelectionChangedEvent e) {
> System.out.println("schedule");
> Display display = Display.getDefault();
> display.timerExec(500, new Runnable() {
> public void run() {
> System.out.println("run");
> }
> }
> }
> });
>
> The problem is that if I change the selection (SWT.FULL_SELECTION) I
> get to see "schedule", but "run" doesn't show up after 500ms. But if I
> click somewhere else, as if it would wait for some kind of event, then
> it actually runs.
>
> In the RCP version of my app I get to see "run" like expected after
> 500ms.
>
> Does anyone know why this happens and how I could make it run like in
> RCP?
Re: [Display].timerExec() not executed when expected (as RCP does) [message #546433 is a reply to message #546397] Mon, 12 July 2010 18:21 Go to previous messageGo to next message
Rüdiger Herrmann is currently offline Rüdiger HerrmannFriend
Messages: 581
Registered: July 2009
Senior Member
for (a)syncExec() and timerExec() to update the UI you will need to
activate the UICallback. See the FAQ for more details:
http://wiki.eclipse.org/RAP/FAQ#How_to_update_the_UI_from_a_ background_thread

HTH
Rüdiger

On 12.07.2010 17:59, Bogdan B. wrote:
> In my TreeViewer I add the following:
> addPostSelectionChangedListener(new ISelectionChangedListener() {
> public void selectionChanged(final SelectionChangedEvent e) {
> System.out.println("schedule");
> Display display = Display.getDefault();
> display.timerExec(500, new Runnable() {
> public void run() {
> System.out.println("run");
> }
> }
> }
> });
>
> The problem is that if I change the selection (SWT.FULL_SELECTION) I get
> to see "schedule", but "run" doesn't show up after 500ms. But if I click
> somewhere else, as if it would wait for some kind of event, then it
> actually runs.
>
> In the RCP version of my app I get to see "run" like expected after 500ms.
>
> Does anyone know why this happens and how I could make it run like in RCP?
Re: [Display].timerExec() not executed when expected (as RCP does) [message #546666 is a reply to message #546433] Tue, 13 July 2010 17:13 Go to previous messageGo to next message
Bogdan B. is currently offline Bogdan B.Friend
Messages: 50
Registered: July 2009
Member
Rüdiger Herrmann wrote on Mon, 12 July 2010 14:21
for (a)syncExec() and timerExec() to update the UI you will need to
activate the UICallback. See the FAQ for more details:
http://wiki.eclipse.org/RAP/FAQ#How_to_update_the_UI_from_a_ background_thread

Thank you, Rüdiger, it works now (I'm not sure why though Smile)! I just changed my code as follows:
addPostSelectionChangedListener(new ISelectionChangedListener() {
    public void selectionChanged(final SelectionChangedEvent e) {
        System.out.println("schedule");
        Display display = Display.getDefault();
        final String callbackId = new Date().getTime() + "_" + Math.random();
        UICallBack.activate(callbackId);
        display.timerExec(500, new Runnable() {
            public void run() {
                try {
                    System.out.println("run");
                } finally {
                    UICallBack.deactivate(callbackId);
                }
            }
        }
    }
});

What I still don't understand is why you said I needed to "update the UI". Since "run" was not printed out, it seems to me that the execution blocked when it met the display.timerExec() call. It didn't execute at all until it received my click event.
Re: [Display].timerExec() not executed when expected (as RCP does) [message #546931 is a reply to message #546666] Wed, 14 July 2010 16:13 Go to previous message
Rüdiger Herrmann is currently offline Rüdiger HerrmannFriend
Messages: 581
Registered: July 2009
Senior Member
With "update the UI" I meant that the runnable that is passed into
timerExec is executed (as you usually want to run UI code within the
runnables).
timerExec (same accounts for asyncExec) do *not* block. Both methods
schedule the runnable for execution "at the next reasonable
opportunity". And here RAP behaves just like SWT, the runnables are
executed by readAndDispatch().
As you observed, the runnable gets executed with the next click. But if
you want it being executed more reliably and not just when someone
"accidentally" triggers a reuqest, you will have to activate the
UICallback. When it is active and timerExec() is called, it causes the
client to issue a request. The request in turn will call
readAndDispatch() which in turn will execute the runnables from
timerExec and asyncExec.

HTH
Rüdiger

On 13.07.2010 19:13, Bogdan B. wrote:
> Rüdiger Herrmann wrote on Mon, 12 July 2010 14:21
>> for (a)syncExec() and timerExec() to update the UI you will need to
>> activate the UICallback. See the FAQ for more details:
>> http://wiki.eclipse.org/RAP/FAQ#How_to_update_the_UI_from_a_
>> background_thread
>
> Thank you, Rüdiger, it works now (I'm not sure why though :))! I just
> changed my code as follows:
> addPostSelectionChangedListener(new ISelectionChangedListener() {
> public void selectionChanged(final SelectionChangedEvent e) {
> System.out.println("schedule");
> Display display = Display.getDefault();
> final String callbackId = new Date().getTime() + "_" + Math.random();
> UICallBack.activate(callbackId);
> display.timerExec(500, new Runnable() {
> public void run() {
> try {
> System.out.println("run");
> } finally {
> UICallBack.deactivate(callbackId);
> }
> }
> }
> }
> });
> What I still don't understand is why you said I needed to "update the
> UI". Since "run" was not printed out, it seems to me that the execution
> blocked when it met the display.timerExec() call. It didn't execute at
> all until it received my click event.
Previous Topic:Problem including Prototype Library
Next Topic:could not evaluate javascript response: Invalid characters?
Goto Forum:
  


Current Time: Fri Dec 03 06:45:29 GMT 2021

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

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

Back to the top