1 11 package org.eclipse.jdt.internal.ui.actions; 12 13 import java.util.Iterator ; 14 import java.util.List ; 15 16 import org.eclipse.core.resources.IResource; 17 18 import org.eclipse.jface.action.IMenuManager; 19 import org.eclipse.jface.action.MenuManager; 20 import org.eclipse.jface.viewers.ISelection; 21 import org.eclipse.jface.viewers.IStructuredSelection; 22 23 import org.eclipse.ui.IWorkbenchSite; 24 import org.eclipse.ui.IWorkingSet; 25 import org.eclipse.ui.actions.ActionGroup; 26 import org.eclipse.ui.actions.NewWizardMenu; 27 28 import org.eclipse.jdt.core.IJavaElement; 29 30 import org.eclipse.jdt.ui.IContextMenuConstants; 31 32 import org.eclipse.jdt.internal.ui.workingsets.JavaWorkingSetUpdater; 33 import org.eclipse.jdt.internal.ui.workingsets.OthersWorkingSetUpdater; 34 35 36 44 public class NewWizardsActionGroup extends ActionGroup { 45 46 private IWorkbenchSite fSite; 47 48 55 public NewWizardsActionGroup(IWorkbenchSite site) { 56 fSite= site; 57 } 58 59 60 63 public void fillContextMenu(IMenuManager menu) { 64 super.fillContextMenu(menu); 65 66 ISelection selection= getContext().getSelection(); 67 if (selection instanceof IStructuredSelection) { 68 if (canEnable((IStructuredSelection)selection)) { 69 MenuManager newMenu = new MenuManager(ActionMessages.NewWizardsActionGroup_new); 70 menu.appendToGroup(IContextMenuConstants.GROUP_NEW, newMenu); 71 newMenu.add(new NewWizardMenu(fSite.getWorkbenchWindow())); 72 } 73 } 74 75 } 76 77 private boolean canEnable(IStructuredSelection sel) { 78 if (sel.size() == 0) 79 return true; 80 81 List list= sel.toList(); 82 for (Iterator iterator= list.iterator(); iterator.hasNext();) { 83 if (!isNewTarget(iterator.next())) 84 return false; 85 } 86 87 return true; 88 } 89 90 private boolean isNewTarget(Object element) { 91 if (element == null) 92 return true; 93 if (element instanceof IResource) { 94 return true; 95 } 96 if (element instanceof IJavaElement) { 97 int type= ((IJavaElement)element).getElementType(); 98 return type == IJavaElement.JAVA_PROJECT || 99 type == IJavaElement.PACKAGE_FRAGMENT_ROOT || 100 type == IJavaElement.PACKAGE_FRAGMENT || 101 type == IJavaElement.COMPILATION_UNIT || 102 type == IJavaElement.TYPE; 103 } 104 if (element instanceof IWorkingSet) { 105 String workingSetId= ((IWorkingSet)element).getId(); 106 return 107 JavaWorkingSetUpdater.ID.equals(workingSetId) || 108 "org.eclipse.ui.resourceWorkingSetPage".equals(workingSetId) || OthersWorkingSetUpdater.ID.equals(workingSetId); 110 } 111 return false; 112 } 113 114 } 115 | Popular Tags |