Same child, different parents in a TreeViewer

73 Views Asked by At

I have a JFace TreeViewer where the structure is such that a child can have several parents.

When selecting a child in the viewer, I want to get the parent of that selection.

Example, with the following structure:

- parent1
    - child
- parent2
    - child

When the bottom row is selected, I want to retrieve parent2, but child.getParent() only gives me the first occurrence of a parent, and does not take which branch I selected in the tree.

2

There are 2 best solutions below

0
greg-449 On

The Tree Viewer model doesn't support this.

You will have to add additional methods to your content provider class to return the additional parents.

0
Shashwat On

Create one marker interface and make all root to implement that interface and on run time add different root model.