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 ?

有帮助吗?

解决方案

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!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top