How do we retrieve all the children of a selected item in JFace
TreeViewer
? I am able to get the parent of a selected item, but not the children.
You normally use the tree content provider to get both the children and the parent of a selection in the tree viewer.
IStructuredSelection sel = treeViewer.getStructuredSelection();
Object selElement = sel.getFirstElement();
ITreeContentProvider provider = (ITreeContentProvider)treeViewer.getContentProvider();
Object [] children = provider.getChildren(selElement);
Object parent = provider.getParent(selElement);
Note: When using TreeViewer
you should avoid looking at the Tree
or TreeItem
controls that TreeViewer
uses internally.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.