1 11 package org.eclipse.ui.internal.navigator.resources.actions; 12 13 import org.eclipse.jface.action.IAction; 14 import org.eclipse.jface.action.IMenuManager; 15 import org.eclipse.jface.action.MenuManager; 16 import org.eclipse.jface.action.Separator; 17 import org.eclipse.ui.IWorkbenchWindow; 18 import org.eclipse.ui.PlatformUI; 19 import org.eclipse.ui.actions.ActionFactory; 20 import org.eclipse.ui.actions.NewExampleAction; 21 import org.eclipse.ui.actions.NewProjectAction; 22 import org.eclipse.ui.internal.navigator.resources.plugin.WorkbenchNavigatorMessages; 23 import org.eclipse.ui.navigator.CommonActionProvider; 24 import org.eclipse.ui.navigator.ICommonActionExtensionSite; 25 import org.eclipse.ui.navigator.ICommonMenuConstants; 26 import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite; 27 import org.eclipse.ui.navigator.WizardActionGroup; 28 import org.eclipse.ui.wizards.IWizardCategory; 29 import org.eclipse.ui.wizards.IWizardRegistry; 30 31 51 public class NewActionProvider extends CommonActionProvider { 52 53 private static final String FULL_EXAMPLES_WIZARD_CATEGORY = "org.eclipse.ui.Examples"; 55 private static final String NEW_MENU_NAME = "common.new.menu"; 57 private IAction showDlgAction; 58 59 private IAction newProjectAction; 60 61 private IAction newExampleAction; 62 63 private WizardActionGroup newWizardActionGroup; 64 65 private boolean contribute = false; 66 67 public void init(ICommonActionExtensionSite anExtensionSite) { 68 69 if (anExtensionSite.getViewSite() instanceof ICommonViewerWorkbenchSite) { 70 IWorkbenchWindow window = ((ICommonViewerWorkbenchSite) anExtensionSite.getViewSite()).getWorkbenchWindow(); 71 showDlgAction = ActionFactory.NEW.create(window); 72 newProjectAction = new NewProjectAction(window); 73 newExampleAction = new NewExampleAction(window); 74 75 newWizardActionGroup = new WizardActionGroup(window, PlatformUI.getWorkbench().getNewWizardRegistry(), WizardActionGroup.TYPE_NEW, anExtensionSite.getContentService()); 76 77 contribute = true; 78 } 79 } 80 81 95 public void fillContextMenu(IMenuManager menu) { 96 IMenuManager submenu = new MenuManager( 97 WorkbenchNavigatorMessages.NewActionProvider_NewMenu_label, 98 NEW_MENU_NAME); 99 if(!contribute) { 100 return; 101 } 102 submenu.add(newProjectAction); 104 submenu.add(new Separator()); 105 106 newWizardActionGroup.setContext(getContext()); 108 newWizardActionGroup.fillContextMenu(submenu); 109 110 submenu.add(new Separator(ICommonMenuConstants.GROUP_ADDITIONS)); 111 112 if (hasExamples()) { 114 submenu.add(new Separator()); 115 submenu.add(newExampleAction); 116 } 117 118 submenu.add(new Separator()); 120 submenu.add(showDlgAction); 121 122 menu.insertAfter(ICommonMenuConstants.GROUP_NEW, submenu); 124 } 125 126 131 private boolean hasExamples() { 132 IWizardRegistry newRegistry = PlatformUI.getWorkbench().getNewWizardRegistry(); 133 IWizardCategory category = newRegistry.findCategory(FULL_EXAMPLES_WIZARD_CATEGORY); 134 return category != null; 135 136 } 137 138 } 139 | Popular Tags |