Programmatically showing a View from an Eclipse Plug-in

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.


Solution 1:

You are probably looking for this:

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("viewId");

Solution 2:

If called from handler of a command

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

would be better, as I know.

Solution 3:

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.