1 11 package org.eclipse.ui.actions; 12 13 import org.eclipse.core.runtime.IAdaptable; 14 import org.eclipse.jface.action.Action; 15 import org.eclipse.ui.IWorkbenchPage; 16 import org.eclipse.ui.IWorkbenchWindow; 17 import org.eclipse.ui.WorkbenchException; 18 import org.eclipse.ui.internal.IWorkbenchHelpContextIds; 19 import org.eclipse.ui.internal.Workbench; 20 import org.eclipse.ui.internal.WorkbenchMessages; 21 import org.eclipse.ui.internal.misc.StatusUtil; 22 import org.eclipse.ui.statushandlers.StatusManager; 23 24 31 public class OpenInNewWindowAction extends Action implements 32 ActionFactory.IWorkbenchAction { 33 34 38 private IWorkbenchWindow workbenchWindow; 39 40 private IAdaptable pageInput; 41 42 49 public OpenInNewWindowAction(IWorkbenchWindow window) { 50 this(window, ((Workbench) window.getWorkbench()).getDefaultPageInput()); 51 setActionDefinitionId("org.eclipse.ui.window.newWindow"); } 53 54 60 public OpenInNewWindowAction(IWorkbenchWindow window, IAdaptable input) { 61 super(WorkbenchMessages.OpenInNewWindowAction_text); 62 if (window == null) { 63 throw new IllegalArgumentException (); 64 } 65 this.workbenchWindow = window; 66 setToolTipText(WorkbenchMessages.OpenInNewWindowAction_toolTip); 68 pageInput = input; 69 window.getWorkbench().getHelpSystem().setHelp(this, 70 IWorkbenchHelpContextIds.OPEN_NEW_WINDOW_ACTION); 71 } 72 73 78 public void setPageInput(IAdaptable input) { 79 pageInput = input; 80 } 81 82 89 public void run() { 90 if (workbenchWindow == null) { 91 return; 93 } 94 try { 95 String perspId; 96 97 IWorkbenchPage page = workbenchWindow.getActivePage(); 98 if (page != null && page.getPerspective() != null) { 99 perspId = page.getPerspective().getId(); 100 } else { 101 perspId = workbenchWindow.getWorkbench() 102 .getPerspectiveRegistry().getDefaultPerspective(); 103 } 104 105 workbenchWindow.getWorkbench().openWorkbenchWindow(perspId, 106 pageInput); 107 } catch (WorkbenchException e) { 108 StatusUtil.handleStatus(e.getStatus(), 109 WorkbenchMessages.OpenInNewWindowAction_errorTitle 110 + ": " + e.getMessage(), StatusManager.SHOW); 112 } 113 } 114 115 119 public void dispose() { 120 workbenchWindow = null; 121 } 122 } 123 | Popular Tags |