I try to add a new element to my Treeviewer. When I add a subelement everything works fine. But I don't know how I can get the rootelement of my treeviewer to use it as parent for new root elements. I tried something like treeviewer.add(null,element)
and treeviwer.add(treeviwer.getTree(),element)
but nothing seems to work. Whats the best approach to add new root elements ?
Asked
Active
Viewed 1,783 times
4

Johnny000
- 2,058
- 5
- 30
- 59
-
2`treeviewer.add(treeviewer.getInput(), element)` might work – greg-449 Aug 29 '13 at 14:09
-
@greg-449 Why don't you move your comment to an answer and maybe add a link to the javadoc? – Baz Aug 30 '13 at 08:23
-
Likeiwse Thank You, this was driving me crazy! – Duncan Krebs Aug 15 '14 at 14:25
1 Answers
5
treeviewer.add(treeviewer.getInput(), element)
should work. The getInput()
value is the root element of the tree.
From the AbstractTreeViewer
comments:
This method should be called (by the content provider) when a single element has been added to the model, in order to cause the viewer to accurately reflect the model. This method only affects the viewer, not the model.
So be sure to update your model!

greg-449
- 109,219
- 232
- 102
- 145