本文介绍了从另一个插件获取RCP中的TreeViewer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在使用Eclipse-RCP插件。还有一个带有TreeViewer的插件,我想从插件中选择一个项目。我不知道如何访问它,甚至有可能吗?

I'm working at a Plugin for a Eclipse-RCP. There is another Plugin with a TreeViewer and I want to select an Item from my Plugin. I don't know how to get access it, is this even possible?

我认为可以通过以下方式获得正确的视图:

I think can get the correct view with:

IViewReference home;
    IViewReference [] viewRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
    for (int i = 0; i < viewRefs.length; i++) {
        if(viewRefs[i].getId()==myid){
            home = viewRefs[i];
            break;
        }
    }

但是家不是TreeViewer,我无法投射它。如何获得TreeViewer?

But home is not a TreeViewer and I cant cast it. How can I get the TreeViewer?

home.getTreeViewer() //Doesn't work cause of casting issues

我是rcp的新手,所以我很乐意提供一些解释。

I am a newbie to rcp, so I would be nice for some explanation.

推荐答案

您需要使用以下视图找到视图:

You need to find your view using:

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

IViewPart viewPart = page.findView("your view id");

然后可以将视图部分转换为视图类,并调用在该类上编写的方法:

You can then cast the view part to your view class and call a method that you write on that class:

if (viewPart != null) {
   MyViewClass myViewPart = (MyViewClass)viewPart;

   myViewPart.getTreeViewer();
}

其中 MyViewClass 是您的 ViewPart 类。您将必须编写 getTreeViewer 方法。

where MyViewClass is your ViewPart class. You will have to write the getTreeViewer method.

如果视图当前未打开,则可以使用 showView

If the view is not currently open you can use showView:

viewPart = page.showView("your view id");

这篇关于从另一个插件获取RCP中的TreeViewer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 03:59