Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Set Selection on Tree Viewer(We aren't able to select a particular item on a tree viewer)
Set Selection on Tree Viewer [message #644089] Thu, 09 December 2010 12:45 Go to next message
Aravindhan Annamalai is currently offline Aravindhan AnnamalaiFriend
Messages: 89
Registered: July 2009
Location: Chennai
Member
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 #644104 is a reply to message #644089] Thu, 09 December 2010 14:28 Go to previous messageGo to next message
T. Wilhelm is currently offline T. WilhelmFriend
Messages: 129
Registered: July 2009
Senior Member
Hi,

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
Re: Set Selection on Tree Viewer [message #644107 is a reply to message #644089] Thu, 09 December 2010 14:33 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 2010-12-09 13:45, Aravindhan.A wrote:
> 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
Re: Set Selection on Tree Viewer [message #1096394 is a reply to message #644089] Wed, 28 August 2013 10:30 Go to previous message
dhrumil shah is currently offline dhrumil shahFriend
Messages: 1
Registered: August 2013
Junior Member
//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);
}
}
Previous Topic:how to add a double-click listener on TableViewer column header
Next Topic:Embedding images in a org.eclipse.ui.editors.text.TextEditor
Goto Forum:
  


Current Time: Tue Apr 23 11:52:17 GMT 2024

Powered by FUDForum. Page generated in 0.03161 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top