问题
I have a custom outline in my Eclipse plug-in, implemented using class TreeViewer
and I created this outline using this code:
public class MyOutlinePage extends ContentOutlinePage
(...)
Object[] data = (...)
TreeViewer treeViewer = getTreeViewer();
treeViewer.setInput(data);
After set input I need to select one specific element in outline.
For example, I need to select the element data[2]
in the outline.
Im trying to use this code to select the emelent of outline:
treeViewer.setSelection(new StructuredSelection(data[2]));
If I select the outline item using mouse, the outline was selected and the "Properties Views" was updated. The outline item is selected as shown:

But If I select the outline item using the method setSelection
the "Properties Views" was NOT updated and the outline item is selected as shown:

I need to select outline item using code and this selection must update the "Properties View" like the click of mouse does.
回答1:
The gray highlight shows that the outline view is not the active part. The Properties view always shows values from the active part.
You can activate the Outline view with:
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
page.showView(IPageLayout.ID_OUTLINE, null, IWorkbenchPage.VIEW_ACTIVATE);
but note that this will move focus away from whatever part is currently active.
来源:https://stackoverflow.com/questions/29214920/how-to-select-a-treeview-node-like-a-click-of-mouse-to-update-properties-view