How can I select an item in a tree programmatically? [message #523781] |
Mon, 29 March 2010 05:58  |
Eclipse User |
|
|
|
Hello
I have a search dialog that I open from a CNF tree, which is populated with entries from the model that match the search string. When one of the entries is selected, I want the CNF tree to expand and highlight the item.
I have seen this behaviour in the IDE (though I can't recall a specific example!), so I know it's possible. Despite searching on a variety of keywords, I still haven't found a solution.
If anyone can help, I would be really grateful.
BTW, I'm not using a viewer filter for two reasons:
1. I never managed to figure out how to filter a tree!
2. If I did manage to figure out how to do it, I assume that I would end up with a list of items matching the search string, but I need to see the selected item in its tree context .
Regards, John
|
|
|
|
Re: How can I select an item in a tree programmatically? [message #851075 is a reply to message #851061] |
Fri, 20 April 2012 12:16  |
Eclipse User |
|
|
|
Ok, this one was fairly easy ;-/
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
if (page != null) {
IViewPart view = page.findView(navigatorViewId);
if (view != null && view instanceof CommonNavigator) {
CommonNavigator cn = (CommonNavigator) view;
cn.getCommonViewer().setSelection(new StructuredSelection(objToSelect));
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.04923 seconds