Reputation: 739
I am very new to Eclipse plugin development. I want to get (access) the active perspective name using Java. How do I do that?
Upvotes: 6
Views: 7022
Reputation: 4495
The new E4 way relies on the EModelService
.
Simply as:
import javax.inject.Inject;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
@Inject EModelService modelService;
@Inject MWindow window;
MPerspective p = modelService.getActivePerspective(window);
System.out.println("ACTIVE PERSPECTIVE: " + p.getLabel());
Upvotes: 1
Reputation: 2551
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.
Upvotes: 15
Reputation: 408
Have a look at "Using Perspectives in the Eclipse UI".
If you have access to an object of type IWorkbenchWindow:
window.getActivePage().getPerspective().getLabel()
Upvotes: 1