TimerTask [message #53374] |
Thu, 18 October 2007 13:38 |
Eclipse User |
|
|
|
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 #53485 is a reply to message #53458] |
Thu, 18 October 2007 20:38 |
Eclipse User |
|
|
|
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 #53645 is a reply to message #53595] |
Fri, 19 October 2007 09:18 |
Eclipse User |
|
|
|
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 #53695 is a reply to message #53671] |
Fri, 19 October 2007 10:27 |
Eclipse User |
|
|
|
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 11:34 |
Eclipse User |
|
|
|
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 12:42 |
Stefan Messages: 316 Registered: July 2009 |
Senior Member |
|
|
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);
> }
> }
> }
>
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.04370 seconds