KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > javaeditor > BasicEditorActionContributor


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.javaeditor;
12
13
14 import org.eclipse.jface.action.IMenuManager;
15
16 import org.eclipse.ui.IActionBars;
17 import org.eclipse.ui.IEditorPart;
18 import org.eclipse.ui.IWorkbenchActionConstants;
19 import org.eclipse.ui.IWorkbenchPage;
20 import org.eclipse.ui.actions.RetargetAction;
21 import org.eclipse.ui.ide.IDEActionFactory;
22 import org.eclipse.ui.texteditor.ITextEditor;
23 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
24 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
25 import org.eclipse.ui.texteditor.RetargetTextEditorAction;
26
27 import org.eclipse.jdt.ui.IContextMenuConstants;
28 import org.eclipse.jdt.ui.actions.IJavaEditorActionDefinitionIds;
29 import org.eclipse.jdt.ui.actions.JdtActionConstants;
30
31 import org.eclipse.jdt.internal.ui.JavaPluginImages;
32
33
34 public class BasicEditorActionContributor extends BasicJavaEditorActionContributor {
35
36
37     protected RetargetAction fRetargetContentAssist;
38     protected RetargetTextEditorAction fContentAssist;
39     protected RetargetTextEditorAction fContextInformation;
40     protected RetargetTextEditorAction fCorrectionAssist;
41     protected RetargetTextEditorAction fChangeEncodingAction;
42
43
44     public BasicEditorActionContributor() {
45
46         fRetargetContentAssist= new RetargetAction(JdtActionConstants.CONTENT_ASSIST, JavaEditorMessages.ContentAssistProposal_label);
47         fRetargetContentAssist.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
48         markAsPartListener(fRetargetContentAssist);
49
50         fContentAssist= new RetargetTextEditorAction(JavaEditorMessages.getBundleForConstructedKeys(), "ContentAssistProposal."); //$NON-NLS-1$
51
fContentAssist.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
52         fContentAssist.setImageDescriptor(JavaPluginImages.DESC_ELCL_CODE_ASSIST);
53         fContentAssist.setDisabledImageDescriptor(JavaPluginImages.DESC_DLCL_CODE_ASSIST);
54
55         fContextInformation= new RetargetTextEditorAction(JavaEditorMessages.getBundleForConstructedKeys(), "ContentAssistContextInformation."); //$NON-NLS-1$
56
fContextInformation.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
57
58         fCorrectionAssist= new RetargetTextEditorAction(JavaEditorMessages.getBundleForConstructedKeys(), "CorrectionAssistProposal."); //$NON-NLS-1$
59
fCorrectionAssist.setActionDefinitionId(IJavaEditorActionDefinitionIds.CORRECTION_ASSIST_PROPOSALS);
60
61         fChangeEncodingAction= new RetargetTextEditorAction(JavaEditorMessages.getBundleForConstructedKeys(), "Editor.ChangeEncodingAction."); //$NON-NLS-1$
62
}
63
64     /*
65      * @see EditorActionBarContributor#contributeToMenu(IMenuManager)
66      */

67     public void contributeToMenu(IMenuManager menu) {
68
69         super.contributeToMenu(menu);
70
71         IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
72         if (editMenu != null) {
73             editMenu.add(fChangeEncodingAction);
74             editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fRetargetContentAssist);
75             editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fCorrectionAssist);
76             editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fContextInformation);
77         }
78     }
79
80     /*
81      * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
82      */

83     public void setActiveEditor(IEditorPart part) {
84         super.setActiveEditor(part);
85
86         ITextEditor textEditor= null;
87         if (part instanceof ITextEditor)
88             textEditor= (ITextEditor) part;
89
90         fContentAssist.setAction(getAction(textEditor, "ContentAssistProposal")); //$NON-NLS-1$
91
fContextInformation.setAction(getAction(textEditor, "ContentAssistContextInformation")); //$NON-NLS-1$
92
fCorrectionAssist.setAction(getAction(textEditor, "CorrectionAssistProposal")); //$NON-NLS-1$
93

94         fChangeEncodingAction.setAction(getAction(textEditor, ITextEditorActionConstants.CHANGE_ENCODING));
95
96         IActionBars actionBars= getActionBars();
97         actionBars.setGlobalActionHandler(JdtActionConstants.SHIFT_RIGHT, getAction(textEditor, "ShiftRight")); //$NON-NLS-1$
98
actionBars.setGlobalActionHandler(JdtActionConstants.SHIFT_LEFT, getAction(textEditor, "ShiftLeft")); //$NON-NLS-1$
99

100         actionBars.setGlobalActionHandler(IDEActionFactory.ADD_TASK.getId(), getAction(textEditor, IDEActionFactory.ADD_TASK.getId()));
101         actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), getAction(textEditor, IDEActionFactory.BOOKMARK.getId()));
102     }
103
104     /*
105      * @see IEditorActionBarContributor#init(IActionBars, IWorkbenchPage)
106      */

107     public void init(IActionBars bars, IWorkbenchPage page) {
108         super.init(bars, page);
109         // register actions that have a dynamic editor.
110
bars.setGlobalActionHandler(JdtActionConstants.CONTENT_ASSIST, fContentAssist);
111     }
112     
113     /*
114      * @see org.eclipse.jdt.internal.ui.javaeditor.BasicJavaEditorActionContributor#dispose()
115      * @since 3.1
116      */

117     public void dispose() {
118         if (fRetargetContentAssist != null) {
119             fRetargetContentAssist.dispose();
120             fRetargetContentAssist= null;
121         }
122         super.dispose();
123     }
124 }
125
Popular Tags