Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get active perspective name in Eclipse plugin development

I am very new to Eclipse plugin development. I want to get (access) the active perspective name using Java. How do I do that?

like image 461
user964147 Avatar asked Mar 23 '12 11:03

user964147


People also ask

How do I open perspective in Eclipse?

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.

Which is the valid set of perspectives in Eclipse?

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.

Which determines the visible actions views and view layout within the Eclipse window?

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.


2 Answers

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.

like image 140
katsharp Avatar answered Sep 30 '22 09:09

katsharp


Have a look at "Using Perspectives in the Eclipse UI".

If you have access to an object of type IWorkbenchWindow:

window.getActivePage().getPerspective().getLabel()
like image 42
Heinrich Avatar answered Sep 30 '22 09:09

Heinrich