How to get the active name of a perspective in Eclipse plugin development

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


source to share

3 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 perspective ID using the IPerspectiveDescriptor methods.



See Using Perspective in Eclipse User Interface . "

If you have access to an object of type IWorkbenchWindow :





The new E4 way builds on . EModelService

Just like:

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());




All Articles