Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » TreeViewer collapses when calling refresh()
TreeViewer collapses when calling refresh() [message #524884] Sat, 03 April 2010 13:36 Go to next message
Eclipse UserFriend
Originally posted by: leopold.gerlinger.aon.at

Hello everybody!

I'm working on an explorer-like window to allow my customer to edit
database items from our SWT client. The window has a TreeViewer on the
left and a editor window to the right. Everything works fine, except
when I call refresh() on the TreeViewer to update the visible items
(text and image depends on a status cache). In this case most of my
tree collapses and is not opened again.

This seems to be bound to the fact that I load the child items of the
tree from the database everytime the getChildren() method is called.

It seems like the TreeViewer compares the object id's and collapses if
it's not able to match it with the ones returned by the new
getChildren() call. I've also tried to implement the equals() method of
my root item class to compare against the primary key of the database
but this doesn't help (or I've done something wrong).

In an older implementation (having the whole DB tables cached) it worked
when I copied the items attributes (the ones from the recently fetched
from the DB) to the items already known by the TreeViewer to avoid
returning new item objects to the TreeViewer. So there either seems a
dependency on the object id's or the hashcode of the objects.

Any hints of how I could solve the problem?

Regards - Leo

P.S.: I know, a snippet would be fine, but then I'd have to deliver my
DB too - that's a bit too much ;-)
Re: TreeViewer collapses when calling refresh() [message #524917 is a reply to message #524884] Sun, 04 April 2010 03:38 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Did you tried to set an IElementComparer?

Tom

Am 03.04.10 15:36, schrieb leoger:
> Hello everybody!
>
> I'm working on an explorer-like window to allow my customer to edit
> database items from our SWT client. The window has a TreeViewer on the
> left and a editor window to the right. Everything works fine, except
> when I call refresh() on the TreeViewer to update the visible items
> (text and image depends on a status cache). In this case most of my
> tree collapses and is not opened again.
>
> This seems to be bound to the fact that I load the child items of the
> tree from the database everytime the getChildren() method is called.
>
> It seems like the TreeViewer compares the object id's and collapses if
> it's not able to match it with the ones returned by the new
> getChildren() call. I've also tried to implement the equals() method of
> my root item class to compare against the primary key of the database
> but this doesn't help (or I've done something wrong).
>
> In an older implementation (having the whole DB tables cached) it worked
> when I copied the items attributes (the ones from the recently fetched
> from the DB) to the items already known by the TreeViewer to avoid
> returning new item objects to the TreeViewer. So there either seems a
> dependency on the object id's or the hashcode of the objects.
>
> Any hints of how I could solve the problem?
>
> Regards - Leo
>
> P.S.: I know, a snippet would be fine, but then I'd have to deliver my
> DB too - that's a bit too much ;-)
Re: TreeViewer collapses when calling refresh() [message #524940 is a reply to message #524917] Sun, 04 April 2010 14:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: leopold.gerlinger.aon.at

Thanks Tom for the prompt answer.

No up to now not, this seems not to be covered by the eclipse TreeViewer
article. I will try to use that and get back with an answer shortly (if
my wife let me do this ;-).

Anyway will I run into problems when producing the same hashcode for
different elements then? I would implement to give the hashcode of the
DB primary key as a result to hashcode(), so there will be the same
has for two POJO's from the DB.

Regards - Leo

Am 04.04.2010 05:38, schrieb Tom Schindl:
> Did you tried to set an IElementComparer?
>
> Tom
>
> Am 03.04.10 15:36, schrieb leoger:
>> Hello everybody!
>>
>> I'm working on an explorer-like window to allow my customer to edit
>> database items from our SWT client. The window has a TreeViewer on the
>> left and a editor window to the right. Everything works fine, except
>> when I call refresh() on the TreeViewer to update the visible items
>> (text and image depends on a status cache). In this case most of my
>> tree collapses and is not opened again.
>>
>> This seems to be bound to the fact that I load the child items of the
>> tree from the database everytime the getChildren() method is called.
>>
>> It seems like the TreeViewer compares the object id's and collapses if
>> it's not able to match it with the ones returned by the new
>> getChildren() call. I've also tried to implement the equals() method of
>> my root item class to compare against the primary key of the database
>> but this doesn't help (or I've done something wrong).
>>
>> In an older implementation (having the whole DB tables cached) it worked
>> when I copied the items attributes (the ones from the recently fetched
>> from the DB) to the items already known by the TreeViewer to avoid
>> returning new item objects to the TreeViewer. So there either seems a
>> dependency on the object id's or the hashcode of the objects.
>>
>> Any hints of how I could solve the problem?
>>
>> Regards - Leo
>>
>> P.S.: I know, a snippet would be fine, but then I'd have to deliver my
>> DB too - that's a bit too much ;-)
>
Re: TreeViewer collapses when calling refresh() [message #525345 is a reply to message #524940] Tue, 06 April 2010 09:50 Go to previous message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 04.04.2010 16:21, leoger wrote:
> Anyway will I run into problems when producing the same hashcode for
> different elements then? I would implement to give the hashcode of the
> DB primary key as a result to hashcode(), so there will be the same
> has for two POJO's from the DB.

Equal hash values are uncritical for the functionality, because hash
collisions "only" influence the performance (which of-course may make
the hash-map unusable for a badly-chosen hash function). I assume that
your question actually refers to: May there be equal elements in the
viewer according to the IElementComparer query? The answer is: No,
because there exists the implied assumption that every element is
unique.

HTH & Greeetings from Bremen,

Daniel Krügler
Previous Topic:Maintaining a TreeView expansion state after setInput()
Next Topic:SWT applet. I don't see anything. Please help!
Goto Forum:
  


Current Time: Fri Apr 26 10:12:19 GMT 2024

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

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

Back to the top