Skip to main content



      Home
Home » Eclipse Projects » Remote Application Platform (RAP) » TimerTask
TimerTask [message #53374] Thu, 18 October 2007 09:38 Go to next message
Eclipse UserFriend
Originally posted by: sparkitny.gmail.com

1) How is it possible to implement a timertask in RAP? I need this to
periodically update a tables content.

2) I fixed some problems with my dialog. But now I have a strange problem.
When I open the dialog for the first time everthing seems to be alright.
When I open it the again the Buttons that are within the dialog by default
disappear. Does anybody know this problem?
Re: TimerTask [message #53458 is a reply to message #53374] Thu, 18 October 2007 13:49 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

> 1) How is it possible to implement a timertask in RAP? I need this to
> periodically update a tables content.
>
you could just start a background thread in a seperate osgi plugin for
this. This would be one of many ways.

Markus Wolf
--
> emedia-solutions wolf web: http://www.emedia-solutions-wolf.de
> Eimsbüttler Straße 115 mail: markus@emedia-solutions-wolf.de
> 22769 Hamburg pgp: http://wwwkeys.de.pgp.net
> +49 40 432 635 83 taxid: 57 / 126 / 16123
Re: TimerTask [message #53485 is a reply to message #53458] Thu, 18 October 2007 16:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sparkitny.gmail.com

Hi,

thanks for the answer. But I don't understand exactly. Why should I use a
background threat in another osgi plugin?
I tried to play with TimerTask => didn't work. Some strange complaints.
It should be possible to do such updates as RAP is partly built on qooxdoo
and there exist a timer. Is there another, more intuitive way?
Re: TimerTask [message #53595 is a reply to message #53485] Fri, 19 October 2007 01:46 Go to previous messageGo to next message
Eclipse UserFriend
One way how you can update your table contents asynchronously every second:

final String uiCallbackId = getClass().getName();
UICallBack.activate(uiCallbackId);

[...]

Thread thread = new Thread(new Runnable(){
public void run(){
while (isTableToBeUpdated()) {

try {
Thread.sleep(1000);
} catch (InterruptedException shouldNotHappen) {
shouldNotHappen.printStackTrace();
}

display.syncExec(new Runnable(){

public void run(){
refreshTableViewer();
}
});

}

}
});

thread.start();

[...]
// call this if asynchronous ui-updates are no longner necessary
UICallBack.deactivate(uiCallbackId);


Hope this helps,
Stefan.

Sebastian Parkitny schrieb:
> Hi,
>
> thanks for the answer. But I don't understand exactly. Why should I use
> a background threat in another osgi plugin? I tried to play with
> TimerTask => didn't work. Some strange complaints.
> It should be possible to do such updates as RAP is partly built on
> qooxdoo and there exist a timer. Is there another, more intuitive way?
>
Re: TimerTask [message #53645 is a reply to message #53595] Fri, 19 October 2007 05:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sparkitny.gmail.com

Hello Stefan,

thanks for the answer. Unfortunately it doesn't work correctly. The thread
is only executed once and I don't know why. Any idea? Furthermore I'm
going to try Jobs. Maybe this works.
Re: TimerTask [message #53671 is a reply to message #53645] Fri, 19 October 2007 05:25 Go to previous messageGo to next message
Eclipse UserFriend
When do you call UICallBack.deactivate(uiCallbackId)?

Enabling and disabling should only be done once. For instance, if you
know that the table should refresh from now on, call
UICallBack#enable(). If the asynchron refreshes are no longer needed,
call UICallback#deactivate(). Maybe, this is your problem?

Stefan.

Sebastian Parkitny schrieb:
> Hello Stefan,
>
> thanks for the answer. Unfortunately it doesn't work correctly. The
> thread is only executed once and I don't know why. Any idea? Furthermore
> I'm going to try Jobs. Maybe this works.
>
Re: TimerTask [message #53695 is a reply to message #53671] Fri, 19 October 2007 06:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sparkitny.gmail.com

Here is the code. The class extends a Table and can easily be added to any
View

package rap;

import java.util.Date;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.rwt.lifecycle.UICallBack;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

public class MessageTable extends Table implements Runnable {

final Thread thread = new Thread(this);

final MessageTable self = this;

final Display display = this.getDisplay();

public MessageTable(Composite parent, int style) {
super(parent, style);

TableLayout tablelayout = new TableLayout();
tablelayout.addColumnData(new ColumnWeightData(33, 75, true));
tablelayout.addColumnData(new ColumnWeightData(33, 75, true));
tablelayout.addColumnData(new ColumnWeightData(33, 75, true));

this.setLayout(tablelayout);

TableColumn c1 = new TableColumn(this, SWT.LEFT);
TableColumn c2 = new TableColumn(this, SWT.LEFT);
TableColumn c3 = new TableColumn(this, SWT.LEFT);
c1.setText("Time");
c2.setText("Type");
c3.setText("Description");

this.setHeaderVisible(true);
this.setLinesVisible(true);

UICallBack.activate("updatetable");

thread.start();
}


public void run() {

final MessageTable self = this;

try {
Thread.sleep(2000);
System.out.println(new Date().toString() + " executed Thread");

display.syncExec(new Runnable() {

public void run() {
try {

for (int j = 0; j < 10; j++) {
TableItem i = new TableItem(self, SWT.NONE);
i.setText(0, new Date().toString());
i.setText(1, "Information");
i.setText(2, "Test description");
}

} catch (Exception e) {
System.out.println(e);
}
}
});
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}


Maybe you try it yourself.
Re: TimerTask [message #53718 is a reply to message #53695] Fri, 19 October 2007 07:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sparkitny.gmail.com

The usage of Jobs did the trick. Nearly. There are some strange update
problems in the table. Maybe I'll try TableViewer. Here's the code:

package rap;

import java.util.Date;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.rwt.lifecycle.UICallBack;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

public class MessageTable extends Table {

final MessageTable self = this;

final Display display = this.getDisplay();

public MessageTable(Composite parent, int style) {

super(parent, style);

TableLayout tablelayout = new TableLayout();
tablelayout.addColumnData(new ColumnWeightData(33, 75, true));
tablelayout.addColumnData(new ColumnWeightData(33, 75, true));
tablelayout.addColumnData(new ColumnWeightData(33, 75, true));

this.setLayout(tablelayout);

TableColumn c1 = new TableColumn(this, SWT.LEFT);
TableColumn c2 = new TableColumn(this, SWT.LEFT);
TableColumn c3 = new TableColumn(this, SWT.LEFT);
c1.setText("Time");
c2.setText("Type");
c3.setText("Description");

this.setHeaderVisible(true);
this.setLinesVisible(true);

UICallBack.activate("updatetable");

final Job job = new Job("Long Running Job") {
protected IStatus run(IProgressMonitor monitor) {
try {
display.asyncExec(new Runnable() {

public void run() {
fill();
}
});

return Status.OK_STATUS;
} finally {
schedule(5000);
}
}
};

job.schedule();

}

private void fill() {
try {
System.out.println(this.getItemCount());
this.removeAll();
for (int j = 0; j < 10; j++) {
TableItem i = new TableItem(self, SWT.NONE);
i.setText(0, new Date().toString());
i.setText(1, "Information");
i.setText(2, "Test description");
}

} catch (Exception e) {
System.out.println(e);
}
}
}
Re: TimerTask [message #53745 is a reply to message #53718] Fri, 19 October 2007 08:42 Go to previous messageGo to next message
Eclipse UserFriend
I think the problem with you first soltion was, that there was no loop
in your thread and so the update has been called only once.

However, there are some open bugs concering the table, especially for
refreshes of virtual tables. See bugs 206324, 205687, 195826 for details
and workarounds.


Sebastian Parkitny schrieb:
> The usage of Jobs did the trick. Nearly. There are some strange update
> problems in the table. Maybe I'll try TableViewer. Here's the code:
>
> package rap;
>
> import java.util.Date;
> import org.eclipse.core.runtime.IProgressMonitor;
> import org.eclipse.core.runtime.IStatus;
> import org.eclipse.core.runtime.Status;
> import org.eclipse.core.runtime.jobs.Job;
> import org.eclipse.jface.viewers.ColumnWeightData;
> import org.eclipse.jface.viewers.TableLayout;
> import org.eclipse.rwt.lifecycle.UICallBack;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Table;
> import org.eclipse.swt.widgets.TableColumn;
> import org.eclipse.swt.widgets.TableItem;
>
> public class MessageTable extends Table {
>
> final MessageTable self = this;
>
> final Display display = this.getDisplay();
>
> public MessageTable(Composite parent, int style) {
>
> super(parent, style);
>
> TableLayout tablelayout = new TableLayout();
> tablelayout.addColumnData(new ColumnWeightData(33, 75, true));
> tablelayout.addColumnData(new ColumnWeightData(33, 75, true));
> tablelayout.addColumnData(new ColumnWeightData(33, 75, true));
>
> this.setLayout(tablelayout);
>
> TableColumn c1 = new TableColumn(this, SWT.LEFT);
> TableColumn c2 = new TableColumn(this, SWT.LEFT);
> TableColumn c3 = new TableColumn(this, SWT.LEFT);
> c1.setText("Time");
> c2.setText("Type");
> c3.setText("Description");
>
> this.setHeaderVisible(true);
> this.setLinesVisible(true);
>
> UICallBack.activate("updatetable");
>
> final Job job = new Job("Long Running Job") {
> protected IStatus run(IProgressMonitor monitor) {
> try {
> display.asyncExec(new Runnable() {
>
> public void run() {
> fill();
> }
> });
>
> return Status.OK_STATUS;
> } finally {
> schedule(5000); }
> }
> };
>
> job.schedule();
>
> }
>
> private void fill() {
> try {
> System.out.println(this.getItemCount());
> this.removeAll();
> for (int j = 0; j < 10; j++) {
> TableItem i = new TableItem(self, SWT.NONE);
> i.setText(0, new Date().toString());
> i.setText(1, "Information");
> i.setText(2, "Test description");
> }
>
> } catch (Exception e) {
> System.out.println(e);
> }
> }
> }
>
>
Re: TimerTask [message #53772 is a reply to message #53745] Fri, 19 October 2007 09:52 Go to previous message
Eclipse UserFriend
Originally posted by: sparkitny.gmail.com

Hello,

of course you're right. I forgot the loop!
Previous Topic:Dialog problems
Next Topic:LifeCycle Exception
Goto Forum:
  


Current Time: Wed Apr 23 23:00:09 EDT 2025

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

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

Back to the top