1 11 package org.eclipse.jdt.ui.actions; 12 13 import org.eclipse.jface.action.IAction; 14 import org.eclipse.jface.action.IMenuManager; 15 import org.eclipse.jface.viewers.ISelection; 16 import org.eclipse.jface.viewers.ISelectionProvider; 17 18 import org.eclipse.ui.IActionBars; 19 import org.eclipse.ui.IViewPart; 20 import org.eclipse.ui.IWorkbenchSite; 21 import org.eclipse.ui.actions.ActionGroup; 22 import org.eclipse.ui.part.Page; 23 24 import org.eclipse.jdt.ui.IContextMenuConstants; 25 26 import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; 27 import org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart; 28 29 38 public class ShowActionGroup extends ActionGroup { 39 40 private boolean fIsPackageExplorer; 41 42 private IWorkbenchSite fSite; 43 private ShowInPackageViewAction fShowInPackagesViewAction; 44 45 52 public ShowActionGroup(Page page) { 53 this(page.getSite()); 54 } 55 56 63 public ShowActionGroup(IViewPart part) { 64 this(part.getSite()); 65 fIsPackageExplorer= part instanceof PackageExplorerPart; 66 } 67 68 72 public ShowActionGroup(JavaEditor part) { 73 fShowInPackagesViewAction= new ShowInPackageViewAction(part); 74 fShowInPackagesViewAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SHOW_IN_PACKAGE_VIEW); 75 part.setAction("ShowInPackageView", fShowInPackagesViewAction); 77 initialize(part.getSite(), true); 78 } 79 80 private ShowActionGroup(IWorkbenchSite site) { 81 fShowInPackagesViewAction= new ShowInPackageViewAction(site); 82 fShowInPackagesViewAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SHOW_IN_PACKAGE_VIEW); 83 84 initialize(site , false); 85 } 86 87 private void initialize(IWorkbenchSite site, boolean isJavaEditor) { 88 fSite= site; 89 ISelectionProvider provider= fSite.getSelectionProvider(); 90 ISelection selection= provider.getSelection(); 91 fShowInPackagesViewAction.update(selection); 92 if (!isJavaEditor) { 93 provider.addSelectionChangedListener(fShowInPackagesViewAction); 94 } 95 } 96 97 100 public void fillActionBars(IActionBars actionBar) { 101 super.fillActionBars(actionBar); 102 setGlobalActionHandlers(actionBar); 103 } 104 105 108 public void fillContextMenu(IMenuManager menu) { 109 super.fillContextMenu(menu); 110 if (!fIsPackageExplorer) { 111 appendToGroup(menu, fShowInPackagesViewAction); 112 } 113 } 114 115 118 public void dispose() { 119 ISelectionProvider provider= fSite.getSelectionProvider(); 120 provider.removeSelectionChangedListener(fShowInPackagesViewAction); 121 super.dispose(); 122 } 123 124 private void setGlobalActionHandlers(IActionBars actionBar) { 125 if (!fIsPackageExplorer) 126 actionBar.setGlobalActionHandler(JdtActionConstants.SHOW_IN_PACKAGE_VIEW, fShowInPackagesViewAction); 127 } 128 129 private void appendToGroup(IMenuManager menu, IAction action) { 130 if (action.isEnabled()) 131 menu.appendToGroup(IContextMenuConstants.GROUP_SHOW, action); 132 } 133 } 134 | Popular Tags |