0

I would like to show the same data in a SWT/Jface TreeViewer and TableViewer. The question is how to store the data in a good way that both viewers can use the same data?

My raw data are stored in an array:

Id | Level | Type    | Value
1  | 1     | Heading | Heading 1
2  | 2     | Text    | This is a text
3  | 2     | Text    | This is another text
4  | 1     | Heading | Heading 2
5  | 2     | Heading | Heading 2.1
6  | 3     | Heading | Heading 2.2
7  | 4     | Text    | This is more text
...

The TreeViewer shall display the item with type "heading" only:

  • Heading 1
  • Heading 2
    • Heading 2.1
    • Heading 2.2

The TableViewer shall display the values in the same order as stored in the array.

My thoughts:

  • I can store the data in an ArrayList and provide it to the TableViewer by using the default ArrayContentProvider. But than I can't use this ArrayList for the TreeViewer.

  • Or I can store the data with parent-child relation and implement the interface ITreeContentProvider for the use in the TreeViewer. But than I can't use it for the TableViewer.

Can you give me some hint?

Background:

Maybe someone knows the software DOORS. You have an outline view on the left (TreeViewer) and a list in the main view (TableViewer). Both share the same data.

Bastian
  • 438
  • 4
  • 11
  • This is really up to you. You could have one class implementing `ITreeContentProvider` for the tree and another implementing `IStructuredContentProvider` for the table. Both these classes would access the actual data held in another class. – greg-449 Feb 04 '20 at 18:07
  • Ok, I understand that both interfaces deal with the same data. The implementation of each interface depends on the underlaying data model. If the data is stored as an array I have to spent more code into the ITreeContentProvider to implement for example the getChildren method. On the other hand I can store the data in an hierachical manner, but than I have to write more lines of code to implement the IStructuredContentProvider to get all items as a list… Is this correct? – Bastian Feb 04 '20 at 18:42
  • @Bastian Did you get the solution? I am facing similar issue. I already have the TableViewer implementation. I am looking for content set up for TreeViewer. – schaturv Jul 08 '20 at 13:48

0 Answers0