KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > actions > OpenInNewWindowAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
25  * Opens a new window. The initial perspective
26  * for the new window will be the same type as
27  * the active perspective in the window which this
28  * action is running in. The default input for the
29  * new window's page is application-specific.
30  */

31 public class OpenInNewWindowAction extends Action implements
32         ActionFactory.IWorkbenchAction {
33
34     /**
35      * The workbench window; or <code>null</code> if this
36      * action has been <code>dispose</code>d.
37      */

38     private IWorkbenchWindow workbenchWindow;
39
40     private IAdaptable pageInput;
41
42     /**
43      * Creates a new <code>OpenInNewWindowAction</code>. Sets
44      * the new window page's input to be an application-specific
45      * default.
46      *
47      * @param window the workbench window containing this action
48      */

49     public OpenInNewWindowAction(IWorkbenchWindow window) {
50         this(window, ((Workbench) window.getWorkbench()).getDefaultPageInput());
51         setActionDefinitionId("org.eclipse.ui.window.newWindow"); //$NON-NLS-1$
52
}
53
54     /**
55      * Creates a new <code>OpenInNewWindowAction</code>.
56      *
57      * @param window the workbench window containing this action
58      * @param input the input for the new window's page
59      */

60     public OpenInNewWindowAction(IWorkbenchWindow window, IAdaptable input) {
61         super(WorkbenchMessages.OpenInNewWindowAction_text);
62         if (window == null) {
63             throw new IllegalArgumentException JavaDoc();
64         }
65         this.workbenchWindow = window;
66         // @issue missing action id
67
setToolTipText(WorkbenchMessages.OpenInNewWindowAction_toolTip);
68         pageInput = input;
69         window.getWorkbench().getHelpSystem().setHelp(this,
70                 IWorkbenchHelpContextIds.OPEN_NEW_WINDOW_ACTION);
71     }
72
73     /**
74      * Set the input to use for the new window's page.
75      *
76      * @param input the input
77      */

78     public void setPageInput(IAdaptable input) {
79         pageInput = input;
80     }
81
82     /**
83      * The implementation of this <code>IAction</code> method
84      * opens a new window. The initial perspective
85      * for the new window will be the same type as
86      * the active perspective in the window which this
87      * action is running in.
88      */

89     public void run() {
90         if (workbenchWindow == null) {
91             // action has been disposed
92
return;
93         }
94         try {
95             String JavaDoc 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(), //$NON-NLS-1$
111
StatusManager.SHOW);
112         }
113     }
114
115     /* (non-Javadoc)
116      * Method declared on ActionFactory.IWorkbenchAction.
117      * @since 3.0
118      */

119     public void dispose() {
120         workbenchWindow = null;
121     }
122 }
123
Popular Tags