1

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Joel
  • 473
  • 2
  • 7
  • 22

2 Answers2

1

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.
Arye Shemesh
  • 582
  • 7
  • 20
1
  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.
Dirk Fauth
  • 4,128
  • 2
  • 13
  • 23
  • Thanks, I've already implemented lazy loading and use the same approach. But I faced new problem regarding sorting. I've update my question. Your help will be really appreciated – Joel May 06 '16 at 22:14
  • The most important fact to notice is that you need to consider two comparator for tree sorting. One to bring the tree in the right order one for the content. It sounds like your comparator only checks the content and doesn't respect the tree hierarchy and therefore breaks the tree structure. But without further information I can't tell. I would also suggest to create a new question if that doesn't help. – Dirk Fauth May 07 '16 at 06:15
  • I've created a new question, because I almost give up. I have this problem even with the example code. http://stackoverflow.com/questions/37105593/sorting-of-tree-implemented-with-nattable – Joel May 08 '16 at 22:44