How to get the active name of a perspective in Eclipse plugin development
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.
+12
source to share
See Using Perspective in Eclipse User Interface . "
If you have access to an object of type IWorkbenchWindow :
window.getActivePage().getPerspective().getLabel()
+1
source to share
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());
0
source to share