Reputation: 333
I'm doing my first RCP example using the TreeViewer
for directory browsing.
My work did start from the example http://www.ibm.com/developerworks/opensource/library/os-ecgui1/
For the TreeViewer
of file entries I want to make the last selection persistent
to open the viewer by the same selection next time.
From the selected file I catched the path and store/retrieve this single string.
On reopening I traverse the ITreeContentProvider
and find the corresponding
File node (and capture the nodes in between).
Next I use
window.getTree().setSelection(new StructuredSelection(target));
with target as a list of Files holding the path.
This works for the top level directories under C:
But restoring a deeper path fails. The next level is initially not
expanded and fails in the AbstractTreeViewer.setSelectionToWidget()
.
My feeling is that I do not handle the setSelection()
parameter well
but I found no suitable example.
Do you have a simple example for me showing how to restore such a path selection?
thanks in advance
Wolfgang R.
Upvotes: 0
Views: 469
Reputation: 333
I've found it. The used example code has a small bug.
public class FileTreeContentProvider implements ITreeContentProvider
{
...
public Object getParent(Object element)
{
// wrong return ((File)element).getParent();
return ((File)element).getParentFile();
}
Upvotes: 1