如何选择一个树状视图节点,如点击鼠标来更新属性视图(How to select a treeview node like a click of mouse to update properties view)

262 IT屋

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:

enter image description here

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:

enter image description here

I need to select outline item using code and this selection must update the "Properties View" like the click of mouse does.

解决方案

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.

我的Eclipse插件中有一个自定义大纲,使用类 TreeViewer 实现,我使用以下代码创建了这个大纲:



  public class MyOutlinePage extends ContentOutlinePage 
(...)
Object [] data =(...)
TreeViewer treeViewer = getTreeViewer();
treeViewer.setInput(data);


设置输入后,我需要在大纲中选择一个特定的元素。
例如,我需要在大纲中选择元素 data [2] 。



Im尝试使用此代码来选择大纲的引用:



  treeViewer.setSelection(new StructuredSelection(data [2])); 


如果我使用鼠标选择轮廓项,则选中轮廓,并更新属性视图 。大纲项目选择如下所示:





但是,如果我使用方法 setSelection 选择大纲项,则属性视图未更新并选择大纲项,如下所示:





我需要使用代码选择大纲项,此选择必须像鼠标点击一样更新属性视图。


解决方案

灰色高亮显示大纲视图不是活动部分。 属性视图始终显示活动零件的值。



您可以使用以下功能激活大纲视图:



  IWorkbenchPage page = PlatformUI.getWorkbench()getActiveWorkbenchWindow()getActivePage()。; 

page.showView(IPageLayout.ID_OUTLINE,null,IWorkbenchPage.VIEW_ACTIVATE);


但请注意,这将使焦点远离当前活动的任何部分。


本文地址:IT屋 » 如何选择一个树状视图节点,如点击鼠标来更新属性视图