1 11 package org.eclipse.jdt.internal.ui.javaeditor; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 import java.util.ResourceBundle ; 17 18 import org.eclipse.jface.action.IAction; 19 import org.eclipse.jface.action.IMenuManager; 20 import org.eclipse.jface.action.IStatusLineManager; 21 import org.eclipse.jface.action.MenuManager; 22 import org.eclipse.jface.action.Separator; 23 24 import org.eclipse.ui.IActionBars; 25 import org.eclipse.ui.IEditorPart; 26 import org.eclipse.ui.IWorkbenchActionConstants; 27 import org.eclipse.ui.IWorkbenchPage; 28 import org.eclipse.ui.actions.RetargetAction; 29 import org.eclipse.ui.texteditor.BasicTextEditorActionContributor; 30 import org.eclipse.ui.texteditor.ITextEditor; 31 import org.eclipse.ui.texteditor.ITextEditorActionConstants; 32 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; 33 import org.eclipse.ui.texteditor.RetargetTextEditorAction; 34 35 import org.eclipse.jdt.ui.actions.IJavaEditorActionDefinitionIds; 36 37 import org.eclipse.jdt.internal.ui.actions.CopyQualifiedNameAction; 38 import org.eclipse.jdt.internal.ui.actions.FoldingActionGroup; 39 import org.eclipse.jdt.internal.ui.javaeditor.selectionactions.GoToNextPreviousMemberAction; 40 import org.eclipse.jdt.internal.ui.javaeditor.selectionactions.StructureSelectionAction; 41 42 45 public class BasicJavaEditorActionContributor extends BasicTextEditorActionContributor { 46 47 private List fPartListeners= new ArrayList (); 48 49 private TogglePresentationAction fTogglePresentation; 50 private ToggleMarkOccurrencesAction fToggleMarkOccurrencesAction; 51 52 private RetargetTextEditorAction fGotoMatchingBracket; 53 private RetargetTextEditorAction fShowOutline; 54 private RetargetTextEditorAction fOpenStructure; 55 private RetargetTextEditorAction fOpenHierarchy; 56 57 private RetargetTextEditorAction fRetargetShowInformationAction; 58 59 private RetargetTextEditorAction fStructureSelectEnclosingAction; 60 private RetargetTextEditorAction fStructureSelectNextAction; 61 private RetargetTextEditorAction fStructureSelectPreviousAction; 62 private RetargetTextEditorAction fStructureSelectHistoryAction; 63 64 private RetargetTextEditorAction fGotoNextMemberAction; 65 private RetargetTextEditorAction fGotoPreviousMemberAction; 66 67 private RetargetTextEditorAction fRemoveOccurrenceAnnotationsAction; 68 69 public BasicJavaEditorActionContributor() { 70 super(); 71 72 ResourceBundle b= JavaEditorMessages.getBundleForConstructedKeys(); 73 74 fRetargetShowInformationAction= new RetargetTextEditorAction(b, "Editor.ShowInformation."); fRetargetShowInformationAction.setActionDefinitionId(ITextEditorActionDefinitionIds.SHOW_INFORMATION); 76 77 fTogglePresentation= new TogglePresentationAction(); 79 80 fToggleMarkOccurrencesAction= new ToggleMarkOccurrencesAction(); 81 82 fGotoMatchingBracket= new RetargetTextEditorAction(b, "GotoMatchingBracket."); fGotoMatchingBracket.setActionDefinitionId(IJavaEditorActionDefinitionIds.GOTO_MATCHING_BRACKET); 84 85 fShowOutline= new RetargetTextEditorAction(JavaEditorMessages.getBundleForConstructedKeys(), "ShowOutline."); fShowOutline.setActionDefinitionId(IJavaEditorActionDefinitionIds.SHOW_OUTLINE); 87 88 fOpenHierarchy= new RetargetTextEditorAction(JavaEditorMessages.getBundleForConstructedKeys(), "OpenHierarchy."); fOpenHierarchy.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_HIERARCHY); 90 91 fOpenStructure= new RetargetTextEditorAction(JavaEditorMessages.getBundleForConstructedKeys(), "OpenStructure."); fOpenStructure.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_STRUCTURE); 93 94 fStructureSelectEnclosingAction= new RetargetTextEditorAction(b, "StructureSelectEnclosing."); fStructureSelectEnclosingAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SELECT_ENCLOSING); 96 fStructureSelectNextAction= new RetargetTextEditorAction(b, "StructureSelectNext."); fStructureSelectNextAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SELECT_NEXT); 98 fStructureSelectPreviousAction= new RetargetTextEditorAction(b, "StructureSelectPrevious."); fStructureSelectPreviousAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SELECT_PREVIOUS); 100 fStructureSelectHistoryAction= new RetargetTextEditorAction(b, "StructureSelectHistory."); fStructureSelectHistoryAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SELECT_LAST); 102 103 fGotoNextMemberAction= new RetargetTextEditorAction(b, "GotoNextMember."); fGotoNextMemberAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.GOTO_NEXT_MEMBER); 105 fGotoPreviousMemberAction= new RetargetTextEditorAction(b, "GotoPreviousMember."); fGotoPreviousMemberAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.GOTO_PREVIOUS_MEMBER); 107 108 fRemoveOccurrenceAnnotationsAction= new RetargetTextEditorAction(b, "RemoveOccurrenceAnnotations."); fRemoveOccurrenceAnnotationsAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.REMOVE_OCCURRENCE_ANNOTATIONS); 110 } 111 112 protected final void markAsPartListener(RetargetAction action) { 113 fPartListeners.add(action); 114 } 115 116 119 public void init(IActionBars bars, IWorkbenchPage page) { 120 Iterator e= fPartListeners.iterator(); 121 while (e.hasNext()) 122 page.addPartListener((RetargetAction) e.next()); 123 124 super.init(bars, page); 125 126 bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY, fTogglePresentation); 127 bars.setGlobalActionHandler(IJavaEditorActionDefinitionIds.TOGGLE_MARK_OCCURRENCES, fToggleMarkOccurrencesAction); 128 129 } 130 131 134 public void contributeToMenu(IMenuManager menu) { 135 136 super.contributeToMenu(menu); 137 138 IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT); 139 if (editMenu != null) { 140 141 MenuManager structureSelection= new MenuManager(JavaEditorMessages.ExpandSelectionMenu_label, "expandSelection"); editMenu.insertAfter(ITextEditorActionConstants.SELECT_ALL, structureSelection); 143 structureSelection.add(fStructureSelectEnclosingAction); 144 structureSelection.add(fStructureSelectNextAction); 145 structureSelection.add(fStructureSelectPreviousAction); 146 structureSelection.add(fStructureSelectHistoryAction); 147 148 editMenu.appendToGroup(ITextEditorActionConstants.GROUP_INFORMATION, fRetargetShowInformationAction); 149 } 150 151 IMenuManager navigateMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_NAVIGATE); 152 if (navigateMenu != null) { 153 navigateMenu.appendToGroup(IWorkbenchActionConstants.SHOW_EXT, fShowOutline); 154 navigateMenu.appendToGroup(IWorkbenchActionConstants.SHOW_EXT, fOpenHierarchy); 155 } 156 157 IMenuManager gotoMenu= menu.findMenuUsingPath("navigate/goTo"); if (gotoMenu != null) { 159 gotoMenu.add(new Separator("additions2")); gotoMenu.appendToGroup("additions2", fGotoPreviousMemberAction); gotoMenu.appendToGroup("additions2", fGotoNextMemberAction); gotoMenu.appendToGroup("additions2", fGotoMatchingBracket); } 164 } 165 166 169 public void setActiveEditor(IEditorPart part) { 170 171 super.setActiveEditor(part); 172 173 ITextEditor textEditor= null; 174 if (part instanceof ITextEditor) 175 textEditor= (ITextEditor)part; 176 177 fTogglePresentation.setEditor(textEditor); 178 fToggleMarkOccurrencesAction.setEditor(textEditor); 179 180 fGotoMatchingBracket.setAction(getAction(textEditor, GotoMatchingBracketAction.GOTO_MATCHING_BRACKET)); 181 fShowOutline.setAction(getAction(textEditor, IJavaEditorActionDefinitionIds.SHOW_OUTLINE)); 182 fOpenHierarchy.setAction(getAction(textEditor, IJavaEditorActionDefinitionIds.OPEN_HIERARCHY)); 183 fOpenStructure.setAction(getAction(textEditor, IJavaEditorActionDefinitionIds.OPEN_STRUCTURE)); 184 185 fStructureSelectEnclosingAction.setAction(getAction(textEditor, StructureSelectionAction.ENCLOSING)); 186 fStructureSelectNextAction.setAction(getAction(textEditor, StructureSelectionAction.NEXT)); 187 fStructureSelectPreviousAction.setAction(getAction(textEditor, StructureSelectionAction.PREVIOUS)); 188 fStructureSelectHistoryAction.setAction(getAction(textEditor, StructureSelectionAction.HISTORY)); 189 190 fGotoNextMemberAction.setAction(getAction(textEditor, GoToNextPreviousMemberAction.NEXT_MEMBER)); 191 fGotoPreviousMemberAction.setAction(getAction(textEditor, GoToNextPreviousMemberAction.PREVIOUS_MEMBER)); 192 193 fRemoveOccurrenceAnnotationsAction.setAction(getAction(textEditor, "RemoveOccurrenceAnnotations")); fRetargetShowInformationAction.setAction(getAction(textEditor, ITextEditorActionConstants.SHOW_INFORMATION)); 195 196 if (part instanceof JavaEditor) { 197 JavaEditor javaEditor= (JavaEditor) part; 198 javaEditor.getActionGroup().fillActionBars(getActionBars()); 199 FoldingActionGroup foldingActions= javaEditor.getFoldingActionGroup(); 200 if (foldingActions != null) 201 foldingActions.updateActionBars(); 202 } 203 204 IActionBars actionBars= getActionBars(); 205 IStatusLineManager manager= actionBars.getStatusLineManager(); 206 manager.setMessage(null); 207 manager.setErrorMessage(null); 208 209 210 IAction action= getAction(textEditor, ITextEditorActionConstants.NEXT); 211 actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_NEXT_ANNOTATION, action); 212 actionBars.setGlobalActionHandler(ITextEditorActionConstants.NEXT, action); 213 action= getAction(textEditor, ITextEditorActionConstants.PREVIOUS); 214 actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_PREVIOUS_ANNOTATION, action); 215 actionBars.setGlobalActionHandler(ITextEditorActionConstants.PREVIOUS, action); 216 action= getAction(textEditor, IJavaEditorActionConstants.COPY_QUALIFIED_NAME); 217 actionBars.setGlobalActionHandler(CopyQualifiedNameAction.ACTION_HANDLER_ID, action); 218 } 219 220 223 public void dispose() { 224 225 Iterator e= fPartListeners.iterator(); 226 while (e.hasNext()) 227 getPage().removePartListener((RetargetAction) e.next()); 228 fPartListeners.clear(); 229 230 setActiveEditor(null); 231 super.dispose(); 232 } 233 } 234 | Popular Tags |