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.ITextEditor;
32 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
33 import org.eclipse.ui.texteditor.RetargetTextEditorAction;
36 * Common base class for action contributors for Java editors.
38 public class BasicJavaEditorActionContributor extends
39 BasicTextEditorActionContributor {
41 private List fPartListeners = new ArrayList();
43 private TogglePresentationAction fTogglePresentation;
45 // private GotoAnnotationAction fPreviousAnnotation;
46 // private GotoAnnotationAction fNextAnnotation;
48 private RetargetTextEditorAction fGotoMatchingBracket;
50 // private RetargetTextEditorAction fShowOutline;
51 // private RetargetTextEditorAction fOpenStructure;
52 // private RetargetTextEditorAction fOpenHierarchy;
54 // private RetargetAction fRetargetShowJavaDoc;
55 // private RetargetTextEditorAction fShowJavaDoc;
57 // private RetargetTextEditorAction fStructureSelectEnclosingAction;
58 // private RetargetTextEditorAction fStructureSelectNextAction;
59 // private RetargetTextEditorAction fStructureSelectPreviousAction;
60 // private RetargetTextEditorAction fStructureSelectHistoryAction;
62 private RetargetTextEditorAction fGotoNextMemberAction;
64 private RetargetTextEditorAction fGotoPreviousMemberAction;
67 // private RetargetTextEditorAction fRemoveOccurrenceAnnotationsAction;
69 public BasicJavaEditorActionContributor() {
72 ResourceBundle b = PHPEditorMessages.getResourceBundle();
74 // fRetargetShowJavaDoc= new
75 // RetargetAction(PHPdtActionConstants.SHOW_JAVA_DOC,
76 // PHPEditorMessages.getString("ShowJavaDoc.label")); //$NON-NLS-1$
77 // fRetargetShowJavaDoc.setActionDefinitionId(net.sourceforge.phpdt.ui.actions.PHPEditorActionDefinitionIds.SHOW_JAVADOC);
78 // markAsPartListener(fRetargetShowJavaDoc);
80 // actions that are "contributed" to editors, they are considered
81 // belonging to the active editor
82 fTogglePresentation = new TogglePresentationAction();
84 // fPreviousAnnotation= new GotoAnnotationAction("PreviousAnnotation.",
85 // false); //$NON-NLS-1$
87 // fNextAnnotation= new GotoAnnotationAction("NextAnnotation.", true);
90 fGotoMatchingBracket = new RetargetTextEditorAction(b,
91 "GotoMatchingBracket."); //$NON-NLS-1$
93 .setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
95 // fShowJavaDoc= new RetargetTextEditorAction(b, "ShowJavaDoc.");
97 // fShowJavaDoc.setActionDefinitionId(net.sourceforge.phpdt.ui.actions.PHPEditorActionDefinitionIds.SHOW_JAVADOC);
100 // RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(),
101 // "ShowOutline."); //$NON-NLS-1$
102 // fShowOutline.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE);
104 // fOpenHierarchy= new
105 // RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(),
106 // "OpenHierarchy."); //$NON-NLS-1$
107 // fOpenHierarchy.setActionDefinitionId(PHPEditorActionDefinitionIds.OPEN_HIERARCHY);
109 // fOpenStructure= new
110 // RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(),
111 // "OpenStructure."); //$NON-NLS-1$
112 // fOpenStructure.setActionDefinitionId(PHPEditorActionDefinitionIds.OPEN_STRUCTURE);
114 // fStructureSelectEnclosingAction= new RetargetTextEditorAction(b,
115 // "StructureSelectEnclosing."); //$NON-NLS-1$
116 // fStructureSelectEnclosingAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_ENCLOSING);
117 // fStructureSelectNextAction= new RetargetTextEditorAction(b,
118 // "StructureSelectNext."); //$NON-NLS-1$
119 // fStructureSelectNextAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_NEXT);
120 // fStructureSelectPreviousAction= new RetargetTextEditorAction(b,
121 // "StructureSelectPrevious."); //$NON-NLS-1$
122 // fStructureSelectPreviousAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_PREVIOUS);
123 // fStructureSelectHistoryAction= new RetargetTextEditorAction(b,
124 // "StructureSelectHistory."); //$NON-NLS-1$
125 // fStructureSelectHistoryAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_LAST);
127 fGotoNextMemberAction = new RetargetTextEditorAction(b,
128 "GotoNextMember."); //$NON-NLS-1$
129 fGotoNextMemberAction
130 .setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_NEXT_MEMBER);
131 fGotoPreviousMemberAction = new RetargetTextEditorAction(b,
132 "GotoPreviousMember."); //$NON-NLS-1$
133 fGotoPreviousMemberAction
134 .setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_PREVIOUS_MEMBER);
136 // fRemoveOccurrenceAnnotationsAction= new RetargetTextEditorAction(b,
137 // "RemoveOccurrenceAnnotations."); //$NON-NLS-1$
138 // fRemoveOccurrenceAnnotationsAction.setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_OCCURRENCE_ANNOTATIONS);
141 protected final void markAsPartListener(RetargetAction action) {
142 fPartListeners.add(action);
146 * @see IEditorActionBarContributor#init(IActionBars, IWorkbenchPage)
148 public void init(IActionBars bars, IWorkbenchPage page) {
149 Iterator e = fPartListeners.iterator();
151 page.addPartListener((RetargetAction) e.next());
153 super.init(bars, page);
155 // register actions that have a dynamic editor.
156 // bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_NEXT_ANNOTATION,
158 // bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_PREVIOUS_ANNOTATION,
159 // fPreviousAnnotation);
160 // bars.setGlobalActionHandler(ITextEditorActionConstants.NEXT,
162 // bars.setGlobalActionHandler(ITextEditorActionConstants.PREVIOUS,
163 // fPreviousAnnotation);
165 .setGlobalActionHandler(
166 ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY,
167 fTogglePresentation);
169 // bars.setGlobalActionHandler(PHPdtActionConstants.SHOW_JAVA_DOC,
174 * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(org.eclipse.jface.action.IMenuManager)
176 public void contributeToMenu(IMenuManager menu) {
178 super.contributeToMenu(menu);
180 IMenuManager editMenu = menu
181 .findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
182 if (editMenu != null) {
184 editMenu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
185 editMenu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
186 editMenu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
188 // MenuManager structureSelection= new
189 // MenuManager(PHPEditorMessages.getString("ExpandSelectionMenu.label"),
190 // "expandSelection"); //$NON-NLS-1$ //$NON-NLS-2$
191 // structureSelection.add(fStructureSelectEnclosingAction);
192 // structureSelection.add(fStructureSelectNextAction);
193 // structureSelection.add(fStructureSelectPreviousAction);
194 // structureSelection.add(fStructureSelectHistoryAction);
195 // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN,
196 // structureSelection);
198 // editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE,
199 // fRetargetShowJavaDoc);
202 // IMenuManager navigateMenu=
203 // menu.findMenuUsingPath(IWorkbenchActionConstants.M_NAVIGATE);
204 // if (navigateMenu != null) {
205 // navigateMenu.appendToGroup(IWorkbenchActionConstants.SHOW_EXT,
207 // navigateMenu.appendToGroup(IWorkbenchActionConstants.SHOW_EXT,
211 IMenuManager gotoMenu = menu.findMenuUsingPath("navigate/goTo"); //$NON-NLS-1$
212 if (gotoMenu != null) {
213 gotoMenu.add(new Separator("additions2")); //$NON-NLS-1$
214 gotoMenu.appendToGroup("additions2", fGotoPreviousMemberAction); //$NON-NLS-1$
215 gotoMenu.appendToGroup("additions2", fGotoNextMemberAction); //$NON-NLS-1$
216 gotoMenu.appendToGroup("additions2", fGotoMatchingBracket); //$NON-NLS-1$
221 * @see EditorActionBarContributor#setActiveEditor(IEditorPart)
223 public void setActiveEditor(IEditorPart part) {
225 super.setActiveEditor(part);
227 IActionBars actionBars = getActionBars();
228 IStatusLineManager manager = actionBars.getStatusLineManager();
229 manager.setMessage(null);
230 manager.setErrorMessage(null);
232 ITextEditor textEditor = null;
233 if (part instanceof ITextEditor)
234 textEditor = (ITextEditor) part;
236 fTogglePresentation.setEditor(textEditor);
237 // fPreviousAnnotation.setEditor(textEditor);
238 // fNextAnnotation.setEditor(textEditor);
240 fGotoMatchingBracket.setAction(getAction(textEditor,
241 GotoMatchingBracketAction.GOTO_MATCHING_BRACKET));
242 // fShowJavaDoc.setAction(getAction(textEditor, "ShowJavaDoc"));
244 // fShowOutline.setAction(getAction(textEditor,
245 // IJavaEditorActionDefinitionIds.SHOW_OUTLINE));
246 // fOpenHierarchy.setAction(getAction(textEditor,
247 // IJavaEditorActionDefinitionIds.OPEN_HIERARCHY));
248 // fOpenStructure.setAction(getAction(textEditor,
249 // IJavaEditorActionDefinitionIds.OPEN_STRUCTURE));
251 // fStructureSelectEnclosingAction.setAction(getAction(textEditor,
252 // StructureSelectionAction.ENCLOSING));
253 // fStructureSelectNextAction.setAction(getAction(textEditor,
254 // StructureSelectionAction.NEXT));
255 // fStructureSelectPreviousAction.setAction(getAction(textEditor,
256 // StructureSelectionAction.PREVIOUS));
257 // fStructureSelectHistoryAction.setAction(getAction(textEditor,
258 // StructureSelectionAction.HISTORY));
260 // fGotoNextMemberAction.setAction(getAction(textEditor,
261 // GoToNextPreviousMemberAction.NEXT_MEMBER));
262 // fGotoPreviousMemberAction.setAction(getAction(textEditor,
263 // GoToNextPreviousMemberAction.PREVIOUS_MEMBER));
265 // fRemoveOccurrenceAnnotationsAction.setAction(getAction(textEditor,
266 // "RemoveOccurrenceAnnotations")); //$NON-NLS-1$
267 if (part instanceof PHPEditor) {
268 PHPEditor javaEditor = (PHPEditor) part;
269 javaEditor.getActionGroup().fillActionBars(getActionBars());
270 FoldingActionGroup foldingActions = javaEditor
271 .getFoldingActionGroup();
272 if (foldingActions != null)
273 foldingActions.updateActionBars();
278 * @see IEditorActionBarContributor#dispose()
280 public void dispose() {
282 Iterator e = fPartListeners.iterator();
284 getPage().removePartListener((RetargetAction) e.next());
285 fPartListeners.clear();
287 setActiveEditor(null);