Programmatically showing a View from an Eclipse Plug-in
Asked Answered
S

4

33

I have a plug-in to an Eclipse RCP application that has a view. After an event occurs in the RCP application, the plug-in is instantiated, its methods are called to populate the plug-in's model, but I cannot find how to make the view appear without going to the "Show View..." menu.

I would think that there would be something in the workbench singleton that could handle this, but I have not found out how anywhere.

Shakeup answered 5/10, 2008 at 11:0 Comment(0)
F
48

You are probably looking for this:

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("viewId");
Fausta answered 5/10, 2008 at 14:44 Comment(2)
It is important to note that the arg0 can be a view part's VIEW_ID field.Denmark
Where do I put that? I put it in all my classes, but still doesn't work. (I accidentally closed the view within the RCP application)Hygrothermograph
A
20

If called from handler of a command

HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().showView(viewId);

would be better, as I know.

Anton answered 23/3, 2009 at 20:44 Comment(0)
S
5

I found the need to bring the view to the front after it had been opened and pushed to the background. The activate method does the trick.

PlatformUI.getWorkbench()
    .getActiveWorkbenchWindow()
    .getActivePage()
    .activate(workbenchPartToActivate);

NOTE: The workbenchPartToActivate is an instance of IWorkbenchPart.

Solifidian answered 20/5, 2009 at 15:37 Comment(0)
M
0

In e4, the EPartService is responsible for opening Parts. This can also be used to open e3 ViewParts. Instantiate the following class through your IEclipseContext, call the openPart-Method, and you should see the Eclipse internal browser view.

public class Opener {
    @Inject
    EPartService partService;

    public void openPart() {
        MPart part = partService.createPart("org.eclipse.ui.browser.view");
        part.setLabel("Browser");

        partService.showPart(part, PartState.ACTIVATE);
    }
}

Here you can find an example of how this works together with your Application.e4xmi.

Magnate answered 24/3, 2014 at 14:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.