1 11 12 package org.eclipse.ui.actions; 13 14 import org.eclipse.jface.action.Action; 15 import org.eclipse.jface.action.ActionContributionItem; 16 import org.eclipse.jface.action.IContributionItem; 17 import org.eclipse.jface.action.IMenuCreator; 18 import org.eclipse.jface.action.MenuManager; 19 import org.eclipse.swt.widgets.Control; 20 import org.eclipse.swt.widgets.Menu; 21 import org.eclipse.ui.ISharedImages; 22 import org.eclipse.ui.IWorkbenchWindow; 23 import org.eclipse.ui.internal.PerspectiveTracker; 24 import org.eclipse.ui.internal.WorkbenchMessages; 25 26 36 public class NewWizardDropDownAction extends Action implements 37 ActionFactory.IWorkbenchAction { 38 39 43 private IWorkbenchWindow workbenchWindow; 44 45 49 private PerspectiveTracker tracker; 50 51 private ActionFactory.IWorkbenchAction showDlgAction; 52 53 private IContributionItem newWizardMenu; 54 55 private IMenuCreator menuCreator = new IMenuCreator() { 56 57 private MenuManager dropDownMenuMgr; 58 59 62 private void createDropDownMenuMgr() { 63 if (dropDownMenuMgr == null) { 64 dropDownMenuMgr = new MenuManager(); 65 dropDownMenuMgr.add(newWizardMenu); 66 } 67 } 68 69 72 public Menu getMenu(Control parent) { 73 createDropDownMenuMgr(); 74 return dropDownMenuMgr.createContextMenu(parent); 75 } 76 77 80 public Menu getMenu(Menu parent) { 81 createDropDownMenuMgr(); 82 Menu menu = new Menu(parent); 83 IContributionItem[] items = dropDownMenuMgr.getItems(); 84 for (int i = 0; i < items.length; i++) { 85 IContributionItem item = items[i]; 86 IContributionItem newItem = item; 87 if (item instanceof ActionContributionItem) { 88 newItem = new ActionContributionItem( 89 ((ActionContributionItem) item).getAction()); 90 } 91 newItem.fill(menu, -1); 92 } 93 return menu; 94 } 95 96 99 public void dispose() { 100 if (dropDownMenuMgr != null) { 101 dropDownMenuMgr.dispose(); 102 dropDownMenuMgr = null; 103 } 104 } 105 }; 106 107 114 public NewWizardDropDownAction(IWorkbenchWindow window) { 115 this(window, ActionFactory.NEW.create(window), ContributionItemFactory.NEW_WIZARD_SHORTLIST.create(window)); 116 } 117 118 126 public NewWizardDropDownAction(IWorkbenchWindow window, 127 ActionFactory.IWorkbenchAction showDlgAction, 128 IContributionItem newWizardMenu) { 129 super(WorkbenchMessages.NewWizardDropDown_text); 130 if (window == null) { 131 throw new IllegalArgumentException (); 132 } 133 this.workbenchWindow = window; 134 this.showDlgAction = showDlgAction; 135 this.newWizardMenu = newWizardMenu; 136 tracker = new PerspectiveTracker(window, this); 137 138 setToolTipText(showDlgAction.getToolTipText()); 139 140 ISharedImages sharedImages = window.getWorkbench() 141 .getSharedImages(); 142 setImageDescriptor(sharedImages 143 .getImageDescriptor(ISharedImages.IMG_TOOL_NEW_WIZARD)); 144 setDisabledImageDescriptor(sharedImages 145 .getImageDescriptor(ISharedImages.IMG_TOOL_NEW_WIZARD_DISABLED)); 146 147 setMenuCreator(menuCreator); 148 } 149 150 151 154 public void dispose() { 155 if (workbenchWindow == null) { 156 return; 158 } 159 tracker.dispose(); 160 showDlgAction.dispose(); 161 newWizardMenu.dispose(); 162 menuCreator.dispose(); 163 workbenchWindow = null; 164 } 165 166 169 public void run() { 170 if (workbenchWindow == null) { 171 return; 173 } 174 showDlgAction.run(); 175 } 176 177 } 178 | Popular Tags |