Tuesday, August 21, 2007

Showing an Eclipse View Programatically

In eclipse non savable containers are called views . It pretty easy to create a view , all you need to do is to implement an extension - point (org.eclipse.ui.views) and add features to a class . If you want to implement your own view , you can google it you 'll find a number of articles about it .

In this blog entry i tell you how to show/hide an existing view programatically .

Scenario1
: Assuming you have created a view whose view ID is "my.view" and you want to show this view .

Scenario2: You know the view id of some view and you want to show that view programatically.

IWorkbench workbench = PLatformUI.getWorkbench();
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
workbenchWindow.getActivePage().showView("my.view");

// to hide a view

workbenchWindow.getActivePage().hideView("my.view");

PlatformUI is a plugin that can give information about currently active windows and objects in an eclipse session . Its available to us so we use it to get the current workbench window . In eclipse workbench window is the main window . Each window has one or more pages . We get the active page . In the active page we either show or hide the view we are interested in .