KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > ide > NewWizardDropDownAction


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

11
12 package org.eclipse.ui.internal.ide;
13
14 import org.eclipse.jface.action.Action;
15 import org.eclipse.jface.action.ActionContributionItem;
16 import org.eclipse.jface.action.IAction;
17 import org.eclipse.jface.action.IContributionItem;
18 import org.eclipse.jface.action.IMenuCreator;
19 import org.eclipse.jface.action.MenuManager;
20 import org.eclipse.jface.viewers.ISelection;
21 import org.eclipse.swt.widgets.Control;
22 import org.eclipse.swt.widgets.Menu;
23 import org.eclipse.ui.ISharedImages;
24 import org.eclipse.ui.IWorkbenchWindow;
25 import org.eclipse.ui.IWorkbenchWindowPulldownDelegate2;
26 import org.eclipse.ui.PlatformUI;
27 import org.eclipse.ui.actions.ActionFactory;
28 import org.eclipse.ui.actions.NewWizardMenu;
29
30 /**
31  * Invoke the resource creation wizard selection Wizard.
32  * This action will retarget to the active view.
33  */

34 public class NewWizardDropDownAction
35         extends Action
36         implements ActionFactory.IWorkbenchAction,
37             IMenuCreator,
38             IWorkbenchWindowPulldownDelegate2 {
39
40     /**
41      * The workbench window; or <code>null</code> if this
42      * action has been <code>dispose</code>d.
43      */

44     private IWorkbenchWindow workbenchWindow;
45
46     private IAction newWizardAction;
47     
48     private MenuManager dropDownMenuMgr;
49     /**
50      * Create a new instance of this class
51      */

52     public NewWizardDropDownAction(IWorkbenchWindow window, IAction newWizardAction) {
53         super(IDEWorkbenchMessages.getString("NewWizardDropDown.text")); //$NON-NLS-1$
54
if (window == null) {
55             throw new IllegalArgumentException JavaDoc();
56         }
57         this.workbenchWindow = window;
58         this.newWizardAction = newWizardAction;
59         setToolTipText(newWizardAction.getToolTipText());
60
61         // @issues should be IDE-specific images
62
ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
63         setImageDescriptor(
64             sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_NEW_WIZARD));
65         setDisabledImageDescriptor(
66             sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_NEW_WIZARD_DISABLED));
67
68         setMenuCreator(this);
69     }
70     /**
71      * create the menu manager for the drop down menu.
72      */

73     protected void createDropDownMenuMgr() {
74         if (dropDownMenuMgr == null) {
75             dropDownMenuMgr = new MenuManager();
76             dropDownMenuMgr.add(new NewWizardMenu(workbenchWindow));
77         }
78     }
79     /**
80      * dispose method comment.
81      */

82     public void dispose() {
83         if (workbenchWindow == null) {
84             // action has already been disposed
85
return;
86         }
87         if (dropDownMenuMgr != null) {
88             dropDownMenuMgr.dispose();
89             dropDownMenuMgr = null;
90         }
91         workbenchWindow = null;
92     }
93     /**
94      * getMenu method comment.
95      */

96     public Menu getMenu(Control parent) {
97         createDropDownMenuMgr();
98         return dropDownMenuMgr.createContextMenu(parent);
99     }
100     /**
101      * Create the drop down menu as a submenu of parent. Necessary
102      * for CoolBar support.
103      */

104     public Menu getMenu(Menu parent) {
105         createDropDownMenuMgr();
106         Menu menu = new Menu(parent);
107         IContributionItem[] items = dropDownMenuMgr.getItems();
108         for (int i = 0; i < items.length; i++) {
109             IContributionItem item = items[i];
110             IContributionItem newItem = item;
111             if (item instanceof ActionContributionItem) {
112                 newItem = new ActionContributionItem(((ActionContributionItem) item).getAction());
113             }
114             newItem.fill(menu, -1);
115         }
116         return menu;
117     }
118     /**
119      * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(IWorkbenchWindow)
120      */

121     public void init(IWorkbenchWindow window) {
122     }
123     public void run() {
124         if (workbenchWindow == null) {
125             // action has been disposed
126
return;
127         }
128         newWizardAction.run();
129     }
130     /**
131      * @see org.eclipse.ui.IActionDelegate#run(IAction)
132      */

133     public void run(IAction action) {
134     }
135     /**
136      * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
137      */

138     public void selectionChanged(IAction action, ISelection selection) {
139     }
140 }
141
Popular Tags