Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsSet Selection on Tree Viewer
https://www.eclipse.org/forums/index.php/mv/msg/201623/644089/#msg_644089
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]]>Aravindhan Annamalai2010-12-09T12:45:48-00:00Re: Set Selection on Tree Viewer
https://www.eclipse.org/forums/index.php/mv/msg/201623/644104/#msg_644104
did you try:
this.treeViewer.getTree().showItem( myTreeItem );
maybe this works for you. Otherwise it would be nice if you post some snippet
Greetz
Thomas]]>T. Wilhelm2010-12-09T14:28:48-00:00Re: Set Selection on Tree Viewer
https://www.eclipse.org/forums/index.php/mv/msg/201623/644107/#msg_644107
> 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
>
> StructuredSelection structuredSelections = new
> StructuredSelection(selectionArray);
> thisTreeViewer.setSelection(structuredSelections, true);
>
> which was also not working in our case..
This should work. I assume you did not provide equal items when
constructing the selection object. This can happen, if your objects
types don't override equal/hash correctly. You can make your tree
equality-aware without need to modify your types, if you provide an
IElementComparer to the tree (I think you need to activate useHashLookup
to make that work).
HTH & Greetings from Bremen,
Daniel Krügler]]>Daniel Krügler2010-12-09T14:33:50-00:00Re: Set Selection on Tree Viewer
https://www.eclipse.org/forums/index.php/mv/msg/201623/1096394/#msg_1096394
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);
}
} ]]>dhrumil shah2013-08-28T10:30:51-00:00