Kevin King
Kevin King

Reputation: 567

java swt jface TreeViewer expanding from node

How can I expand the node to its root node?

So I have this method to expand its parent node recursively

private void expand( Object object ) {
    if ( object.getParent() != null ) {
        tree.setExpandedState( object.getParent(), true );
        expand( object.getParent() );
    }
}

Upvotes: 1

Views: 319

Answers (1)

greg-449
greg-449

Reputation: 111217

Use the expandToLevel TreeViewer method:

viewer.expandToLevel(element, 1);

element can be your model element (the object your content provider provides) or it can be a TreePath. You may need to call setUseHashlookup(true) on the viewer to speed up element lookup.

Upvotes: 1

Related Questions