Kevin King
Kevin King

Reputation: 567

JFace TreeViewer to save the state of tree node when expanded/collapsed

How can I persist the state of the collapsed/expanded tree nodes?

I thought of using the addTreeListener to retrieve the expandedTreePaths from a TreeViewer and save that details, which is a TreePath[], by using the IMemento. So I have to transform the TreePath[] to a String.

What is the best way to do this?

Upvotes: 0

Views: 356

Answers (1)

Rüdiger Herrmann
Rüdiger Herrmann

Reputation: 21025

Right, you can use getExpandedTreePaths() to obtain an array of expanded tree paths. I don't see why a TreeListener would be necessary. It is sufficient to get all expanded elements when saving the tree state is requested.

The segments of the TreePath consist of your domain objects, i.e. the ones returned from your content provider. Hence you should choose an approach for serializing and deserializing that is suitable for your domain model.

Upvotes: 3

Related Questions