1 11 package org.eclipse.ui.actions; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 import org.eclipse.jface.action.ActionContributionItem; 18 import org.eclipse.jface.action.IAction; 19 import org.eclipse.jface.action.IContributionItem; 20 import org.eclipse.jface.action.IContributionManager; 21 import org.eclipse.jface.action.IMenuManager; 22 import org.eclipse.jface.action.Separator; 23 import org.eclipse.ui.IWorkbenchWindow; 24 import org.eclipse.ui.internal.actions.NewWizardShortcutAction; 25 import org.eclipse.ui.internal.dialogs.WorkbenchWizardElement; 26 import org.eclipse.ui.internal.registry.WizardsRegistryReader; 27 import org.eclipse.ui.wizards.IWizardDescriptor; 28 29 33 public class NewWizardMenu extends BaseNewWizardMenu { 34 35 private final IAction newExampleAction; 36 private final IAction newProjectAction; 37 38 private boolean enabled = true; 39 40 46 public NewWizardMenu(IWorkbenchWindow window) { 47 this(window, null); 48 49 } 50 51 59 public NewWizardMenu(IWorkbenchWindow window, String id) { 60 super(window, id); 61 newExampleAction = new NewExampleAction(window); 62 newProjectAction = new NewProjectAction(window); 63 } 64 65 82 public NewWizardMenu(IMenuManager innerMgr, IWorkbenchWindow window, 83 boolean register) { 84 this(window, null); 85 fillMenu(innerMgr); 86 } 88 89 92 private void fillMenu(IContributionManager innerMgr) { 93 innerMgr.removeAll(); 95 96 IContributionItem[] items = getContributionItems(); 97 for (int i = 0; i < items.length; i++) { 98 innerMgr.add(items[i]); 99 } 100 } 101 102 111 public void deregisterListeners() { 112 } 114 115 120 private boolean hasExamples() { 121 return registryHasCategory(WizardsRegistryReader.FULL_EXAMPLES_WIZARD_CATEGORY); 122 } 123 124 127 protected void addItems(List list) { 128 ArrayList shortCuts= new ArrayList (); 129 addShortcuts(shortCuts); 130 131 for (Iterator iterator= shortCuts.iterator(); iterator.hasNext();) { 132 Object curr= iterator.next(); 133 if (curr instanceof ActionContributionItem && isNewProjectWizardAction(((ActionContributionItem) curr).getAction())) { 134 iterator.remove(); 135 list.add(curr); 136 } 137 } 138 list.add(new ActionContributionItem(newProjectAction)); 139 list.add(new Separator()); 140 if (!shortCuts.isEmpty()) { 141 list.addAll(shortCuts); 142 list.add(new Separator()); 143 } 144 if (hasExamples()) { 145 list.add(new ActionContributionItem(newExampleAction)); 146 list.add(new Separator()); 147 } 148 list.add(new ActionContributionItem(getShowDialogAction())); 149 } 150 151 private boolean isNewProjectWizardAction(IAction action) { 152 if (action instanceof NewWizardShortcutAction) { 153 IWizardDescriptor wizardDescriptor= ((NewWizardShortcutAction) action).getWizardDescriptor(); 154 String [] tags = wizardDescriptor.getTags(); 155 for (int i = 0; i < tags.length; i++) { 156 if (WorkbenchWizardElement.TAG_PROJECT.equals(tags[i])) { 157 return true; 158 } 159 } 160 } 161 return false; 162 } 163 164 167 public boolean isEnabled() { 168 return enabled; 169 } 170 171 177 public void setEnabled(boolean enabledValue) { 178 this.enabled = enabledValue; 179 } 180 181 184 protected IContributionItem[] getContributionItems() { 185 if (isEnabled()) { 186 return super.getContributionItems(); 187 } 188 return new IContributionItem[0]; 189 } 190 } 191 | Popular Tags |