Joel
Joel

Reputation: 473

Tree implementation using NatTable

I try to switch from JFace TreeViewer to NatTable. Unfortunately I didn't find a lot of documentation about implementing trees with NatTable. So I have some questions

  1. With TreeViewer I used setInput() to provide new input. How can I achieve the same with NatTable? Is it a proper way to call clear() and addAll() on underlying data source List? (I use GlazedLists)

  2. I use described clear()/addAll() way to pass new data after querying a database. And after it expanded state of tree is lost, all nodes are colapsed. With JFace TreeViewer I used getExpandedElements() / setExpandedElements() to keep expanded state. Is there something similar available in NatTable?

  3. Is it possible to load child tree nodes only when parent node is clicked? I can't build beforehand all tree data because I can have cycles in it (well, strictly speaking my data is not really a tree, but it's convenient to display it like a tree)

UPD: Not sure if I should ask it here or create separate question

  1. I have problems with sorting. I've found similar discussion here https://www.eclipse.org/forums/index.php?t=msg&th=489524 but I still don't have deep understanding.

My problem: after sorting on any column other than 'tree' column child nodes can move to invalid parent. Though the order of elements is correct on all levels of hierarchy. I use SortableTreeComparator and as treeComparator I use my custom comparator (not GlazedLists.beanPropertyComparator as in example). What can be wrong here?

Upvotes: 1

Views: 1172

Answers (2)

Dirk Fauth
Dirk Fauth

Reputation: 4231

  1. Yes it is fine and even recommended to do this. NatTable visualizes data. It doesn't care where it comes from, at least if an IDataProvider is able to provide the data in a two-dimensional way. Because of our abstraction levels, we don't have a setInput() in NatTable. With 1.4 we opened the API to be able to set the IDataProvider to the DataLayer at runtime, which is something similar.
  2. You need to implement an ExpansionModel that remembers the expansion state. In NatTable we have the same in the GroupByExpansionModel because of the same reaons.
  3. I haven't done that myself yet in NatTable, but I have seen this often. So yes it is possible. IIRC you need to implement a custom ITreeRowModel that performs the lazy loading on expand if necessary. I would suggest to extend GlazedListTreeRowModel and check the various expand methods that you need to override.

Upvotes: 1

Arye Shemesh
Arye Shemesh

Reputation: 679

First, you can look in NatTable examples and look at the way the tree is implemented.

  1. Yes, the data source list is the place to put and manage your data objects.
  2. In order to manage the expanded state you can use ca.odell.glazedlists.TreeList.ExpansionModel which is part of the TreeList you use as input.
  3. As far as I know one of the major advantages of NatTable is the ability to load data on demand, only when it should become visible. This is the default behavior.

Upvotes: 1

Related Questions