0
votes

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;
        }
    }

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

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

3

3 Answers

0
votes

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();
}

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

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

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

You have to cast home to the type of your other view. Then you can get the TreeViewer.

0
votes

You can find the ViewPart directly from your active IWorkbenchPage using IWorkbenchPage#findView(java.lang.String).

If you have the object you want to be selected, get the View's Site, get the Site's selection provider, and then tell the selection provider what should be selected (with a StructuredSelection instance containing the object). This only works if the tree, or whatever is in the part (you shouldn't have to care or know that it's a tree), actually contains the object that you're telling it to select.