KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > editor > AntEditorActionContributor


1 /*******************************************************************************
2  * Copyright (c) 2002, 2005 GEBIT Gesellschaft fuer EDV-Beratung
3  * und Informatik-Technologien mbH,
4  * Berlin, Duesseldorf, Frankfurt (Germany) and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * GEBIT Gesellschaft fuer EDV-Beratung und Informatik-Technologien mbH - initial API and implementation
12  * IBM Corporation - bug fixes
13  * John-Mason P. Shackelford - bug 40255
14  *******************************************************************************/

15
16 package org.eclipse.ant.internal.ui.editor;
17
18 import java.util.ResourceBundle JavaDoc;
19
20 import org.eclipse.ant.internal.ui.editor.actions.FoldingActionGroup;
21 import org.eclipse.ant.internal.ui.editor.actions.OpenDeclarationAction;
22 import org.eclipse.ant.internal.ui.editor.actions.OpenExternalDocAction;
23 import org.eclipse.ant.internal.ui.editor.actions.ToggleAutoReconcileAction;
24 import org.eclipse.ant.internal.ui.editor.actions.ToggleMarkOccurrencesAction;
25 import org.eclipse.ant.internal.ui.editor.actions.TogglePresentationAction;
26 import org.eclipse.jface.action.IMenuManager;
27 import org.eclipse.jface.action.Separator;
28 import org.eclipse.ui.IActionBars;
29 import org.eclipse.ui.IEditorPart;
30 import org.eclipse.ui.IWorkbenchActionConstants;
31 import org.eclipse.ui.IWorkbenchPage;
32 import org.eclipse.ui.editors.text.TextEditorActionContributor;
33 import org.eclipse.ui.texteditor.ITextEditor;
34 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
35 import org.eclipse.ui.texteditor.RetargetTextEditorAction;
36
37 /**
38  * Contributes interesting Ant Editor actions to the desktop's Edit menu and the toolbar.
39  *
40  */

41 public class AntEditorActionContributor extends TextEditorActionContributor {
42
43     private final static String JavaDoc TOGGLE_MARK_OCCURRENCES_ID= "org.eclipse.ant.ui.toggleMarkOccurrences"; //$NON-NLS-1$
44
protected RetargetTextEditorAction fContentAssistProposal;
45     protected RetargetTextEditorAction fContentFormat;
46     private OpenDeclarationAction fOpenDeclarationAction;
47     private TogglePresentationAction fTogglePresentation;
48     private OpenExternalDocAction fOpenExternalDocAction;
49     private ToggleMarkOccurrencesAction fToggleMarkOccurrencesAction;
50     private ToggleAutoReconcileAction fToggleAutoReconcileAction;
51
52     public AntEditorActionContributor() {
53         super();
54         ResourceBundle JavaDoc bundle = AntEditorMessages.getResourceBundle();
55         fContentAssistProposal = new RetargetTextEditorAction(bundle, "ContentAssistProposal."); //$NON-NLS-1$
56
fContentFormat = new RetargetTextEditorAction(bundle, "ContentFormat."); //$NON-NLS-1$
57
fTogglePresentation= new TogglePresentationAction();
58         fToggleMarkOccurrencesAction= new ToggleMarkOccurrencesAction();
59         fToggleAutoReconcileAction= new ToggleAutoReconcileAction();
60         
61     }
62     
63     protected void initializeActions(AntEditor editor) {
64         fOpenDeclarationAction= new OpenDeclarationAction(editor);
65         fOpenExternalDocAction= new OpenExternalDocAction(editor);
66     }
67     
68     private void doSetActiveEditor(IEditorPart part) {
69         super.setActiveEditor(part);
70
71         ITextEditor editor= null;
72         if (part instanceof ITextEditor) {
73             editor= (ITextEditor) part;
74         }
75
76         fContentAssistProposal.setAction(getAction(editor, "ContentAssistProposal")); //$NON-NLS-1$
77
fContentFormat.setAction(getAction(editor, "ContentFormat")); //$NON-NLS-1$
78

79         if (editor instanceof AntEditor) {
80             AntEditor antEditor= (AntEditor) part;
81             if (fOpenDeclarationAction == null) {
82                 initializeActions(antEditor);
83                 contributeToMenu(getActionBars().getMenuManager());
84             }
85             
86             FoldingActionGroup foldingActions= antEditor.getFoldingActionGroup();
87             if (foldingActions != null) {
88                 foldingActions.updateActionBars();
89             }
90             if (fOpenDeclarationAction != null) {
91                 fOpenDeclarationAction.setEditor(antEditor);
92             }
93             if (fOpenExternalDocAction != null) {
94                 fOpenExternalDocAction.setActiveEditor(null, antEditor);
95             }
96         }
97         
98         if (fTogglePresentation != null) {
99             fTogglePresentation.setEditor(editor);
100         }
101         if (fToggleMarkOccurrencesAction != null) {
102             fToggleMarkOccurrencesAction.setEditor(editor);
103         }
104         if (fToggleAutoReconcileAction != null) {
105             fToggleAutoReconcileAction.setEditor(editor);
106         }
107     }
108     
109     /* (non-Javadoc)
110      * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(org.eclipse.jface.action.IMenuManager)
111      */

112     public void contributeToMenu(IMenuManager menu) {
113         if (fOpenDeclarationAction == null) {
114             return;
115         }
116         super.contributeToMenu(menu);
117         
118         IMenuManager navigateMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_NAVIGATE);
119         if (navigateMenu != null) {
120             navigateMenu.appendToGroup(IWorkbenchActionConstants.OPEN_EXT, fOpenDeclarationAction);
121             navigateMenu.appendToGroup(IWorkbenchActionConstants.OPEN_EXT, fOpenExternalDocAction);
122             navigateMenu.setVisible(true);
123         }
124     }
125
126     /* (non-Javadoc)
127      * @see org.eclipse.ui.part.EditorActionBarContributor#init(org.eclipse.ui.IActionBars)
128      */

129     public void init(IActionBars bars) {
130         super.init(bars);
131         
132         IMenuManager menuManager= bars.getMenuManager();
133         IMenuManager editMenu= menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
134         if (editMenu != null) {
135             editMenu.add(new Separator());
136             editMenu.add(fContentAssistProposal);
137             editMenu.add(fContentFormat);
138         }
139     }
140     
141     /* (non-Javadoc)
142      * @see org.eclipse.ui.IEditorActionBarContributor#setActiveEditor(org.eclipse.ui.IEditorPart)
143      */

144     public void setActiveEditor(IEditorPart part) {
145         doSetActiveEditor(part);
146     }
147     
148     /* (non-Javadoc)
149      * @see org.eclipse.ui.IEditorActionBarContributor#dispose()
150      */

151     public void dispose() {
152         doSetActiveEditor(null);
153         super.dispose();
154     }
155     
156     /* (non-Javadoc)
157      * @see org.eclipse.ui.IEditorActionBarContributor#init(org.eclipse.ui.IActionBars, org.eclipse.ui.IWorkbenchPage)
158      */

159     public void init(IActionBars bars, IWorkbenchPage page) {
160         super.init(bars, page);
161         bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY, fTogglePresentation);
162         bars.setGlobalActionHandler(TOGGLE_MARK_OCCURRENCES_ID, fToggleMarkOccurrencesAction);
163         bars.setGlobalActionHandler("org.eclipse.ant.ui.toggleAutoReconcile", fToggleAutoReconcileAction); //$NON-NLS-1$
164
}
165 }
166
Popular Tags