1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpeclipse.phpeditor;
13 import java.util.ArrayList;
14 import java.util.Iterator;
15 import java.util.List;
16 import java.util.ResourceBundle;
18 import net.sourceforge.phpdt.internal.ui.actions.FoldingActionGroup;
19 import net.sourceforge.phpdt.ui.IContextMenuConstants;
20 import net.sourceforge.phpdt.ui.actions.GotoMatchingBracketAction;
22 import org.eclipse.jface.action.IMenuManager;
23 import org.eclipse.jface.action.IStatusLineManager;
24 import org.eclipse.jface.action.Separator;
25 import org.eclipse.ui.IActionBars;
26 import org.eclipse.ui.IEditorPart;
27 import org.eclipse.ui.IWorkbenchActionConstants;
28 import org.eclipse.ui.IWorkbenchPage;
29 import org.eclipse.ui.actions.RetargetAction;
30 import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
31 import org.eclipse.ui.texteditor.GotoAnnotationAction;
32 import org.eclipse.ui.texteditor.ITextEditor;
33 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
34 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
35 import org.eclipse.ui.texteditor.RetargetTextEditorAction;
38 * Common base class for action contributors for Java editors.
40 public class BasicJavaEditorActionContributor extends
41 BasicTextEditorActionContributor {
43 private List fPartListeners = new ArrayList();
45 private TogglePresentationAction fTogglePresentation;
47 private GotoAnnotationAction fPreviousAnnotation;
48 private GotoAnnotationAction fNextAnnotation;
50 private RetargetTextEditorAction fGotoMatchingBracket;
52 // private RetargetTextEditorAction fShowOutline;
53 // private RetargetTextEditorAction fOpenStructure;
54 // private RetargetTextEditorAction fOpenHierarchy;
56 // private RetargetAction fRetargetShowJavaDoc;
57 // private RetargetTextEditorAction fShowJavaDoc;
59 // private RetargetTextEditorAction fStructureSelectEnclosingAction;
60 // private RetargetTextEditorAction fStructureSelectNextAction;
61 // private RetargetTextEditorAction fStructureSelectPreviousAction;
62 // private RetargetTextEditorAction fStructureSelectHistoryAction;
64 private RetargetTextEditorAction fGotoNextMemberAction;
66 private RetargetTextEditorAction fGotoPreviousMemberAction;
69 // private RetargetTextEditorAction fRemoveOccurrenceAnnotationsAction;
71 public BasicJavaEditorActionContributor() {
74 ResourceBundle b = PHPEditorMessages.getResourceBundle();
76 // fRetargetShowJavaDoc= new
77 // RetargetAction(PHPdtActionConstants.SHOW_JAVA_DOC,
78 // PHPEditorMessages.getString("ShowJavaDoc.label")); //$NON-NLS-1$
79 // fRetargetShowJavaDoc.setActionDefinitionId(net.sourceforge.phpdt.ui.actions.PHPEditorActionDefinitionIds.SHOW_JAVADOC);
80 // markAsPartListener(fRetargetShowJavaDoc);
82 // actions that are "contributed" to editors, they are considered
83 // belonging to the active editor
84 fTogglePresentation = new TogglePresentationAction();
86 fPreviousAnnotation = new GotoAnnotationAction(b,
87 "PreviousAnnotation.", null, false); //$NON-NLS-1$
88 fNextAnnotation = new GotoAnnotationAction(b,
89 "NextAnnotation.", null, true); //$NON-NLS-1$
91 fGotoMatchingBracket = new RetargetTextEditorAction(b,
92 "GotoMatchingBracket."); //$NON-NLS-1$
94 .setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
96 // fShowJavaDoc= new RetargetTextEditorAction(b, "ShowJavaDoc.");
98 // fShowJavaDoc.setActionDefinitionId(net.sourceforge.phpdt.ui.actions.PHPEditorActionDefinitionIds.SHOW_JAVADOC);
101 // RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(),
102 // "ShowOutline."); //$NON-NLS-1$
103 // fShowOutline.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE);
105 // fOpenHierarchy= new
106 // RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(),
107 // "OpenHierarchy."); //$NON-NLS-1$
108 // fOpenHierarchy.setActionDefinitionId(PHPEditorActionDefinitionIds.OPEN_HIERARCHY);
110 // fOpenStructure= new
111 // RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(),
112 // "OpenStructure."); //$NON-NLS-1$
113 // fOpenStructure.setActionDefinitionId(PHPEditorActionDefinitionIds.OPEN_STRUCTURE);
115 // fStructureSelectEnclosingAction= new RetargetTextEditorAction(b,
116 // "StructureSelectEnclosing."); //$NON-NLS-1$
117 // fStructureSelectEnclosingAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_ENCLOSING);
118 // fStructureSelectNextAction= new RetargetTextEditorAction(b,
119 // "StructureSelectNext."); //$NON-NLS-1$
120 // fStructureSelectNextAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_NEXT);
121 // fStructureSelectPreviousAction= new RetargetTextEditorAction(b,
122 // "StructureSelectPrevious."); //$NON-NLS-1$
123 // fStructureSelectPreviousAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_PREVIOUS);
124 // fStructureSelectHistoryAction= new RetargetTextEditorAction(b,
125 // "StructureSelectHistory."); //$NON-NLS-1$
126 // fStructureSelectHistoryAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_LAST);
128 fGotoNextMemberAction = new RetargetTextEditorAction(b,
129 "GotoNextMember."); //$NON-NLS-1$
130 fGotoNextMemberAction
131 .setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_NEXT_MEMBER);
132 fGotoPreviousMemberAction = new RetargetTextEditorAction(b,
133 "GotoPreviousMember."); //$NON-NLS-1$
134 fGotoPreviousMemberAction
135 .setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_PREVIOUS_MEMBER);
137 // fRemoveOccurrenceAnnotationsAction= new RetargetTextEditorAction(b,
138 // "RemoveOccurrenceAnnotations."); //$NON-NLS-1$
139 // fRemoveOccurrenceAnnotationsAction.setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_OCCURRENCE_ANNOTATIONS);
142 protected final void markAsPartListener(RetargetAction action) {
143 fPartListeners.add(action);
147 * @see IEditorActionBarContributor#init(IActionBars, IWorkbenchPage)
149 public void init(IActionBars bars, IWorkbenchPage page) {
150 Iterator e = fPartListeners.iterator();
152 page.addPartListener((RetargetAction) e.next());
154 super.init(bars, page);
156 // register actions that have a dynamic editor.
157 bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_NEXT_ANNOTATION, fNextAnnotation);
158 bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_PREVIOUS_ANNOTATION, fPreviousAnnotation);
159 bars.setGlobalActionHandler(ITextEditorActionConstants.NEXT, fNextAnnotation);
160 bars.setGlobalActionHandler(ITextEditorActionConstants.PREVIOUS, fPreviousAnnotation);
162 .setGlobalActionHandler(
163 ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY,
164 fTogglePresentation);
166 // bars.setGlobalActionHandler(PHPdtActionConstants.SHOW_JAVA_DOC,
171 * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(org.eclipse.jface.action.IMenuManager)
173 public void contributeToMenu(IMenuManager menu) {
175 super.contributeToMenu(menu);
177 IMenuManager editMenu = menu
178 .findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
179 if (editMenu != null) {
181 editMenu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
182 editMenu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
183 editMenu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
185 // MenuManager structureSelection= new
186 // MenuManager(PHPEditorMessages.getString("ExpandSelectionMenu.label"),
187 // "expandSelection"); //$NON-NLS-1$ //$NON-NLS-2$
188 // structureSelection.add(fStructureSelectEnclosingAction);
189 // structureSelection.add(fStructureSelectNextAction);
190 // structureSelection.add(fStructureSelectPreviousAction);
191 // structureSelection.add(fStructureSelectHistoryAction);
192 // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN,
193 // structureSelection);
195 // editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE,
196 // fRetargetShowJavaDoc);
199 // IMenuManager navigateMenu=
200 // menu.findMenuUsingPath(IWorkbenchActionConstants.M_NAVIGATE);
201 // if (navigateMenu != null) {
202 // navigateMenu.appendToGroup(IWorkbenchActionConstants.SHOW_EXT,
204 // navigateMenu.appendToGroup(IWorkbenchActionConstants.SHOW_EXT,
208 IMenuManager gotoMenu = menu.findMenuUsingPath("navigate/goTo"); //$NON-NLS-1$
209 if (gotoMenu != null) {
210 gotoMenu.add(new Separator("additions2")); //$NON-NLS-1$
211 gotoMenu.appendToGroup("additions2", fGotoPreviousMemberAction); //$NON-NLS-1$
212 gotoMenu.appendToGroup("additions2", fGotoNextMemberAction); //$NON-NLS-1$
213 gotoMenu.appendToGroup("additions2", fGotoMatchingBracket); //$NON-NLS-1$
218 * @see EditorActionBarContributor#setActiveEditor(IEditorPart)
220 public void setActiveEditor(IEditorPart part) {
222 super.setActiveEditor(part);
224 IActionBars actionBars = getActionBars();
225 IStatusLineManager manager = actionBars.getStatusLineManager();
226 manager.setMessage(null);
227 manager.setErrorMessage(null);
229 ITextEditor textEditor = null;
230 if (part instanceof ITextEditor)
231 textEditor = (ITextEditor) part;
233 fTogglePresentation.setEditor(textEditor);
234 fPreviousAnnotation.setEditor(textEditor);
235 fNextAnnotation.setEditor(textEditor);
237 fGotoMatchingBracket.setAction(getAction(textEditor,
238 GotoMatchingBracketAction.GOTO_MATCHING_BRACKET));
239 // fShowJavaDoc.setAction(getAction(textEditor, "ShowJavaDoc"));
241 // fShowOutline.setAction(getAction(textEditor,
242 // IJavaEditorActionDefinitionIds.SHOW_OUTLINE));
243 // fOpenHierarchy.setAction(getAction(textEditor,
244 // IJavaEditorActionDefinitionIds.OPEN_HIERARCHY));
245 // fOpenStructure.setAction(getAction(textEditor,
246 // IJavaEditorActionDefinitionIds.OPEN_STRUCTURE));
248 // fStructureSelectEnclosingAction.setAction(getAction(textEditor,
249 // StructureSelectionAction.ENCLOSING));
250 // fStructureSelectNextAction.setAction(getAction(textEditor,
251 // StructureSelectionAction.NEXT));
252 // fStructureSelectPreviousAction.setAction(getAction(textEditor,
253 // StructureSelectionAction.PREVIOUS));
254 // fStructureSelectHistoryAction.setAction(getAction(textEditor,
255 // StructureSelectionAction.HISTORY));
257 // fGotoNextMemberAction.setAction(getAction(textEditor,
258 // GoToNextPreviousMemberAction.NEXT_MEMBER));
259 // fGotoPreviousMemberAction.setAction(getAction(textEditor,
260 // GoToNextPreviousMemberAction.PREVIOUS_MEMBER));
262 // fRemoveOccurrenceAnnotationsAction.setAction(getAction(textEditor,
263 // "RemoveOccurrenceAnnotations")); //$NON-NLS-1$
264 if (part instanceof PHPEditor) {
265 PHPEditor javaEditor = (PHPEditor) part;
266 javaEditor.getActionGroup().fillActionBars(getActionBars());
267 FoldingActionGroup foldingActions = javaEditor
268 .getFoldingActionGroup();
269 if (foldingActions != null)
270 foldingActions.updateActionBars();
275 * @see IEditorActionBarContributor#dispose()
277 public void dispose() {
279 Iterator e = fPartListeners.iterator();
281 getPage().removePartListener((RetargetAction) e.next());
282 fPartListeners.clear();
284 setActiveEditor(null);