1 11 package org.eclipse.search.internal.ui.text; 12 13 import org.eclipse.core.runtime.Assert; 14 import org.eclipse.core.runtime.IAdaptable; 15 16 import org.eclipse.jface.action.IMenuManager; 17 import org.eclipse.jface.action.MenuManager; 18 import org.eclipse.jface.viewers.ISelection; 19 import org.eclipse.jface.viewers.ISelectionProvider; 20 import org.eclipse.jface.viewers.IStructuredSelection; 21 22 import org.eclipse.ui.IActionBars; 23 import org.eclipse.ui.IViewPart; 24 import org.eclipse.ui.IWorkbenchPage; 25 import org.eclipse.ui.IWorkbenchPartSite; 26 import org.eclipse.ui.actions.ActionFactory; 27 import org.eclipse.ui.actions.ActionGroup; 28 import org.eclipse.ui.actions.OpenFileAction; 29 import org.eclipse.ui.actions.OpenWithMenu; 30 import org.eclipse.ui.dialogs.PropertyDialogAction; 31 32 import org.eclipse.search.internal.ui.SearchMessages; 33 import org.eclipse.search.ui.IContextMenuConstants; 34 35 45 public class NewTextSearchActionGroup extends ActionGroup { 46 47 private ISelectionProvider fSelectionProvider; 48 private IWorkbenchPage fPage; 49 private OpenFileAction fOpenAction; 50 private PropertyDialogAction fOpenPropertiesDialog; 51 52 public NewTextSearchActionGroup(IViewPart part) { 53 Assert.isNotNull(part); 54 IWorkbenchPartSite site= part.getSite(); 55 fSelectionProvider= site.getSelectionProvider(); 56 fPage= site.getPage(); 57 fOpenPropertiesDialog= new PropertyDialogAction(site, fSelectionProvider); 58 fOpenAction= new OpenFileAction(fPage); 59 ISelection selection= fSelectionProvider.getSelection(); 60 61 if (selection instanceof IStructuredSelection) 62 fOpenPropertiesDialog.selectionChanged((IStructuredSelection)selection); 63 else 64 fOpenPropertiesDialog.selectionChanged(selection); 65 66 } 67 68 public void fillContextMenu(IMenuManager menu) { 69 71 ISelection selection= getContext().getSelection(); 72 if (selection instanceof IStructuredSelection) { 73 addOpenWithMenu(menu, (IStructuredSelection) selection); 74 if (fOpenPropertiesDialog != null && fOpenPropertiesDialog.isEnabled() && fOpenPropertiesDialog.isApplicableForSelection((IStructuredSelection) selection)) 75 menu.appendToGroup(IContextMenuConstants.GROUP_PROPERTIES, fOpenPropertiesDialog); 76 } 77 78 } 79 80 private void addOpenWithMenu(IMenuManager menu, IStructuredSelection selection) { 81 if (selection == null || selection.size() != 1) 82 return; 83 84 Object o= selection.getFirstElement(); 85 86 if (!(o instanceof IAdaptable)) 87 return; 88 89 fOpenAction.selectionChanged(selection); 90 menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fOpenAction); 91 92 IMenuManager submenu= new MenuManager(SearchMessages.OpenWithMenu_label); 94 submenu.add(new OpenWithMenu(fPage, (IAdaptable)o)); 95 96 menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, submenu); 98 } 99 100 103 public void fillActionBars(IActionBars actionBar) { 104 super.fillActionBars(actionBar); 105 setGlobalActionHandlers(actionBar); 106 } 107 108 private void setGlobalActionHandlers(IActionBars actionBars) { 109 actionBars.setGlobalActionHandler(ActionFactory.PROPERTIES.getId(), fOpenPropertiesDialog); 110 } 111 } 112 | Popular Tags |