I am very new to Eclipse plugin development. I want to get (access) the active perspective name using Java. How do I do that?
In top right corner of the Eclipse window, click the Open Perspective icon (Figure 4-1). The Open Perspective context menu appears (Figure 4-2). The Open Perspective dialog box appears (Figure 4-3). Select Mission Control and click OK.
The default perspective is called java. An eclipse window can have multiple perspectives open in it but only one perspective is active at any point of time. A user can switch between open perspectives or open a new perspective.
A perspective determines the visible actions, views, and view layout within the window. There are many types of perspective, and each one defines the layout in a different way.
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
IWorkbenchPage page = win.getActivePage();
IPerspectiveDescriptor perspective = page.getPerspective();
String label = perspective.getLabel();
You can also access the description and the id of the perspective using the methods on IPerspectiveDescriptor.
Have a look at "Using Perspectives in the Eclipse UI".
If you have access to an object of type IWorkbenchWindow:
window.getActivePage().getPerspective().getLabel()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With