1 11 package org.eclipse.ui.internal; 12 13 import org.eclipse.core.runtime.IAdaptable; 14 import org.eclipse.jface.dialogs.ErrorDialog; 15 import org.eclipse.jface.preference.IPreferenceStore; 16 import org.eclipse.ui.IPerspectiveDescriptor; 17 import org.eclipse.ui.IWorkbench; 18 import org.eclipse.ui.IWorkbenchPage; 19 import org.eclipse.ui.IWorkbenchWindow; 20 import org.eclipse.ui.WorkbenchException; 21 import org.eclipse.ui.actions.PerspectiveMenu; 22 import org.eclipse.ui.internal.util.PrefUtil; 23 24 28 public class ChangeToPerspectiveMenu extends PerspectiveMenu { 29 30 35 public ChangeToPerspectiveMenu(IWorkbenchWindow window, String id) { 36 super(window, id); 37 ((WorkbenchWindow) window) 39 .addSubmenu(WorkbenchWindow.OPEN_PERSPECTIVE_SUBMENU); 40 showActive(true); 41 } 42 43 50 66 67 70 protected void run(IPerspectiveDescriptor desc) { 71 IPreferenceStore store = PrefUtil.getInternalPreferenceStore(); 72 int mode = store.getInt(IPreferenceConstants.OPEN_PERSP_MODE); 73 IWorkbenchPage page = getWindow().getActivePage(); 74 IPerspectiveDescriptor persp = null; 75 if (page != null) { 76 persp = page.getPerspective(); 77 } 78 79 if (IPreferenceConstants.OPM_NEW_WINDOW == mode && persp != null) { 82 try { 83 IWorkbench workbench = getWindow().getWorkbench(); 84 IAdaptable input = ((Workbench) workbench) 85 .getDefaultPageInput(); 86 workbench.openWorkbenchWindow(desc.getId(), input); 87 } catch (WorkbenchException e) { 88 handleWorkbenchException(e); 89 } 90 } else { 91 if (page != null) { 92 page.setPerspective(desc); 93 } else { 94 try { 95 IWorkbench workbench = getWindow().getWorkbench(); 96 IAdaptable input = ((Workbench) workbench) 97 .getDefaultPageInput(); 98 getWindow().openPage(desc.getId(), input); 99 } catch (WorkbenchException e) { 100 handleWorkbenchException(e); 101 } 102 } 103 } 104 } 105 106 109 private void handleWorkbenchException(WorkbenchException e) { 110 ErrorDialog.openError(getWindow().getShell(), WorkbenchMessages.ChangeToPerspectiveMenu_errorTitle, 111 e.getMessage(), e.getStatus()); 112 } 113 } 114 | Popular Tags |