0

I am using common navigator framework(CNF) for my project explorer view. I have set the content provider and label provider for the tree viewer. When a data changes internally in my application, i need to update the tree view also(eg. just like adding nodes, deleting nodes).

For this case, i tried to refresh the tree viewer. And the refresh operation works successfully. But after the refresh operation, the tree viewers selection get to the top most parent node in the viewer. But instead, i need the selection on the newly added node or the parent node of the newly added node. How can this be achieved?

2 Answers2

0

You can manually set the selection and reveal it in the tree viewer:

//after the refresh operation
treeViewer.setSelection(new StructuredSelection(newlyAddedNode, true));
Ilya Shinkarenko
  • 2,134
  • 18
  • 35
  • Hi llya, Thnks for your valuable reply. But iam not getting the desired result. When i do refreshing operation, the tree viewer collapse automatically to the root node of the tree and selection is made on the first node of the tree. – Girish Chandran C Jun 14 '12 at 09:22
  • Moreover, i tried to refresh the node on which the update operation takes place by treeViewer.refresh(node,true). But nothing is happening. The node is not getting refreshed. – Girish Chandran C Jun 14 '12 at 09:27
  • check the #equals implementation of the class of newlyAddedNode – Ilya Shinkarenko Jun 14 '12 at 15:02
  • Hi llya, I couldn't understand what you have told. could you please explain it with a snippet? – Girish Chandran C Jun 22 '12 at 03:23
  • @GirishChandranC: Hi Girish, I was also working on the CNF few days back. What I have realized, if you are binding resourceContent with CNF, you dont have to refresh it. It is required only when you are binding custom model with CNF. Now in the scenario of refreshing the tree you have to remember the last selected path. But the this might not work if the sort order within a tree changes. This link will help you for resource based CNF: http://scribbledideas.blogspot.com/ – Priyank Thakkar Aug 21 '12 at 08:56
  • While this link will guide you for non-resource based CNF: http://www.techjava.de/topics/2009/04/eclipse-common-navigator-framework/ – Priyank Thakkar Aug 21 '12 at 08:57
0

Treeviewer requires that you implement hashCode() and equals() on the objects in your Viewer. As well, you should provide an IElementComparer to the Viewer.

Hat tip to the Eclipse forums: http://www.eclipse.org/forums/index.php/t/166563/

Darcy Casselman
  • 2,574
  • 3
  • 24
  • 26