Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » TreeLayer: Retrieve items lazily does not work properly
TreeLayer: Retrieve items lazily does not work properly [message #1752500] Tue, 24 January 2017 14:19 Go to next message
Marc M is currently offline Marc MFriend
Messages: 5
Registered: June 2014
Location: France
Junior Member
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 #1752512 is a reply to message #1752500] Tue, 24 January 2017 15:18 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Without looking into your code because of missing time for that, I assume there is a mistake in the necessary comparator. You need to think of the tree function in NatTable as a tree styled view of a list. It is not really a tree. Therefore new items are added to the end of the list and the comparator needs to ensure that they are shown at the correct position.
Re: TreeLayer: Retrieve items lazily does not work properly [message #1752515 is a reply to message #1752512] Tue, 24 January 2017 16:02 Go to previous messageGo to next message
Marc M is currently offline Marc MFriend
Messages: 5
Registered: June 2014
Location: France
Junior Member
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:
http://image.prntscr.com/image/edc4fe3021384ac9b42ffa311622cb89.png

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 08:02 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
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.
Previous Topic:Search not working
Next Topic:Focus is not coming out of custom cell editor.
Goto Forum:
  


Current Time: Fri Apr 19 12:52:54 GMT 2024

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

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

Back to the top