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.action.MenuManager; 16 import org.eclipse.jface.viewers.ISelection; 17 import org.eclipse.jface.viewers.ISelectionProvider; 18 import org.eclipse.jface.viewers.IStructuredSelection; 19 20 import org.eclipse.ui.IActionBars; 21 import org.eclipse.ui.IViewPart; 22 import org.eclipse.ui.IWorkbenchSite; 23 import org.eclipse.ui.IWorkbenchWindow; 24 import org.eclipse.ui.PlatformUI; 25 import org.eclipse.ui.actions.ActionFactory; 26 import org.eclipse.ui.actions.ActionGroup; 27 import org.eclipse.ui.actions.ContributionItemFactory; 28 import org.eclipse.ui.dialogs.PropertyDialogAction; 29 import org.eclipse.ui.keys.IBindingService; 30 import org.eclipse.ui.part.Page; 31 import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds; 32 33 import org.eclipse.jdt.ui.IContextMenuConstants; 34 35 import org.eclipse.jdt.internal.ui.actions.ActionMessages; 36 import org.eclipse.jdt.internal.ui.callhierarchy.OpenCallHierarchyAction; 37 import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; 38 39 49 public class OpenViewActionGroup extends ActionGroup { 50 51 private boolean fEditorIsOwner; 52 private boolean fIsTypeHiararchyViewerOwner; 53 private boolean fIsCallHiararchyViewerOwner; 54 55 private ISelectionProvider fSelectionProvider; 56 57 private OpenSuperImplementationAction fOpenSuperImplementation; 58 private OpenExternalJavadocAction fOpenExternalJavadoc; 59 private OpenTypeHierarchyAction fOpenTypeHierarchy; 60 private OpenCallHierarchyAction fOpenCallHierarchy; 61 private PropertyDialogAction fOpenPropertiesDialog; 62 63 private boolean fShowOpenPropertiesAction= true; 64 private boolean fShowShowInMenu= true; 65 66 73 public OpenViewActionGroup(Page page) { 74 createSiteActions(page.getSite(), null); 75 } 76 77 88 public OpenViewActionGroup(Page page, ISelectionProvider selectionProvider) { 89 createSiteActions(page.getSite(), selectionProvider); 90 } 91 92 99 public OpenViewActionGroup(IViewPart part) { 100 this(part, null); 101 } 102 103 114 public OpenViewActionGroup(IViewPart part, ISelectionProvider selectionProvider) { 115 createSiteActions(part.getSite(), selectionProvider); 116 String partName= part.getClass().getName(); 118 fIsTypeHiararchyViewerOwner= "org.eclipse.jdt.internal.ui.typehierarchy.TypeHierarchyViewPart".equals(partName); fIsCallHiararchyViewerOwner= "org.eclipse.jdt.internal.ui.callhierarchy.CallHierarchyViewPart".equals(partName); } 121 122 133 public OpenViewActionGroup(IWorkbenchSite site, ISelectionProvider selectionProvider) { 134 createSiteActions(site, selectionProvider); 135 } 136 137 141 public OpenViewActionGroup(JavaEditor part) { 142 fEditorIsOwner= true; 143 fShowShowInMenu= false; 144 145 fOpenSuperImplementation= new OpenSuperImplementationAction(part); 146 fOpenSuperImplementation.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_SUPER_IMPLEMENTATION); 147 part.setAction("OpenSuperImplementation", fOpenSuperImplementation); 149 fOpenExternalJavadoc= new OpenExternalJavadocAction(part); 150 fOpenExternalJavadoc.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_EXTERNAL_JAVADOC); 151 part.setAction("OpenExternalJavadoc", fOpenExternalJavadoc); 153 fOpenTypeHierarchy= new OpenTypeHierarchyAction(part); 154 fOpenTypeHierarchy.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_TYPE_HIERARCHY); 155 part.setAction("OpenTypeHierarchy", fOpenTypeHierarchy); 157 fOpenCallHierarchy= new OpenCallHierarchyAction(part); 158 fOpenCallHierarchy.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_CALL_HIERARCHY); 159 part.setAction("OpenCallHierarchy", fOpenCallHierarchy); 161 initialize(part.getEditorSite().getSelectionProvider()); 162 } 163 164 171 public void containsOpenPropertiesAction(boolean enable) { 172 fShowOpenPropertiesAction= enable; 173 } 174 175 182 public void containsShowInMenu(boolean enable) { 183 fShowShowInMenu= enable; 184 } 185 186 private void createSiteActions(IWorkbenchSite site, ISelectionProvider specialProvider) { 187 fOpenSuperImplementation= new OpenSuperImplementationAction(site); 188 fOpenSuperImplementation.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_SUPER_IMPLEMENTATION); 189 fOpenSuperImplementation.setSpecialSelectionProvider(specialProvider); 190 191 fOpenExternalJavadoc= new OpenExternalJavadocAction(site); 192 fOpenExternalJavadoc.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_EXTERNAL_JAVADOC); 193 fOpenExternalJavadoc.setSpecialSelectionProvider(specialProvider); 194 195 fOpenTypeHierarchy= new OpenTypeHierarchyAction(site); 196 fOpenTypeHierarchy.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_TYPE_HIERARCHY); 197 fOpenTypeHierarchy.setSpecialSelectionProvider(specialProvider); 198 199 fOpenCallHierarchy= new OpenCallHierarchyAction(site); 200 fOpenCallHierarchy.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_CALL_HIERARCHY); 201 fOpenCallHierarchy.setSpecialSelectionProvider(specialProvider); 202 203 ISelectionProvider provider= specialProvider != null ? specialProvider : site.getSelectionProvider(); 204 205 fOpenPropertiesDialog= new PropertyDialogAction(site, provider); 206 fOpenPropertiesDialog.setActionDefinitionId(IWorkbenchActionDefinitionIds.PROPERTIES); 207 208 initialize(provider); 209 } 210 211 private void initialize(ISelectionProvider provider) { 212 fSelectionProvider= provider; 213 ISelection selection= provider.getSelection(); 214 fOpenSuperImplementation.update(selection); 215 fOpenExternalJavadoc.update(selection); 216 fOpenTypeHierarchy.update(selection); 217 fOpenCallHierarchy.update(selection); 218 if (!fEditorIsOwner) { 219 if (fShowOpenPropertiesAction) { 220 if (selection instanceof IStructuredSelection) { 221 fOpenPropertiesDialog.selectionChanged((IStructuredSelection) selection); 222 } else { 223 fOpenPropertiesDialog.selectionChanged(selection); 224 } 225 } 226 provider.addSelectionChangedListener(fOpenSuperImplementation); 227 provider.addSelectionChangedListener(fOpenExternalJavadoc); 228 provider.addSelectionChangedListener(fOpenTypeHierarchy); 229 provider.addSelectionChangedListener(fOpenCallHierarchy); 230 } 232 } 233 234 237 public void fillActionBars(IActionBars actionBar) { 238 super.fillActionBars(actionBar); 239 setGlobalActionHandlers(actionBar); 240 } 241 242 245 public void fillContextMenu(IMenuManager menu) { 246 super.fillContextMenu(menu); 247 if (!fIsTypeHiararchyViewerOwner) 248 appendToGroup(menu, fOpenTypeHierarchy); 249 if (!fIsCallHiararchyViewerOwner) 250 appendToGroup(menu, fOpenCallHierarchy); 251 252 if (fShowShowInMenu) { 253 MenuManager showInSubMenu= new MenuManager(getShowInMenuLabel()); 254 IWorkbenchWindow workbenchWindow= fOpenSuperImplementation.getSite().getWorkbenchWindow(); 255 showInSubMenu.add(ContributionItemFactory.VIEWS_SHOW_IN.create(workbenchWindow)); 256 menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, showInSubMenu); 257 } 258 259 IStructuredSelection selection= getStructuredSelection(); 260 if (fShowOpenPropertiesAction && selection != null) 261 menu.appendToGroup(IContextMenuConstants.GROUP_PROPERTIES, fOpenPropertiesDialog); 262 } 263 264 private String getShowInMenuLabel() { 265 String keyBinding= null; 266 267 IBindingService bindingService= (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class); 268 if (bindingService != null) 269 keyBinding= bindingService.getBestActiveBindingFormattedFor("org.eclipse.ui.navigate.showInQuickMenu"); 271 if (keyBinding == null) 272 keyBinding= ""; 274 return ActionMessages.OpenViewActionGroup_showInAction_label + '\t' + keyBinding; 275 } 276 277 280 public void dispose() { 281 fSelectionProvider.removeSelectionChangedListener(fOpenSuperImplementation); 282 fSelectionProvider.removeSelectionChangedListener(fOpenExternalJavadoc); 283 fSelectionProvider.removeSelectionChangedListener(fOpenTypeHierarchy); 284 fSelectionProvider.removeSelectionChangedListener(fOpenCallHierarchy); 285 super.dispose(); 286 } 287 288 private void setGlobalActionHandlers(IActionBars actionBars) { 289 actionBars.setGlobalActionHandler(JdtActionConstants.OPEN_SUPER_IMPLEMENTATION, fOpenSuperImplementation); 290 actionBars.setGlobalActionHandler(JdtActionConstants.OPEN_EXTERNAL_JAVA_DOC, fOpenExternalJavadoc); 291 actionBars.setGlobalActionHandler(JdtActionConstants.OPEN_TYPE_HIERARCHY, fOpenTypeHierarchy); 292 actionBars.setGlobalActionHandler(JdtActionConstants.OPEN_CALL_HIERARCHY, fOpenCallHierarchy); 293 294 if (!fEditorIsOwner && fShowOpenPropertiesAction) 295 actionBars.setGlobalActionHandler(ActionFactory.PROPERTIES.getId(), fOpenPropertiesDialog); 296 } 297 298 private void appendToGroup(IMenuManager menu, IAction action) { 299 if (action.isEnabled()) 300 menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, action); 301 } 302 303 private IStructuredSelection getStructuredSelection() { 304 ISelection selection= getContext().getSelection(); 305 if (selection instanceof IStructuredSelection) 306 return (IStructuredSelection)selection; 307 return null; 308 } 309 310 311 312 313 } 314 | Popular Tags |