Skip to main content



      Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » TableTree disappears
TableTree disappears [message #372730] Wed, 20 August 2003 07:26 Go to next message
Eclipse UserFriend
Originally posted by: mueller.software.email.de

Hi all,

At the moment I'm testing SWT if it fit's the requirements
to be used as GUI lib for our application.

What I've tried right now is displaying the first level of items
in a TableTree. One of those items has a sub item which is
only a dummy and which has to be replaced as soon as the
user expands its parent. When the treeExpanded event occurs,
the dummy will be disposed and replaced by the real data.
To simulate the elapsed time used for querying the database
I've added a call to Thread.sleep(5000) in the code. (see code below)

What happens is that the whole TableTree disappears for
that 5000 ms.

My questions:
Is this the normal behaviour and will it be the same if
querying the dabase will need that time?
How can I prevent the TableTree from disappearing?

Regards

J
Re: TableTree disappears [message #372733 is a reply to message #372730] Wed, 20 August 2003 08:19 Go to previous messageGo to next message
Eclipse UserFriend
Hi Jürgen,

for me your snippet works (TableTree doesn't disappear). So my question
is what system you are using (I use Win2K, SWT 2.0.2).
Of course the TableTree disappears while the thread is sleeping and I am
clicking anywhere out of the window becauseof the UIThread was sent to
sleep. So no (re)paint will occur until thread wakes up.

What you could do is using Display.asyncExec or Display.syncExec.

For example something like that will display TableTree when clicking
anywhere out of that window:

public static void main(String[] args) {

final Display display = new Display();
final Shell shell = new Shell(display);
shell.setBounds(100, 100, 800, 600);
shell.setLayout(new FillLayout());
shell.setText("TreeTableTest");

TableTree tableTree = new TableTree(shell, SWT.NONE);
tableTree.getTable().setHeaderVisible(true);
tableTree.getTable().setLinesVisible(true);

TableTreeItem item = new TableTreeItem(tableTree,SWT.NONE);
item.setText("Item 1");
item = new TableTreeItem(tableTree,SWT.NONE);
item.setText("Item 2");
item = new TableTreeItem(tableTree,SWT.NONE);
item.setText("Item 3");
TableTreeItem branch = new TableTreeItem(item, SWT.NONE);
branch.setText("dummy");

tableTree.addTreeListener(new TreeAdapter() {
public void treeExpanded(TreeEvent e) {
final TableTreeItem item = (TableTreeItem) e.item;
item.getItems()[0].dispose();
new Thread () {
public void run () {
try {Thread.sleep (5000);} catch (Throwable th) {}
display.asyncExec (
new Runnable () {
public void run () {
if (item.isDisposed ()) return;
TableTreeItem branch2 = new TableTreeItem(item, SWT.NONE);
branch2.setText("real data 1");
branch2 = new TableTreeItem(item,SWT.NONE);
branch2.setText("real data 2");
branch2 = new TableTreeItem(item,SWT.NONE);
branch2.setText("real data 2");
}
});
}
}.start ();
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}

Ralf

jumu schrieb:

> Hi all,
>
> At the moment I'm testing SWT if it fit's the requirements
> to be used as GUI lib for our application.
>
> What I've tried right now is displaying the first level of items
> in a TableTree. One of those items has a sub item which is
> only a dummy and which has to be replaced as soon as the
> user expands its parent. When the treeExpanded event occurs,
> the dummy will be disposed and replaced by the real data.
> To simulate the elapsed time used for querying the database
> I've added a call to Thread.sleep(5000) in the code. (see code below)
>
> What happens is that the whole TableTree disappears for
> that 5000 ms.
>
> My questions:
> Is this the normal behaviour and will it be the same if
> querying the dabase will need that time?
> How can I prevent the TableTree from disappearing?
>
> Regards
>
> Jürgen

[snip]
Re: TableTree disappears [message #372735 is a reply to message #372733] Wed, 20 August 2003 08:45 Go to previous messageGo to next message
Eclipse UserFriend
Well,

there is a bug in it, so here is the solution:

....

public void treeExpanded(TreeEvent e) {
final TableTreeItem item = (TableTreeItem) e.item;
TableTreeItem[] items = item.getItems();
for(int i = 0; i < items.length; i++)
items[i].dispose();

....


Ralf
Re: TableTree disappears [message #372742 is a reply to message #372735] Wed, 20 August 2003 09:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mueller.software.email.de

Hello Ralf,

thanks for your hint.
My solution now is the following (but it's not perfect, yet).
Unfortunately, while the thread sleeps the shell may not be positioned and
doesn't repaint
after it was hidden by another window.
Is the behaviour the same on your system?
I'm using SWT 3.0M2 and Win XP.

In SWING it is possible to move the main window and it comes up again
after it was hidden behind another window and is activated again.
I think this should be possible here, too. Is it possible to start an extra
thread which can perform UI updates in SWT?

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TableTree;
import org.eclipse.swt.custom.TableTreeItem;
import org.eclipse.swt.events.TreeAdapter;
import org.eclipse.swt.events.TreeEvent;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class TreeTableTest {

public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setBounds(100, 100, 800, 600);
shell.setLayout(new FillLayout());
shell.setText("TreeTableTest");

TableTree tableTree = new TableTree(shell, SWT.NONE);
tableTree.getTable().setHeaderVisible(true);
tableTree.getTable().setLinesVisible(true);

TableTreeItem item = new TableTreeItem(tableTree, SWT.NONE);
item.setText("Item 1");
item = new TableTreeItem(tableTree, SWT.NONE);
item.setText("Item 2");
item = new TableTreeItem(tableTree, SWT.NONE);
item.setText("Item 3");
TableTreeItem branch = new TableTreeItem(item, SWT.NONE);
branch.setText("dummy");

tableTree.addTreeListener(new TreeAdapter() {

public void treeExpanded(TreeEvent e) {
final TableTreeItem item = (TableTreeItem) e.item;
TableTreeItem[] items = item.getItems();
for (int i = 0; i < items.length; i++)
items[i].dispose();

final Cursor cursor = new Cursor(display, SWT.CURSOR_WAIT);
shell.setCursor(cursor);
display.asyncExec(new Runnable() {
public void run() {
if (item.isDisposed())
return;

try {Thread.sleep(5000);} catch (InterruptedException e) {}

TableTreeItem branch2 =
new TableTreeItem(item, SWT.NONE);
branch2.setText("real data 1");
branch2 = new TableTreeItem(item, SWT.NONE);
branch2.setText("real data 2");
branch2 = new TableTreeItem(item, SWT.NONE);
branch2.setText("real data 2");
final Cursor c = new Cursor(display, SWT.CURSOR_ARROW);
shell.setCursor(c);
cursor.dispose();
}
});
}
});
tableTree.setEnabled(true);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}



"Ralf Koban" <ralf.koban@gmx.de> schrieb im Newsbeitrag
news:bhvqgt$h98$1@eclipse.org...
> Well,
>
> there is a bug in it, so here is the solution:
>
> ...
>
> public void treeExpanded(TreeEvent e) {
> final TableTreeItem item = (TableTreeItem) e.item;
> TableTreeItem[] items = item.getItems();
> for(int i = 0; i < items.length; i++)
> items[i].dispose();
>
> ...
>
>
> Ralf
>
Re: TableTree disappears [message #372743 is a reply to message #372742] Wed, 20 August 2003 10:11 Go to previous messageGo to next message
Eclipse UserFriend
jumu schrieb:

> Hello Ralf,

Hi Jürgen,

>
> thanks for your hint.
> My solution now is the following (but it's not perfect, yet).
> Unfortunately, while the thread sleeps the shell may not be positioned and
> doesn't repaint
> after it was hidden by another window.
> Is the behaviour the same on your system?
> I'm using SWT 3.0M2 and Win XP.
>
> In SWING it is possible to move the main window and it comes up again
> after it was hidden behind another window and is activated again.
> I think this should be possible here, too. Is it possible to start an extra
> thread which can perform UI updates in SWT?

the behaviour you described is system independent.
Don't think about creating a new thread which performs the UI updates,
think about creating a new working thread (which you can send to sleep)
so that the UI thread can update itself.

Your described behaviour is caused by the following lines in your code:

> tableTree.addTreeListener(new TreeAdapter() {
>
> public void treeExpanded(TreeEvent e) {
> final TableTreeItem item = (TableTreeItem) e.item;
> TableTreeItem[] items = item.getItems();
> for (int i = 0; i < items.length; i++)
> items[i].dispose();
>
> final Cursor cursor = new Cursor(display, SWT.CURSOR_WAIT);
> shell.setCursor(cursor);
> display.asyncExec(new Runnable() {
> public void run() {
> if (item.isDisposed())
> return;
>
> try {Thread.sleep(5000);} catch (InterruptedException e) {}


Reason: You didn't created a new thread and so Thread.sleep(x) sends the
UIThread to sleep.


Create a new thread and it will work:

tableTree.addTreeListener(new TreeAdapter() {
public void treeExpanded(TreeEvent e) {
final TableTreeItem item = (TableTreeItem) e.item;
for (int i = 0; i < items.length; i++)
items[i].dispose();
final Cursor cursor = new Cursor(display, SWT.CURSOR_WAIT);
shell.setCursor(cursor);

// create the working thread here so that that thread will
// be sent to sleep
new Thread () {
public void run () {
try {Thread.sleep (5000);} catch (Throwable th) {}
display.asyncExec (
new Runnable () {
public void run () {
if (item.isDisposed ()) return;
....
(here comes the rest of code in my previous postings)

Ralf
Re: TableTree disappears [message #372744 is a reply to message #372730] Wed, 20 August 2003 10:39 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: veronika_irvine.oti.com

>Thread.sleep(5000);

You are putting the UI thread to sleep and thus "hanging" the display for 5
seconds. When the UI thread is put to sleep it will not be able to repaint
damaged areas such as when a window is placed in front of it or when it is
resized.

You need to do your database query in another thread and then update the UI
from the other thread using display.syncExec or display.asyncExec.

See:
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/plat form-swt-home/faq.html#uithread

"jumu" <mueller.software@email.de> wrote in message
news:bhvlm0$cud$1@eclipse.org...
> Hi all,
>
> At the moment I'm testing SWT if it fit's the requirements
> to be used as GUI lib for our application.
>
> What I've tried right now is displaying the first level of items
> in a TableTree. One of those items has a sub item which is
> only a dummy and which has to be replaced as soon as the
> user expands its parent. When the treeExpanded event occurs,
> the dummy will be disposed and replaced by the real data.
> To simulate the elapsed time used for querying the database
> I've added a call to Thread.sleep(5000) in the code. (see code below)
>
> What happens is that the whole TableTree disappears for
> that 5000 ms.
>
> My questions:
> Is this the normal behaviour and will it be the same if
> querying the dabase will need that time?
> How can I prevent the TableTree from disappearing?
>
> Regards
>
> J
Re: TableTree disappears [message #372745 is a reply to message #372744] Wed, 20 August 2003 10:40 Go to previous message
Eclipse UserFriend
Originally posted by: veronika_irvine.oti.com

See also the following snippet:

http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/plat form-swt-home/snippits/snippet7.html

"Veronika Irvine" <veronika_irvine@oti.com> wrote in message
news:bi0173$pd9$1@eclipse.org...
> >Thread.sleep(5000);
>
> You are putting the UI thread to sleep and thus "hanging" the display for
5
> seconds. When the UI thread is put to sleep it will not be able to
repaint
> damaged areas such as when a window is placed in front of it or when it is
> resized.
>
> You need to do your database query in another thread and then update the
UI
> from the other thread using display.syncExec or display.asyncExec.
>
> See:
>
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/plat form-swt-home/faq.html#uithread
>
> "jumu" <mueller.software@email.de> wrote in message
> news:bhvlm0$cud$1@eclipse.org...
> > Hi all,
> >
> > At the moment I'm testing SWT if it fit's the requirements
> > to be used as GUI lib for our application.
> >
> > What I've tried right now is displaying the first level of items
> > in a TableTree. One of those items has a sub item which is
> > only a dummy and which has to be replaced as soon as the
> > user expands its parent. When the treeExpanded event occurs,
> > the dummy will be disposed and replaced by the real data.
> > To simulate the elapsed time used for querying the database
> > I've added a call to Thread.sleep(5000) in the code. (see code below)
> >
> > What happens is that the whole TableTree disappears for
> > that 5000 ms.
> >
> > My questions:
> > Is this the normal behaviour and will it be the same if
> > querying the dabase will need that time?
> > How can I prevent the TableTree from disappearing?
> >
> > Regards
> >
> > J
Previous Topic:Buffered Table
Next Topic:TableEditor and dispose
Goto Forum:
  


Current Time: Thu Nov 06 15:13:26 EST 2025

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

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

Back to the top