1 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 34 public class NewWizardDropDownAction 35 extends Action 36 implements ActionFactory.IWorkbenchAction, 37 IMenuCreator, 38 IWorkbenchWindowPulldownDelegate2 { 39 40 44 private IWorkbenchWindow workbenchWindow; 45 46 private IAction newWizardAction; 47 48 private MenuManager dropDownMenuMgr; 49 52 public NewWizardDropDownAction(IWorkbenchWindow window, IAction newWizardAction) { 53 super(IDEWorkbenchMessages.getString("NewWizardDropDown.text")); if (window == null) { 55 throw new IllegalArgumentException (); 56 } 57 this.workbenchWindow = window; 58 this.newWizardAction = newWizardAction; 59 setToolTipText(newWizardAction.getToolTipText()); 60 61 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 73 protected void createDropDownMenuMgr() { 74 if (dropDownMenuMgr == null) { 75 dropDownMenuMgr = new MenuManager(); 76 dropDownMenuMgr.add(new NewWizardMenu(workbenchWindow)); 77 } 78 } 79 82 public void dispose() { 83 if (workbenchWindow == null) { 84 return; 86 } 87 if (dropDownMenuMgr != null) { 88 dropDownMenuMgr.dispose(); 89 dropDownMenuMgr = null; 90 } 91 workbenchWindow = null; 92 } 93 96 public Menu getMenu(Control parent) { 97 createDropDownMenuMgr(); 98 return dropDownMenuMgr.createContextMenu(parent); 99 } 100 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 121 public void init(IWorkbenchWindow window) { 122 } 123 public void run() { 124 if (workbenchWindow == null) { 125 return; 127 } 128 newWizardAction.run(); 129 } 130 133 public void run(IAction action) { 134 } 135 138 public void selectionChanged(IAction action, ISelection selection) { 139 } 140 } 141 | Popular Tags |