1 11 12 package org.eclipse.ui.internal.actions; 13 14 import org.eclipse.core.runtime.Assert; 15 import org.eclipse.core.runtime.IAdaptable; 16 import org.eclipse.jface.action.Action; 17 import org.eclipse.jface.window.Window; 18 import org.eclipse.ui.IPerspectiveDescriptor; 19 import org.eclipse.ui.IWorkbench; 20 import org.eclipse.ui.IWorkbenchWindow; 21 import org.eclipse.ui.WorkbenchException; 22 import org.eclipse.ui.actions.ActionFactory; 23 import org.eclipse.ui.internal.IWorkbenchGraphicConstants; 24 import org.eclipse.ui.internal.Workbench; 25 import org.eclipse.ui.internal.WorkbenchImages; 26 import org.eclipse.ui.internal.WorkbenchMessages; 27 import org.eclipse.ui.internal.WorkbenchPlugin; 28 import org.eclipse.ui.internal.dialogs.SelectPerspectiveDialog; 29 30 35 public class OpenPerspectiveDialogAction extends Action implements 36 ActionFactory.IWorkbenchAction { 37 38 private IWorkbenchWindow workbenchWindow; 39 40 45 public OpenPerspectiveDialogAction(IWorkbenchWindow window) { 46 Assert.isNotNull(window); 47 this.workbenchWindow = window; 48 setText(WorkbenchMessages.OpenPerspectiveDialogAction_text); 49 setToolTipText(WorkbenchMessages.OpenPerspectiveDialogAction_tooltip); 50 setImageDescriptor(WorkbenchImages.getImageDescriptor( 51 IWorkbenchGraphicConstants.IMG_ETOOL_NEW_PAGE)); 52 } 53 54 59 public void run() { 60 if (workbenchWindow == null) { 61 return; 62 } 63 SelectPerspectiveDialog dlg = new SelectPerspectiveDialog(workbenchWindow 64 .getShell(), workbenchWindow.getWorkbench().getPerspectiveRegistry()); 65 dlg.open(); 66 if (dlg.getReturnCode() == Window.CANCEL) { 67 return; 68 } 69 IPerspectiveDescriptor desc = dlg.getSelection(); 70 if (desc != null) { 71 try { 72 IWorkbench workbench = workbenchWindow.getWorkbench(); 73 IAdaptable input = ((Workbench) workbench) 74 .getDefaultPageInput(); 75 workbenchWindow.openPage(desc.getId(), input); 76 } catch (WorkbenchException e) { 77 WorkbenchPlugin.log("Error opening perspective ", e); } 79 } 80 } 81 82 85 public void dispose() { 86 workbenchWindow = null; 87 } 88 } 89 | Popular Tags |