/* (non-Javadoc) * @see PerspectiveMenu#run(IPerspectiveDescriptor) */ protected void run(IPerspectiveDescriptor desc) { // IPreferenceStore store = PrefUtil.getInternalPreferenceStore(); // int mode = store.getInt(IPreferenceConstants.OPEN_PERSP_MODE); int mode = IPreferenceConstants.OPM_ACTIVE_PAGE; IWorkbenchPage page = getWindow().getActivePage(); IPerspectiveDescriptor persp = null; if (page != null) { persp = page.getPerspective(); } // Only open a new window if user preference is set and the window // has an active perspective. if (IPreferenceConstants.OPM_NEW_WINDOW == mode && persp != null) { try { IWorkbench workbench = getWindow().getWorkbench(); IAdaptable input = ((Workbench) workbench).getDefaultPageInput(); workbench.openWorkbenchWindow(desc.getId(), input); } catch (WorkbenchException e) { handleWorkbenchException(e); } } else { if (page != null) { page.setPerspective(desc); } else { try { IWorkbench workbench = getWindow().getWorkbench(); IAdaptable input = ((Workbench) workbench).getDefaultPageInput(); getWindow().openPage(desc.getId(), input); } catch (WorkbenchException e) { handleWorkbenchException(e); } } } }
boolean openPerspective( final String perspId, final IAdaptable input, final IWorkbench workbench, final IPreferenceStore store, final ILog logger) { try { // Verify the requested perspective ID IPerspectiveRegistry reg = workbench.getPerspectiveRegistry(); IPerspectiveDescriptor perspective = reg.findPerspectiveWithId(perspId); if (perspective == null) { logger.log(statusFactory.error("Unable to open perspective: " + perspId)); return false; } // Get "Open Behavior" preference. String pref = store.getString(IWorkbenchPreferenceConstants.OPEN_NEW_PERSPECTIVE); // Implement open behavior. if (pref.equals(IWorkbenchPreferenceConstants.OPEN_PERSPECTIVE_WINDOW)) { workbench.openWorkbenchWindow(perspId, input); } else if (pref.equals(IWorkbenchPreferenceConstants.OPEN_PERSPECTIVE_REPLACE)) { IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); IWorkbenchPage activePage = window.getActivePage(); if (activePage != null) { activePage.setPerspective(perspective); } else { window.openPage(perspId, input); } } Shell shell = workbench.getActiveWorkbenchWindow().getShell(); shell.setMinimized(false); shell.forceActive(); logger.log(statusFactory.info("Opened perspective: " + perspId)); return true; } catch (WorkbenchException e) { logger.log(statusFactory.error("Error opening perspective: " + e.getMessage(), e)); return false; } }