KickJava   Java API By Example, From Geeks To Geeks.

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


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.ui.IPerspectiveDescriptor;
15 import org.eclipse.ui.IWorkbenchWindow;
16 import org.eclipse.ui.WorkbenchException;
17 import org.eclipse.ui.internal.WorkbenchMessages;
18 import org.eclipse.ui.internal.misc.StatusUtil;
19 import org.eclipse.ui.statushandlers.StatusManager;
20
21 /**
22  * A menu for window creation in the workbench.
23  * <p>
24  * An <code>OpenNewWindowMenu</code> is used to populate a menu with
25  * "Open Window" actions. One item is added for each shortcut perspective,
26  * as defined by the product ini. If the user selects one of these items a new window is
27  * created in the workbench with the given perspective.
28  * </p><p>
29  * The visible perspectives within the menu may also be updated dynamically to
30  * reflect user preference.
31  * </p><p>
32  * The input for the page is determined by the value of <code>pageInput</code>.
33  * The input should be passed into the constructor of this class or set using
34  * the <code>setPageInput</code> method.
35  * </p><p>
36  * This class may be instantiated; it is not intended to be subclassed.
37  * </p>
38  * @deprecated See IWorkbench.showPerspective methods.
39  */

40 public class OpenNewWindowMenu extends PerspectiveMenu {
41     private IAdaptable pageInput;
42
43     /**
44      * Constructs a new instance of <code>OpenNewPageMenu</code>.
45      * <p>
46      * If this method is used be sure to set the page input by invoking
47      * <code>setPageInput</code>. The page input is required when the user
48      * selects an item in the menu. At that point the menu will attempt to
49      * open a new page with the selected perspective and page input. If there
50      * is no page input an error dialog will be opened.
51      * </p>
52      *
53      * @param window the window where a new page is created if an item within
54      * the menu is selected
55      */

56     public OpenNewWindowMenu(IWorkbenchWindow window) {
57         this(window, null);
58     }
59
60     /**
61      * Constructs a new instance of <code>OpenNewPageMenu</code>.
62      *
63      * @param window the window where a new page is created if an item within
64      * the menu is selected
65      * @param input the page input
66      */

67     public OpenNewWindowMenu(IWorkbenchWindow window, IAdaptable input) {
68         super(window, "Open New Page Menu");//$NON-NLS-1$
69
this.pageInput = input;
70     }
71
72     /* (non-Javadoc)
73      * Opens a new window with a particular perspective and input.
74      */

75     protected void run(IPerspectiveDescriptor desc) {
76         // Verify page input.
77
if (pageInput == null) {
78             StatusUtil.handleStatus(
79                     WorkbenchMessages.OpenNewWindowMenu_dialogTitle + ": " + //$NON-NLS-1$
80
WorkbenchMessages.OpenNewWindowMenu_unknownInput,
81                     StatusManager.SHOW);
82             return;
83         }
84
85         // Open the page.
86
try {
87             getWindow().getWorkbench().openWorkbenchWindow(desc.getId(),
88                     pageInput);
89         } catch (WorkbenchException e) {
90             StatusUtil.handleStatus(
91                     WorkbenchMessages.OpenNewWindowMenu_dialogTitle + ": " + //$NON-NLS-1$
92
e.getMessage(), e, StatusManager.SHOW);
93         }
94     }
95
96     /**
97      * Sets the page input.
98      *
99      * @param input the page input
100      */

101     public void setPageInput(IAdaptable input) {
102         pageInput = input;
103     }
104 }
105
Popular Tags