TreeLayer: Retrieve items lazily does not work properly [message #1752500] |
Tue, 24 January 2017 09:19  |
Eclipse User |
|
|
|
Hi there,
I want to use NatTable for a tree. I have a relatively simple Tree element
class TreeElement {
TreeElement parent;
public List<TreeElement> getVisibleChildren() {
... //potentially expensive computation the first time; for my sample code not yet
}
I have implemented the ITreeData interface and use it as second argument of the TreeLayer constructor as in:
new TreeRowModel<TreeElement>(new ITreeData<TreeElement>() {
//Implemented accordingly
}))
As the TreeLayer needs an EventList, I have supplied an event list which only contain root elements at the beginning. As nodes are expanded, they get inserted at the right position in the list according to the tree structure.
The ids are stored in the TreeElement themselves and are starting with 0. They correspond to another extra list of TreeElements where newly expanded elements get added to the end, thus ensuring each element keeps the id even if an element in between gets expanded.
However, in my sample class, instead of
- Root
Depth 1 #1
Depth 2 #1
Depth 3 #1
- Depth 1 #2
- Depth 2 #2
Depth 3 #2
It generates the following tree
- Root
Depth 1 #1
- Depth 1 #2
Depth 2 #2
- Depth 2 #1
Depth 3 #2
Depth 3 #1
It appears that instead of being inserted at the correct position, the expanded item gets appended to the end nontheless, which is strange.
I have marked the line with the problem with the line
// HERE IS THE PROBLEM:
The code can be found at
http://pastebin.com/aQpbwbn2
It is basically a customized TreeGridExample.
Thank you very much in advance
Marc
|
|
|
|
Re: TreeLayer: Retrieve items lazily does not work properly [message #1752515 is a reply to message #1752512] |
Tue, 24 January 2017 11:02   |
Eclipse User |
|
|
|
Ah, yes, thanks for hinting to the comparator. It was indeed the reason for the elements being in the wrong order in the list.
Now it is in the correct order:
[Root, Depth 1 #1, Depth 2 #1, Depth 3 #1, Depth 1 #2, Depth 2 #2, Depth 3 #2]
Even the tree printed to stdout is correct:
- Root
- Depth 1 #1
- Depth 2 #1
Depth 3 #1
- Depth 1 #2
- Depth 2 #2
Depth 3 #2
However, still, the graphical output is wrong: "Depth 1 #2" is put under "Depth 3 #1:

I see that you might not have the time to look into the updated code; maybe s.o. else can:
http://pastebin.com/s1DVRRvr
Maybe you have an idea why this behaviour might occur.
Thank you very much in advance,
Marc
|
|
|
Re: TreeLayer: Retrieve items lazily does not work properly [message #1752565 is a reply to message #1752515] |
Wed, 25 January 2017 03:02  |
Eclipse User |
|
|
|
Well I can't tell in detail. I tried to look at your code example, but with that code format and the lots of anonymous inner classes it is hard to review.
From my point of view you have a basic issue with your lazy loading design. First you want to introduce lazy loading, but you show all nodes initially expanded. Therefore the use of lazy loading is nonsense. So you need to provide an ExpansionModel that is capable of dealing with the expansion state on creating the TreeList.
Another topic is that you assume that the whole list with all nodes is loaded while you are operating on the TreeList. That is somehow strange, as you want to implement lazy loading and typically in a TreeList not all items are available, e.g. when they are collapsed. So you need to rethink your whole list handling logic and read about the transformation logic of GlazedLists. Probably you need to operate on the underlying list and not on the TreeList.
If there might be an additional issue with NatTable layers that not update correctly because of previous issues I can't tell so far.
|
|
|
Powered by
FUDForum. Page generated in 0.09282 seconds