0

I am new to eclipse RCP, well as a matter of fact to java also. Have a very basic question. I have a JFace TreeViewer. I want to expand a particular node in that. The catch is I only have the name of the node. and no information apart from that. I tried using treeItem, compared its string with that of the node name that I have, thus I got the node. I tried expanding it in the contentprovider of the tree. But i am not getting the desired output. When I check it in the log i get that it is expanded but it doesnt show in the viewer. I am performing this in display.asyncExec method in the contentprovider.

I hope the question is clear.

flavio.donze
  • 7,432
  • 9
  • 58
  • 91
Sid
  • 51
  • 1
  • 5
  • What do you mean by "expanding it in the contentprovider"? There's `expandToLevel(Object elementOrTreePath, int level)` method in [TreeViewer](http://help.eclipse.org/indigo/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/jface/viewers/TreeViewer.html), does that work? – Martti Käärik Dec 21 '11 at 21:07
  • I tried it. but then i dont know the level of the node. i tried using treeItem.setexpanded(true). Though it seems to be working sometimes it gives some totally unexpected output, as in, the nodes arent viewed but after one more operation they are visible. can it be a problem with treeViewer.refresh()? What other ways can i refresh a particular node, not the whole tree? – Sid Dec 23 '11 at 08:45

1 Answers1

5

JFace viewers were created so that developers wouldn't have to mess around with SWT widgets and could use higher level API instead. When using JFace's viewer/content provider/label provider you should be in control of what nodes are in your tree (thus when you say you only know the name, I assume you are using SWT Tree directly). You can read about JFace viewers from Eclipse help.

To expand a tree node use expandToLevel(Object elementOrTreePath, int level) method of TreeViewer (the level is relative to the node that is expanded, not the root of the tree).

Martti Käärik
  • 3,601
  • 18
  • 28