Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Fill JFace TableViewer from background Thread
Fill JFace TableViewer from background Thread [message #448869] Fri, 14 January 2005 11:52 Go to next message
Eclipse UserFriend
Originally posted by: joerg.von.frantzius.artnology.nospam.com

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi,<br>
<br>
I'm trying to do pretty much the same as demonstrated in a <a
href=" http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet7.java?rev=HEAD&am p;amp;content-type=text/vnd.viewcvs-markup">snippet
for SWT Table </a> only that I want to fill a TableViewer instead of an
SWT Table. My TableViewer has a LabelProvider and everything works fine
if I fill it synchronously using setInput() and a ContentProvider.
Using a separate Thread and TableViewer.add(), I got it so far as the
table's scroll bar becoming smaller and smaller due to new objects
being added, but it does not show the actual contents in the table,
only the scroll bar becomes smaller!<br>
<br>
This is what my Thread's run method looks like:<br>
<br>
            public void run() {<br>
                for (Iterator iter = kunstwerke.iterator();
iter.hasNext();) {<br>
                    final Kunstwerk kunstwerk = (Kunstwerk) iter.next();<br>
                    d.syncExec(new Runnable() {<br>
                        public void run() {<br>
                            tableViewer.add(kunstwerk);<br>
                            //tableViewer.refresh();<br>
                            }<br>
                    });<br>
                }<br>
<br>
"kunstwerke" is a Set containing the objects to be displayed in the
table and Display "d" was determined using
Display.findDisplay(Thread.currentThread()) in the main thread. I can
see my LabelProvider being called and returning Strings for the table's
columns, but they are not painted. I tried calling refresh as in the
comment above, and tableViewer.update(kunstwerk,null); after the add,
but it didn't help.<br>
<br>
Does anybody haven an idea what the problem might be here? This is with
Eclipse 3.1 M4 on Windows XP.<br>
<br>
Thanks,<br>
Jörg.<br>
</body>
</html>
Re: Fill JFace TableViewer from background Thread [message #448881 is a reply to message #448869] Fri, 14 January 2005 16:56 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: joerg.von.frantzius.artnology.nospam.com

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Alright, nobody answered, which is good because it was entirely my
fault and not related to TableViewer at all... Please disregard.<br>
<br>
Joerg von Frantzius schrieb:
<blockquote cite="midcs8bpo$n7g$1@www.eclipse.org" type="cite">
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
<title></title>
Hi,<br>
<br>
I'm trying to do pretty much the same as demonstrated in a <a
href=" http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet7.java?rev=HEAD&am p;amp;content-type=text/vnd.viewcvs-markup">snippet
for SWT Table </a> only that I want to fill a TableViewer instead of an
SWT Table. My TableViewer has a LabelProvider and everything works fine
if I fill it synchronously using setInput() and a ContentProvider.
Using a separate Thread and TableViewer.add(), I got it so far as the
table's scroll bar becoming smaller and smaller due to new objects
being added, but it does not show the actual contents in the table,
only the scroll bar becomes smaller!<br>
<br>
This is what my Thread's run method looks like:<br>
<br>
            public void run() {<br>
                for (Iterator iter = kunstwerke.iterator();
iter.hasNext();) {<br>
                    final Kunstwerk kunstwerk = (Kunstwerk) iter.next();<br>
                    d.syncExec(new Runnable() {<br>
                        public void run() {<br>
                            tableViewer.add(kunstwerk);<br>
                            //tableViewer.refresh();<br>
                            }<br>
                    });<br>
                }<br>
<br>
"kunstwerke" is a Set containing the objects to be displayed in the
table and Display "d" was determined using
Display.findDisplay(Thread.currentThread()) in the main thread. I can
see my LabelProvider being called and returning Strings for the table's
columns, but they are not painted. I tried calling refresh as in the
comment above, and tableViewer.update(kunstwerk,null); after the add,
but it didn't help.<br>
<br>
Does anybody haven an idea what the problem might be here? This is with
Eclipse 3.1 M4 on Windows XP.<br>
<br>
Thanks,<br>
Jörg.<br>
</blockquote>
<br>
</body>
</html>
Re: Fill JFace TableViewer from background Thread [message #448934 is a reply to message #448881] Sat, 15 January 2005 08:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: petra_h.hotmail.com

Hi Joerg!
I tried to do the same as you describe but unfortunately my table viewer
stay empty as well. What was the problem you had, maybe I do the same
mistake...
I wrote the following code:

final Display display = PlatformUI.getWorkbench().getDisplay();
Thread thread = new Thread () {
public void run() {
//get dbObject display in this editor
DBObject editorObj = ListSection.editorInput;
//get the elements to set in the table
Object[] elements = ((TableContentProvider)collectionViewer.
getContentProvider()).getElements(editorObj);
for (int i=0; i< elements.length; i++){
final DBObject dbObj = (DBObject)elements[i];
display.syncExec(new Runnable() {
public void run() {
collectionViewer.add(dbObj);
collectionViewer.refresh();
}
});
}
};
};
thread.start();

Thanks for your answer,
Petra

Joerg von Frantzius wrote:

> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <html>
> <head>
> <meta content="text/html;charset=ISO-8859-15"
> http-equiv="Content-Type">
> </head>
> <body bgcolor="#ffffff" text="#000000">
> Alright, nobody answered, which is good because it was entirely my
> fault and not related to TableViewer at all... Please disregard.<br>
> <br>
> Joerg von Frantzius schrieb:
> <blockquote cite="midcs8bpo$n7g$1@www.eclipse.org" type="cite">
> <meta content="text/html;charset=ISO-8859-15"
> http-equiv="Content-Type">
> <title></title>
> Hi,<br>
> <br>
> I'm trying to do pretty much the same as demonstrated in a <a
>
href=" http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet7.java?rev=HEAD&am p;content-type=text/vnd.viewcvs-markup">snippet
> for SWT Table </a> only that I want to fill a TableViewer instead of an
> SWT Table. My TableViewer has a LabelProvider and everything works fine
> if I fill it synchronously using setInput() and a ContentProvider.
> Using a separate Thread and TableViewer.add(), I got it so far as the
> table's scroll bar becoming smaller and smaller due to new objects
> being added, but it does not show the actual contents in the table,
> only the scroll bar becomes smaller!<br>
> <br>
> This is what my Thread's run method looks like:<br>
> <br>
>             public void run() {<br>
>                 for (Iterator iter = kunstwerke.iterator();
> iter.hasNext();) {<br>
>                     final Kunstwerk kunstwerk = (Kunstwerk) iter.next();<br>
>                     d.syncExec(new Runnable() {<br>
>                         public void run() {<br>
>                             tableViewer.add(kunstwerk);<br>
>                             //tableViewer.refresh();<br>
>                             }<br>
>                     });<br>
>                 }<br>
> <br>
> "kunstwerke" is a Set containing the objects to be displayed in the
> table and Display "d" was determined using
> Display.findDisplay(Thread.currentThread()) in the main thread. I can
> see my LabelProvider being called and returning Strings for the table's
> columns, but they are not painted. I tried calling refresh as in the
> comment above, and tableViewer.update(kunstwerk,null); after the add,
> but it didn't help.<br>
> <br>
> Does anybody haven an idea what the problem might be here? This is with
> Eclipse 3.1 M4 on Windows XP.<br>
> <br>
> Thanks,<br>
> Jörg.<br>
> </blockquote>
> <br>
> </body>
> </html>
TreeViewer? Re: Fill JFace TableViewer from background Thread [message #448936 is a reply to message #448934] Sat, 15 January 2005 08:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: petra_h.hotmail.com

Hi!
I also managed it to get it working. But another question (maybe someone
knows an answer): is the same behavior possible for a tree viewer instead
of a table viewer? My problem is that the first two levels of the tree
expand quite quickly, but then the third level needs a lot of time. Is it
possible to do this third expansion in a lazy manner?
Thanks for any help.
Petra

Petra Hangartner wrote:

> Hi Joerg!
> I tried to do the same as you describe but unfortunately my table viewer
> stay empty as well. What was the problem you had, maybe I do the same
> mistake...
> I wrote the following code:

> final Display display = PlatformUI.getWorkbench().getDisplay();
> Thread thread = new Thread () {
> public void run() {
> //get dbObject display in this editor
> DBObject editorObj = ListSection.editorInput;
> //get the elements to set in the table
> Object[] elements = ((TableContentProvider)collectionViewer.
> getContentProvider()).getElements(editorObj);
> for (int i=0; i< elements.length; i++){
> final DBObject dbObj = (DBObject)elements[i];
> display.syncExec(new Runnable() {
> public void run() {
> collectionViewer.add(dbObj);
> collectionViewer.refresh();
> }
> });
> }
> };
> };
> thread.start();

> Thanks for your answer,
> Petra

> Joerg von Frantzius wrote:

>> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
>> <html>
>> <head>
>> <meta content="text/html;charset=ISO-8859-15"
>> http-equiv="Content-Type">
>> </head>
>> <body bgcolor="#ffffff" text="#000000">
>> Alright, nobody answered, which is good because it was entirely my
>> fault and not related to TableViewer at all... Please disregard.<br>
>> <br>
>> Joerg von Frantzius schrieb:
>> <blockquote cite="midcs8bpo$n7g$1@www.eclipse.org" type="cite">
>> <meta content="text/html;charset=ISO-8859-15"
>> http-equiv="Content-Type">
>> <title></title>
>> Hi,<br>
>> <br>
>> I'm trying to do pretty much the same as demonstrated in a <a
>>
>
href=" http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet7.java?rev=HEAD&am p;content-type=text/vnd.viewcvs-markup">snippet
>> for SWT Table </a> only that I want to fill a TableViewer instead of an
>> SWT Table. My TableViewer has a LabelProvider and everything works fine
>> if I fill it synchronously using setInput() and a ContentProvider.
>> Using a separate Thread and TableViewer.add(), I got it so far as the
>> table's scroll bar becoming smaller and smaller due to new objects
>> being added, but it does not show the actual contents in the table,
>> only the scroll bar becomes smaller!<br>
>> <br>
>> This is what my Thread's run method looks like:<br>
>> <br>
>>             public void run() {<br>
>>                 for (Iterator iter = kunstwerke.iterator();
>> iter.hasNext();) {<br>
>>                     final Kunstwerk kunstwerk = (Kunstwerk) iter.next();<br>
>>                     d.syncExec(new Runnable() {<br>
>>                         public void run() {<br>
>>                             tableViewer.add(kunstwerk);<br>
>>                             //tableViewer.refresh();<br>
>>                             }<br>
>>                     });<br>
>>                 }<br>
>> <br>
>> "kunstwerke" is a Set containing the objects to be displayed in the
>> table and Display "d" was determined using
>> Display.findDisplay(Thread.currentThread()) in the main thread. I can
>> see my LabelProvider being called and returning Strings for the table's
>> columns, but they are not painted. I tried calling refresh as in the
>> comment above, and tableViewer.update(kunstwerk,null); after the add,
>> but it didn't help.<br>
>> <br>
>> Does anybody haven an idea what the problem might be here? This is with
>> Eclipse 3.1 M4 on Windows XP.<br>
>> <br>
>> Thanks,<br>
>> Jörg.<br>
>> </blockquote>
>> <br>
>> </body>
>> </html>
Re: TreeViewer? Re: Fill JFace TableViewer from background Thread [message #448937 is a reply to message #448936] Sat, 15 January 2005 11:25 Go to previous message
Stefan Zeiger is currently offline Stefan ZeigerFriend
Messages: 102
Registered: July 2009
Senior Member
Petra Hangartner wrote:

> I also managed it to get it working. But another question (maybe someone
> knows an answer): is the same behavior possible for a tree viewer
> instead of a table viewer? My problem is that the first two levels of
> the tree expand quite quickly, but then the third level needs a lot of
> time. Is it possible to do this third expansion in a lazy manner? Thanks
> for any help.

I've written a TreeContentProvider which can be used as an adapter for
another TreeContentProvider whose methods are called in background
threads. If a node cannot be expanded within 0.1 seconds, a "Pending"
node is shown instead of the real children. When the getChildren() call
finally returns, the "Pending" node is replaced by the real children.
This is the same effect that you see in Eclipse's "CVS Repositories"
view but it can be used with any TreeContentProvider that doesn't mind
being called simultaneously from multiple threads.

The class is
com.novocode.naf.jface.viewers.BackgroundTreeContentProvider s in
Novocode Application Framework 0.2 (http://www.novocode.com/swt). The
included "ExplorerExample" application shows how to use it.

The class is not quite finished yet but it already works very well for
the intended purpose. The hasChildren() handling could be improved and
there needs to be some kind of refresh() method which allows a tree node
to be refreshed even when a background operation is currently running on
that node.

--
Stefan Zeiger http://www.szeiger.de http://www.novocode.com
My SWT controls: http://www.novocode.com/swt
Previous Topic:TableEditor Question
Next Topic:Buttons and Action
Goto Forum:
  


Current Time: Fri Apr 19 13:37:51 GMT 2024

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

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

Back to the top