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 07:45 Go to next message
Aravindhan Annamalai is currently offline Aravindhan Annamalai
Messages: 88
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 09:28 Go to previous messageGo to next message
T. Wilhelm is currently offline T. Wilhelm
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 09:33 Go to previous message
Daniel Krügler is currently offline Daniel Krügler
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
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: Sun May 19 02:44:12 EDT 2013

Powered by FUDForum. Page generated in 0.01426 seconds