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.ui.IContextMenuConstants;
19 import net.sourceforge.phpdt.ui.actions.GotoMatchingBracketAction;
20 import net.sourceforge.phpdt.ui.actions.PHPdtActionConstants;
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 BasicTextEditorActionContributor {
40 private List fPartListeners= new ArrayList();
42 private TogglePresentationAction fTogglePresentation;
43 // private GotoAnnotationAction fPreviousAnnotation;
44 // private GotoAnnotationAction fNextAnnotation;
46 private RetargetTextEditorAction fGotoMatchingBracket;
47 // private RetargetTextEditorAction fShowOutline;
48 // private RetargetTextEditorAction fOpenStructure;
49 // private RetargetTextEditorAction fOpenHierarchy;
51 private RetargetAction fRetargetShowJavaDoc;
52 private RetargetTextEditorAction fShowJavaDoc;
54 // private RetargetTextEditorAction fStructureSelectEnclosingAction;
55 // private RetargetTextEditorAction fStructureSelectNextAction;
56 // private RetargetTextEditorAction fStructureSelectPreviousAction;
57 // private RetargetTextEditorAction fStructureSelectHistoryAction;
59 // private RetargetTextEditorAction fGotoNextMemberAction;
60 // private RetargetTextEditorAction fGotoPreviousMemberAction;
62 // private RetargetTextEditorAction fRemoveOccurrenceAnnotationsAction;
64 public BasicJavaEditorActionContributor() {
67 ResourceBundle b= PHPEditorMessages.getResourceBundle();
69 fRetargetShowJavaDoc= new RetargetAction(PHPdtActionConstants.SHOW_JAVA_DOC, PHPEditorMessages.getString("ShowJavaDoc.label")); //$NON-NLS-1$
70 fRetargetShowJavaDoc.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_JAVADOC);
71 markAsPartListener(fRetargetShowJavaDoc);
73 // actions that are "contributed" to editors, they are considered belonging to the active editor
74 fTogglePresentation= new TogglePresentationAction();
76 // fPreviousAnnotation= new GotoAnnotationAction("PreviousAnnotation.", false); //$NON-NLS-1$
78 // fNextAnnotation= new GotoAnnotationAction("NextAnnotation.", true); //$NON-NLS-1$
80 fGotoMatchingBracket= new RetargetTextEditorAction(b, "GotoMatchingBracket."); //$NON-NLS-1$
81 fGotoMatchingBracket.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
83 fShowJavaDoc= new RetargetTextEditorAction(b, "ShowJavaDoc."); //$NON-NLS-1$
84 fShowJavaDoc.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_JAVADOC);
86 // fShowOutline= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ShowOutline."); //$NON-NLS-1$
87 // fShowOutline.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE);
89 // fOpenHierarchy= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "OpenHierarchy."); //$NON-NLS-1$
90 // fOpenHierarchy.setActionDefinitionId(PHPEditorActionDefinitionIds.OPEN_HIERARCHY);
92 // fOpenStructure= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "OpenStructure."); //$NON-NLS-1$
93 // fOpenStructure.setActionDefinitionId(PHPEditorActionDefinitionIds.OPEN_STRUCTURE);
95 // fStructureSelectEnclosingAction= new RetargetTextEditorAction(b, "StructureSelectEnclosing."); //$NON-NLS-1$
96 // fStructureSelectEnclosingAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_ENCLOSING);
97 // fStructureSelectNextAction= new RetargetTextEditorAction(b, "StructureSelectNext."); //$NON-NLS-1$
98 // fStructureSelectNextAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_NEXT);
99 // fStructureSelectPreviousAction= new RetargetTextEditorAction(b, "StructureSelectPrevious."); //$NON-NLS-1$
100 // fStructureSelectPreviousAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_PREVIOUS);
101 // fStructureSelectHistoryAction= new RetargetTextEditorAction(b, "StructureSelectHistory."); //$NON-NLS-1$
102 // fStructureSelectHistoryAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_LAST);
104 // fGotoNextMemberAction= new RetargetTextEditorAction(b, "GotoNextMember."); //$NON-NLS-1$
105 // fGotoNextMemberAction.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_NEXT_MEMBER);
106 // fGotoPreviousMemberAction= new RetargetTextEditorAction(b, "GotoPreviousMember."); //$NON-NLS-1$
107 // fGotoPreviousMemberAction.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_PREVIOUS_MEMBER);
109 // fRemoveOccurrenceAnnotationsAction= new RetargetTextEditorAction(b, "RemoveOccurrenceAnnotations."); //$NON-NLS-1$
110 // fRemoveOccurrenceAnnotationsAction.setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_OCCURRENCE_ANNOTATIONS);
113 protected final void markAsPartListener(RetargetAction action) {
114 fPartListeners.add(action);
118 * @see IEditorActionBarContributor#init(IActionBars, IWorkbenchPage)
120 public void init(IActionBars bars, IWorkbenchPage page) {
121 Iterator e= fPartListeners.iterator();
123 page.addPartListener((RetargetAction) e.next());
125 super.init(bars, page);
127 // register actions that have a dynamic editor.
128 // bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_NEXT_ANNOTATION, fNextAnnotation);
129 // bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_PREVIOUS_ANNOTATION, fPreviousAnnotation);
130 // bars.setGlobalActionHandler(ITextEditorActionConstants.NEXT, fNextAnnotation);
131 // bars.setGlobalActionHandler(ITextEditorActionConstants.PREVIOUS, fPreviousAnnotation);
132 bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY, fTogglePresentation);
134 bars.setGlobalActionHandler(PHPdtActionConstants.SHOW_JAVA_DOC, fShowJavaDoc);
138 * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(org.eclipse.jface.action.IMenuManager)
140 public void contributeToMenu(IMenuManager menu) {
142 super.contributeToMenu(menu);
144 IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
145 if (editMenu != null) {
147 editMenu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
148 editMenu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
149 editMenu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
151 // MenuManager structureSelection= new MenuManager(PHPEditorMessages.getString("ExpandSelectionMenu.label"), "expandSelection"); //$NON-NLS-1$ //$NON-NLS-2$
152 // structureSelection.add(fStructureSelectEnclosingAction);
153 // structureSelection.add(fStructureSelectNextAction);
154 // structureSelection.add(fStructureSelectPreviousAction);
155 // structureSelection.add(fStructureSelectHistoryAction);
156 // editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN, structureSelection);
158 editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fRetargetShowJavaDoc);
161 // IMenuManager navigateMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_NAVIGATE);
162 // if (navigateMenu != null) {
163 // navigateMenu.appendToGroup(IWorkbenchActionConstants.SHOW_EXT, fShowOutline);
164 // navigateMenu.appendToGroup(IWorkbenchActionConstants.SHOW_EXT, fOpenHierarchy);
167 IMenuManager gotoMenu= menu.findMenuUsingPath("navigate/goTo"); //$NON-NLS-1$
168 if (gotoMenu != null) {
169 gotoMenu.add(new Separator("additions2")); //$NON-NLS-1$
170 // gotoMenu.appendToGroup("additions2", fGotoPreviousMemberAction); //$NON-NLS-1$
171 // gotoMenu.appendToGroup("additions2", fGotoNextMemberAction); //$NON-NLS-1$
172 gotoMenu.appendToGroup("additions2", fGotoMatchingBracket); //$NON-NLS-1$
177 * @see EditorActionBarContributor#setActiveEditor(IEditorPart)
179 public void setActiveEditor(IEditorPart part) {
181 super.setActiveEditor(part);
183 IActionBars actionBars= getActionBars();
184 IStatusLineManager manager= actionBars.getStatusLineManager();
185 manager.setMessage(null);
186 manager.setErrorMessage(null);
188 ITextEditor textEditor= null;
189 if (part instanceof ITextEditor)
190 textEditor= (ITextEditor) part;
192 fTogglePresentation.setEditor(textEditor);
193 // fPreviousAnnotation.setEditor(textEditor);
194 // fNextAnnotation.setEditor(textEditor);
196 fGotoMatchingBracket.setAction(getAction(textEditor, GotoMatchingBracketAction.GOTO_MATCHING_BRACKET));
197 fShowJavaDoc.setAction(getAction(textEditor, "ShowJavaDoc")); //$NON-NLS-1$
198 // fShowOutline.setAction(getAction(textEditor, IJavaEditorActionDefinitionIds.SHOW_OUTLINE));
199 // fOpenHierarchy.setAction(getAction(textEditor, IJavaEditorActionDefinitionIds.OPEN_HIERARCHY));
200 // fOpenStructure.setAction(getAction(textEditor, IJavaEditorActionDefinitionIds.OPEN_STRUCTURE));
202 // fStructureSelectEnclosingAction.setAction(getAction(textEditor, StructureSelectionAction.ENCLOSING));
203 // fStructureSelectNextAction.setAction(getAction(textEditor, StructureSelectionAction.NEXT));
204 // fStructureSelectPreviousAction.setAction(getAction(textEditor, StructureSelectionAction.PREVIOUS));
205 // fStructureSelectHistoryAction.setAction(getAction(textEditor, StructureSelectionAction.HISTORY));
207 // fGotoNextMemberAction.setAction(getAction(textEditor, GoToNextPreviousMemberAction.NEXT_MEMBER));
208 // fGotoPreviousMemberAction.setAction(getAction(textEditor, GoToNextPreviousMemberAction.PREVIOUS_MEMBER));
210 // fRemoveOccurrenceAnnotationsAction.setAction(getAction(textEditor, "RemoveOccurrenceAnnotations")); //$NON-NLS-1$
212 if (part instanceof PHPEditor) {
213 PHPEditor javaEditor= (PHPEditor) part;
214 javaEditor.getActionGroup().fillActionBars(getActionBars());
219 * @see IEditorActionBarContributor#dispose()
221 public void dispose() {
223 Iterator e= fPartListeners.iterator();
225 getPage().removePartListener((RetargetAction) e.next());
226 fPartListeners.clear();
228 setActiveEditor(null);