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;
21 import net.sourceforge.phpdt.ui.actions.PHPdtActionConstants;
23 import org.eclipse.jface.action.IMenuManager;
24 import org.eclipse.jface.action.IStatusLineManager;
25 import org.eclipse.jface.action.Separator;
26 import org.eclipse.ui.IActionBars;
27 import org.eclipse.ui.IEditorPart;
28 import org.eclipse.ui.IWorkbenchActionConstants;
29 import org.eclipse.ui.IWorkbenchPage;
30 import org.eclipse.ui.actions.RetargetAction;
31 import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
32 import org.eclipse.ui.texteditor.ITextEditor;
33 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
34 import org.eclipse.ui.texteditor.RetargetTextEditorAction;
37 * Common base class for action contributors for Java editors.
39 public class BasicJavaEditorActionContributor extends BasicTextEditorActionContributor {
41 private List fPartListeners= new ArrayList();
43 private TogglePresentationAction fTogglePresentation;
44 // private GotoAnnotationAction fPreviousAnnotation;
45 // private GotoAnnotationAction fNextAnnotation;
47 private RetargetTextEditorAction fGotoMatchingBracket;
48 // private RetargetTextEditorAction fShowOutline;
49 // private RetargetTextEditorAction fOpenStructure;
50 // private RetargetTextEditorAction fOpenHierarchy;
52 private RetargetAction fRetargetShowJavaDoc;
53 private RetargetTextEditorAction fShowJavaDoc;
55 // private RetargetTextEditorAction fStructureSelectEnclosingAction;
56 // private RetargetTextEditorAction fStructureSelectNextAction;
57 // private RetargetTextEditorAction fStructureSelectPreviousAction;
58 // private RetargetTextEditorAction fStructureSelectHistoryAction;
60 // private RetargetTextEditorAction fGotoNextMemberAction;
61 // private RetargetTextEditorAction fGotoPreviousMemberAction;
63 // private RetargetTextEditorAction fRemoveOccurrenceAnnotationsAction;
65 public BasicJavaEditorActionContributor() {
68 ResourceBundle b= PHPEditorMessages.getResourceBundle();
70 fRetargetShowJavaDoc= new RetargetAction(PHPdtActionConstants.SHOW_JAVA_DOC, PHPEditorMessages.getString("ShowJavaDoc.label")); //$NON-NLS-1$
71 fRetargetShowJavaDoc.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_JAVADOC);
72 markAsPartListener(fRetargetShowJavaDoc);
74 // actions that are "contributed" to editors, they are considered belonging to the active editor
75 fTogglePresentation= new TogglePresentationAction();
77 // fPreviousAnnotation= new GotoAnnotationAction("PreviousAnnotation.", false); //$NON-NLS-1$
79 // fNextAnnotation= new GotoAnnotationAction("NextAnnotation.", true); //$NON-NLS-1$
81 fGotoMatchingBracket= new RetargetTextEditorAction(b, "GotoMatchingBracket."); //$NON-NLS-1$
82 fGotoMatchingBracket.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
84 fShowJavaDoc= new RetargetTextEditorAction(b, "ShowJavaDoc."); //$NON-NLS-1$
85 fShowJavaDoc.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_JAVADOC);
87 // fShowOutline= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ShowOutline."); //$NON-NLS-1$
88 // fShowOutline.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE);
90 // fOpenHierarchy= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "OpenHierarchy."); //$NON-NLS-1$
91 // fOpenHierarchy.setActionDefinitionId(PHPEditorActionDefinitionIds.OPEN_HIERARCHY);
93 // fOpenStructure= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "OpenStructure."); //$NON-NLS-1$
94 // fOpenStructure.setActionDefinitionId(PHPEditorActionDefinitionIds.OPEN_STRUCTURE);
96 // fStructureSelectEnclosingAction= new RetargetTextEditorAction(b, "StructureSelectEnclosing."); //$NON-NLS-1$
97 // fStructureSelectEnclosingAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_ENCLOSING);
98 // fStructureSelectNextAction= new RetargetTextEditorAction(b, "StructureSelectNext."); //$NON-NLS-1$
99 // fStructureSelectNextAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_NEXT);
100 // fStructureSelectPreviousAction= new RetargetTextEditorAction(b, "StructureSelectPrevious."); //$NON-NLS-1$
101 // fStructureSelectPreviousAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_PREVIOUS);
102 // fStructureSelectHistoryAction= new RetargetTextEditorAction(b, "StructureSelectHistory."); //$NON-NLS-1$
103 // fStructureSelectHistoryAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_LAST);
105 // fGotoNextMemberAction= new RetargetTextEditorAction(b, "GotoNextMember."); //$NON-NLS-1$
106 // fGotoNextMemberAction.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_NEXT_MEMBER);
107 // fGotoPreviousMemberAction= new RetargetTextEditorAction(b, "GotoPreviousMember."); //$NON-NLS-1$
108 // fGotoPreviousMemberAction.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_PREVIOUS_MEMBER);
110 // fRemoveOccurrenceAnnotationsAction= new RetargetTextEditorAction(b, "RemoveOccurrenceAnnotations."); //$NON-NLS-1$
111 // fRemoveOccurrenceAnnotationsAction.setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_OCCURRENCE_ANNOTATIONS);
114 protected final void markAsPartListener(RetargetAction action) {
115 fPartListeners.add(action);
119 * @see IEditorActionBarContributor#init(IActionBars, IWorkbenchPage)
121 public void init(IActionBars bars, IWorkbenchPage page) {
122 Iterator e= fPartListeners.iterator();
124 page.addPartListener((RetargetAction) e.next());
126 super.init(bars, page);
128 // register actions that have a dynamic editor.
129 // bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_NEXT_ANNOTATION, fNextAnnotation);
130 // bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_PREVIOUS_ANNOTATION, fPreviousAnnotation);
131 // bars.setGlobalActionHandler(ITextEditorActionConstants.NEXT, fNextAnnotation);
132 // bars.setGlobalActionHandler(ITextEditorActionConstants.PREVIOUS, fPreviousAnnotation);
133 bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY, fTogglePresentation);
135 bars.setGlobalActionHandler(PHPdtActionConstants.SHOW_JAVA_DOC, fShowJavaDoc);
139 * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(org.eclipse.jface.action.IMenuManager)
141 public void contributeToMenu(IMenuManager menu) {
143 super.contributeToMenu(menu);
145 IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
146 if (editMenu != null) {
148 editMenu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
149 editMenu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
150 editMenu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
152 // MenuManager structureSelection= new MenuManager(PHPEditorMessages.getString("ExpandSelectionMenu.label"), "expandSelection"); //$NON-NLS-1$ //$NON-NLS-2$
153 // structureSelection.add(fStructureSelectEnclosingAction);
154 // structureSelection.add(fStructureSelectNextAction);
155 // structureSelection.add(fStructureSelectPreviousAction);
156 // structureSelection.add(fStructureSelectHistoryAction);
157 // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN, structureSelection);
159 editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fRetargetShowJavaDoc);
162 // IMenuManager navigateMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_NAVIGATE);
163 // if (navigateMenu != null) {
164 // navigateMenu.appendToGroup(IWorkbenchActionConstants.SHOW_EXT, fShowOutline);
165 // navigateMenu.appendToGroup(IWorkbenchActionConstants.SHOW_EXT, fOpenHierarchy);
168 IMenuManager gotoMenu= menu.findMenuUsingPath("navigate/goTo"); //$NON-NLS-1$
169 if (gotoMenu != null) {
170 gotoMenu.add(new Separator("additions2")); //$NON-NLS-1$
171 // gotoMenu.appendToGroup("additions2", fGotoPreviousMemberAction); //$NON-NLS-1$
172 // gotoMenu.appendToGroup("additions2", fGotoNextMemberAction); //$NON-NLS-1$
173 gotoMenu.appendToGroup("additions2", fGotoMatchingBracket); //$NON-NLS-1$
178 * @see EditorActionBarContributor#setActiveEditor(IEditorPart)
180 public void setActiveEditor(IEditorPart part) {
182 super.setActiveEditor(part);
184 IActionBars actionBars= getActionBars();
185 IStatusLineManager manager= actionBars.getStatusLineManager();
186 manager.setMessage(null);
187 manager.setErrorMessage(null);
189 ITextEditor textEditor= null;
190 if (part instanceof ITextEditor)
191 textEditor= (ITextEditor) part;
193 fTogglePresentation.setEditor(textEditor);
194 // fPreviousAnnotation.setEditor(textEditor);
195 // fNextAnnotation.setEditor(textEditor);
197 fGotoMatchingBracket.setAction(getAction(textEditor, GotoMatchingBracketAction.GOTO_MATCHING_BRACKET));
198 fShowJavaDoc.setAction(getAction(textEditor, "ShowJavaDoc")); //$NON-NLS-1$
199 // fShowOutline.setAction(getAction(textEditor, IJavaEditorActionDefinitionIds.SHOW_OUTLINE));
200 // fOpenHierarchy.setAction(getAction(textEditor, IJavaEditorActionDefinitionIds.OPEN_HIERARCHY));
201 // fOpenStructure.setAction(getAction(textEditor, IJavaEditorActionDefinitionIds.OPEN_STRUCTURE));
203 // fStructureSelectEnclosingAction.setAction(getAction(textEditor, StructureSelectionAction.ENCLOSING));
204 // fStructureSelectNextAction.setAction(getAction(textEditor, StructureSelectionAction.NEXT));
205 // fStructureSelectPreviousAction.setAction(getAction(textEditor, StructureSelectionAction.PREVIOUS));
206 // fStructureSelectHistoryAction.setAction(getAction(textEditor, StructureSelectionAction.HISTORY));
208 // fGotoNextMemberAction.setAction(getAction(textEditor, GoToNextPreviousMemberAction.NEXT_MEMBER));
209 // fGotoPreviousMemberAction.setAction(getAction(textEditor, GoToNextPreviousMemberAction.PREVIOUS_MEMBER));
211 // fRemoveOccurrenceAnnotationsAction.setAction(getAction(textEditor, "RemoveOccurrenceAnnotations")); //$NON-NLS-1$
213 if (part instanceof PHPEditor) {
214 PHPEditor javaEditor= (PHPEditor) part;
215 javaEditor.getActionGroup().fillActionBars(getActionBars());
216 FoldingActionGroup foldingActions= javaEditor.getFoldingActionGroup();
217 if (foldingActions != null)
218 foldingActions.updateActionBars();
223 * @see IEditorActionBarContributor#dispose()
225 public void dispose() {
227 Iterator e= fPartListeners.iterator();
229 getPage().removePartListener((RetargetAction) e.next());
230 fPartListeners.clear();
232 setActiveEditor(null);