How to select a treeview node like a click of mouse to update properties view

白昼怎懂夜的黑 提交于 2019-12-11 19:05:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!