1 11 package org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 import org.eclipse.jface.action.Action; 18 import org.eclipse.jface.action.IAction; 19 import org.eclipse.jface.action.IMenuListener; 20 import org.eclipse.jface.action.IMenuManager; 21 import org.eclipse.jface.action.MenuManager; 22 import org.eclipse.jface.action.Separator; 23 import org.eclipse.jface.viewers.ISelection; 24 import org.eclipse.jface.viewers.ISelectionChangedListener; 25 import org.eclipse.jface.viewers.ISelectionProvider; 26 import org.eclipse.jface.viewers.IStructuredSelection; 27 28 import org.eclipse.ui.IActionBars; 29 import org.eclipse.ui.IViewPart; 30 import org.eclipse.ui.IWorkbenchPart; 31 import org.eclipse.ui.IWorkbenchSite; 32 import org.eclipse.ui.IWorkingSet; 33 import org.eclipse.ui.PlatformUI; 34 import org.eclipse.ui.actions.ActionGroup; 35 import org.eclipse.ui.part.Page; 36 import org.eclipse.ui.texteditor.IUpdate; 37 38 import org.eclipse.jdt.ui.IContextMenuConstants; 39 40 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 41 import org.eclipse.jdt.internal.ui.JavaPluginImages; 42 import org.eclipse.jdt.internal.ui.actions.ActionMessages; 43 import org.eclipse.jdt.internal.ui.actions.JarImportWizardAction; 44 import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages; 45 46 56 public class GenerateBuildPathActionGroup extends ActionGroup { 57 62 public static final String MENU_ID= "org.eclipse.jdt.ui.buildpath.menu"; 64 70 public static final String GROUP_BUILDPATH= "buildpathGroup"; 72 78 public static final String GROUP_FILTER= "filterGroup"; 80 86 public static final String GROUP_CUSTOMIZE= "customizeGroup"; 88 private static class NoActionAvailable extends Action { 89 public NoActionAvailable() { 90 setEnabled(false); 91 setText(NewWizardMessages.GenerateBuildPathActionGroup_no_action_available); 92 } 93 } 94 private Action fNoActionAvailable= new NoActionAvailable(); 95 96 private class UpdateJarFileAction extends JarImportWizardAction implements IUpdate { 97 98 public UpdateJarFileAction() { 99 setText(ActionMessages.GenerateBuildPathActionGroup_update_jar_text); 100 setDescription(ActionMessages.GenerateBuildPathActionGroup_update_jar_description); 101 setToolTipText(ActionMessages.GenerateBuildPathActionGroup_update_jar_tooltip); 102 setImageDescriptor(JavaPluginImages.DESC_OBJS_JAR); 103 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.JARIMPORT_WIZARD_PAGE); 104 } 105 106 109 public void update() { 110 final IWorkbenchPart part= fSite.getPage().getActivePart(); 111 if (part != null) 112 setActivePart(this, part); 113 selectionChanged(this, fSite.getSelectionProvider().getSelection()); 114 } 115 } 116 117 private IWorkbenchSite fSite; 118 private List fActions; 119 120 private String fGroupName= IContextMenuConstants.GROUP_REORGANIZE; 121 122 129 public GenerateBuildPathActionGroup(Page page) { 130 this(page.getSite()); 131 } 132 133 140 public GenerateBuildPathActionGroup(IViewPart part) { 141 this(part.getSite()); 142 } 143 144 private GenerateBuildPathActionGroup(IWorkbenchSite site) { 145 fSite= site; 146 fActions= new ArrayList (); 147 148 final CreateLinkedSourceFolderAction addLinkedSourceFolderAction= new CreateLinkedSourceFolderAction(site); 149 fActions.add(addLinkedSourceFolderAction); 150 151 final CreateSourceFolderAction addSourceFolderAction= new CreateSourceFolderAction(site); 152 fActions.add(addSourceFolderAction); 153 154 final AddFolderToBuildpathAction addFolder= new AddFolderToBuildpathAction(site); 155 fActions.add(addFolder); 156 157 final AddSelectedLibraryToBuildpathAction addSelectedLibrary= new AddSelectedLibraryToBuildpathAction(site); 158 fActions.add(addSelectedLibrary); 159 160 final RemoveFromBuildpathAction remove= new RemoveFromBuildpathAction(site); 161 fActions.add(remove); 162 163 final AddArchiveToBuildpathAction addArchive= new AddArchiveToBuildpathAction(site); 164 fActions.add(addArchive); 165 166 final AddLibraryToBuildpathAction addLibrary= new AddLibraryToBuildpathAction(site); 167 fActions.add(addLibrary); 168 169 final UpdateJarFileAction updateAction= new UpdateJarFileAction(); 170 fActions.add(updateAction); 171 172 final ExcludeFromBuildpathAction exclude= new ExcludeFromBuildpathAction(site); 173 fActions.add(exclude); 174 175 final IncludeToBuildpathAction include= new IncludeToBuildpathAction(site); 176 fActions.add(include); 177 178 final EditFilterAction editFilterAction= new EditFilterAction(site); 179 fActions.add(editFilterAction); 180 181 final EditOutputFolderAction editOutput= new EditOutputFolderAction(site); 182 fActions.add(editOutput); 183 184 final ConfigureBuildPathAction configure= new ConfigureBuildPathAction(site); 185 fActions.add(configure); 186 187 final ISelectionProvider provider= fSite.getSelectionProvider(); 188 for (Iterator iter= fActions.iterator(); iter.hasNext();) { 189 Action action= (Action)iter.next(); 190 if (action instanceof ISelectionChangedListener) { 191 provider.addSelectionChangedListener((ISelectionChangedListener)action); 192 } 193 } 194 195 } 196 197 200 public void fillActionBars(IActionBars actionBar) { 201 super.fillActionBars(actionBar); 202 setGlobalActionHandlers(actionBar); 203 } 204 205 208 public void fillContextMenu(IMenuManager menu) { 209 super.fillContextMenu(menu); 210 if (!canOperateOnSelection()) 211 return; 212 String menuText= ActionMessages.BuildPath_label; 213 IMenuManager subMenu= new MenuManager(menuText, MENU_ID); 214 subMenu.addMenuListener(new IMenuListener() { 215 public void menuAboutToShow(IMenuManager manager) { 216 fillViewSubMenu(manager); 217 } 218 }); 219 subMenu.setRemoveAllWhenShown(true); 220 subMenu.add(new ConfigureBuildPathAction(fSite)); 221 menu.appendToGroup(fGroupName, subMenu); 222 } 223 224 private void fillViewSubMenu(IMenuManager source) { 225 int added= 0; 226 int i=0; 227 for (Iterator iter= fActions.iterator(); iter.hasNext();) { 228 Action action= (Action)iter.next(); 229 if (action instanceof IUpdate) 230 ((IUpdate) action).update(); 231 232 if (i == 2) 233 source.add(new Separator(GROUP_BUILDPATH)); 234 else if (i == 8) 235 source.add(new Separator(GROUP_FILTER)); 236 else if (i == 10) 237 source.add(new Separator(GROUP_CUSTOMIZE)); 238 added+= addAction(source, action); 239 i++; 240 } 241 242 if (added == 0) { 243 source.add(fNoActionAvailable); 244 } 245 } 246 247 private void setGlobalActionHandlers(IActionBars actionBar) { 248 } 250 251 private int addAction(IMenuManager menu, IAction action) { 252 if (action != null && action.isEnabled()) { 253 menu.add(action); 254 return 1; 255 } 256 return 0; 257 } 258 259 private boolean canOperateOnSelection() { 260 ISelection sel= fSite.getSelectionProvider().getSelection(); 261 if (!(sel instanceof IStructuredSelection)) 262 return false; 263 IStructuredSelection selection= (IStructuredSelection)sel; 264 for (Iterator iter= selection.iterator(); iter.hasNext();) { 265 Object element= iter.next(); 266 if (element instanceof IWorkingSet) 267 return false; 268 } 269 return true; 270 } 271 272 275 public void dispose() { 276 if (fActions != null) { 277 final ISelectionProvider provider= fSite.getSelectionProvider(); 278 for (Iterator iter= fActions.iterator(); iter.hasNext();) { 279 Action action= (Action)iter.next(); 280 if (action instanceof ISelectionChangedListener) 281 provider.removeSelectionChangedListener((ISelectionChangedListener) action); 282 } 283 } 284 fActions= null; 285 super.dispose(); 286 } 287 } 288 | Popular Tags |