Set Selection on Tree Viewer [message #644089] |
Thu, 09 December 2010 07:45  |
Eclipse User |
|
|
|
Hi,
We display a tree viewer, in which we need to select a particular node by default.
The tree when displayed shows only the root node.
We tried using tree paths by,
we constructed the tree path, using createChildPath and got a successfull tree path and used the below methods...
thisTreeViewer.setExpandedState(prevPath, true); --> wasn't working
thisTreeViewer.setExpandedTreePaths(prevPath); --> wasn't working
thisTreeViewer.reveal(prevPath); ---> wasn't working
we tried
StructuredSelection structuredSelections = new StructuredSelection(selectionArray);
thisTreeViewer.setSelection(structuredSelections, true);
which was also not working in our case..
Is there something we are missing here...
only thisTreeViewer.expandAll() is working...
Regards,
Aravind
|
|
|
|
|
Re: Set Selection on Tree Viewer [message #1096394 is a reply to message #644089] |
Wed, 28 August 2013 06:30  |
Eclipse User |
|
|
|
//my own content provider class
MyTreeContent myContent =new MyTreeContent("parent5","child1ofparent5");
//get the parent element of tree viewer one by one and looping through it
for (Object item : ((ITreeContentProvider) treeViewer.getContentProvider()).getElements(treeViewer.getInput())) {
//get the children of incoming parent element and looping through it
Object[] contents = ((ITreeContentProvider) treeViewer.getContentProvider()).getChildren(item);
for (Object content : contents) {
//checks with my over rided equals method
if (content.equals(myContent))
//expand the particular child
treeViewer.expandToLevel(content, AbstractTreeViewer.ALL_LEVELS);
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.04606 seconds