Вопрос

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