1 11 package org.eclipse.jdt.ui.actions; 12 13 import org.eclipse.core.runtime.Assert; 14 15 import org.eclipse.jface.action.GroupMarker; 16 import org.eclipse.jface.action.IMenuManager; 17 import org.eclipse.jface.action.MenuManager; 18 import org.eclipse.jface.action.Separator; 19 20 import org.eclipse.ui.IActionBars; 21 import org.eclipse.ui.IViewPart; 22 import org.eclipse.ui.IWorkbenchSite; 23 import org.eclipse.ui.actions.ActionContext; 24 import org.eclipse.ui.actions.ActionGroup; 25 import org.eclipse.ui.part.Page; 26 import org.eclipse.ui.texteditor.ITextEditorActionConstants; 27 28 import org.eclipse.jdt.ui.PreferenceConstants; 29 30 import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; 31 import org.eclipse.jdt.internal.ui.search.SearchMessages; 32 33 43 public class JavaSearchActionGroup extends ActionGroup { 44 45 private JavaEditor fEditor; 46 47 private ReferencesSearchGroup fReferencesGroup; 48 private ReadReferencesSearchGroup fReadAccessGroup; 49 private WriteReferencesSearchGroup fWriteAccessGroup; 50 private DeclarationsSearchGroup fDeclarationsGroup; 51 private ImplementorsSearchGroup fImplementorsGroup; 52 private OccurrencesSearchGroup fOccurrencesGroup; 53 54 55 62 public JavaSearchActionGroup(IViewPart part) { 63 this(part.getViewSite()); 64 } 65 66 73 public JavaSearchActionGroup(Page page) { 74 this(page.getSite()); 75 } 76 77 81 public JavaSearchActionGroup(JavaEditor editor) { 82 Assert.isNotNull(editor); 83 fEditor= editor; 84 85 fReferencesGroup= new ReferencesSearchGroup(fEditor); 86 fReadAccessGroup= new ReadReferencesSearchGroup(fEditor); 87 fWriteAccessGroup= new WriteReferencesSearchGroup(fEditor); 88 fDeclarationsGroup= new DeclarationsSearchGroup(fEditor); 89 fImplementorsGroup= new ImplementorsSearchGroup(fEditor); 90 fOccurrencesGroup= new OccurrencesSearchGroup(fEditor); 91 } 92 93 private JavaSearchActionGroup(IWorkbenchSite site) { 94 fReferencesGroup= new ReferencesSearchGroup(site); 95 fReadAccessGroup= new ReadReferencesSearchGroup(site); 96 fWriteAccessGroup= new WriteReferencesSearchGroup(site); 97 fDeclarationsGroup= new DeclarationsSearchGroup(site); 98 fImplementorsGroup= new ImplementorsSearchGroup(site); 99 fOccurrencesGroup= new OccurrencesSearchGroup(site); 100 } 101 102 105 public void setContext(ActionContext context) { 106 fReferencesGroup.setContext(context); 107 fDeclarationsGroup.setContext(context); 108 fImplementorsGroup.setContext(context); 109 fReadAccessGroup.setContext(context); 110 fWriteAccessGroup.setContext(context); 111 fOccurrencesGroup.setContext(context); 112 } 113 114 117 public void fillActionBars(IActionBars actionBar) { 118 super.fillActionBars(actionBar); 119 fReferencesGroup.fillActionBars(actionBar); 120 fDeclarationsGroup.fillActionBars(actionBar); 121 fImplementorsGroup.fillActionBars(actionBar); 122 fReadAccessGroup.fillActionBars(actionBar); 123 fWriteAccessGroup.fillActionBars(actionBar); 124 fOccurrencesGroup.fillActionBars(actionBar); 125 } 126 127 130 public void fillContextMenu(IMenuManager menu) { 131 super.fillContextMenu(menu); 132 133 if(PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.SEARCH_USE_REDUCED_MENU)) { 134 fReferencesGroup.fillContextMenu(menu); 135 fDeclarationsGroup.fillContextMenu(menu); 136 137 if (fEditor == null) { 138 fImplementorsGroup.fillContextMenu(menu); 139 fReadAccessGroup.fillContextMenu(menu); 140 fWriteAccessGroup.fillContextMenu(menu); 141 } 142 } else { 143 IMenuManager target= menu; 144 IMenuManager searchSubMenu= null; 145 if (fEditor != null) { 146 String groupName= SearchMessages.group_search; 147 searchSubMenu= new MenuManager(groupName, ITextEditorActionConstants.GROUP_FIND); 148 searchSubMenu.add(new GroupMarker(ITextEditorActionConstants.GROUP_FIND)); 149 target= searchSubMenu; 150 } 151 152 fReferencesGroup.fillContextMenu(target); 153 fDeclarationsGroup.fillContextMenu(target); 154 fImplementorsGroup.fillContextMenu(target); 155 fReadAccessGroup.fillContextMenu(target); 156 fWriteAccessGroup.fillContextMenu(target); 157 158 if (searchSubMenu != null) { 159 fOccurrencesGroup.fillContextMenu(target); 160 searchSubMenu.add(new Separator()); 161 } 162 163 if (searchSubMenu != null && searchSubMenu.getItems().length > 2) { 165 menu.appendToGroup(ITextEditorActionConstants.GROUP_FIND, searchSubMenu); 166 } 167 } 168 } 169 170 173 public void dispose() { 174 fReferencesGroup.dispose(); 175 fDeclarationsGroup.dispose(); 176 fImplementorsGroup.dispose(); 177 fReadAccessGroup.dispose(); 178 fWriteAccessGroup.dispose(); 179 fOccurrencesGroup.dispose(); 180 181 super.dispose(); 182 } 183 } 184 | Popular Tags |