Search code examples
javaeclipseeclipse-plugineclipse-pde

How to get element by ID in PDE?


for example my View has an id

public static final String ID = "examplePlugin.views.SampleView"

How do I get an instance of this View (or any other thing in eclipse ) by id ?


Solution

  • For views you use methods on the current workbench page IWorkbenchPage. You can find the page with:

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

    (this must be called from a plugin with the workbench running).

    You can find an existing view with:

    page.findView(id);
    

    and create and show a view with:

    page.showView(id);