0

lets consider below Treeviewer data,

Project
->package1
->package2
->->class1

The Viewer has been expanded to level-2. But, how to know that to what level the viewer has been expanded.

I am aware of setting the viewer to expand to a particular level by expandToLevel() method.

Is there a way to get the maximum level to which the viewer has been expanded?

Paul-E
  • 91
  • 12

1 Answers1

1

I don't think there is a simple way to get this information.

You could use the getExpandedTreePaths method and find the longest TreePath that is returned. But note that the JavaDoc for this says:

Returns a list of tree paths corresponding to expanded nodes in this viewer's tree, including currently hidden ones that are marked as expanded but are under a collapsed ancestor.

which might not be what you want.

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • Thanks Greg for the reply – Paul-E Jul 16 '15 at 13:15
  • Greg, is there a way to maintain expanded/collapsed state in Eclipse TreeViewer, programatically? When, i call refresh() method, the items are collapsed – Paul-E Jul 16 '15 at 13:36
  • Use `getExpandedTreePaths` or `getExpandedElements` before and `setExpandedTreePaths` or `setExpandedElements` afterwards. – greg-449 Jul 16 '15 at 13:43