KickJava   Java API By Example, From Geeks To Geeks.

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


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 page creation in the workbench.
23  * <p>
24  * An <code>OpenNewPageMenu</code> is used to populate a menu with
25  * "Open Page" 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 page 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 Workbench no longer exposes the concept of "pages" in the
39  * user ui model. See IWorkbench.showPerspective methods.
40  */

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

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

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

76     protected void run(IPerspectiveDescriptor desc) {
77         // Verify page input.
78
if (pageInput == null) {
79             StatusUtil.handleStatus(
80                     WorkbenchMessages.OpenNewPageMenu_dialogTitle + ": " + //$NON-NLS-1$
81
WorkbenchMessages.OpenNewPageMenu_unknownPageInput,
82                     StatusManager.SHOW);
83             return;
84         }
85
86         // Open the page.
87
try {
88             getWindow().openPage(desc.getId(), pageInput);
89         } catch (WorkbenchException e) {
90             StatusUtil.handleStatus(
91                     WorkbenchMessages.OpenNewPageMenu_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