KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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 import java.util.ResourceBundle JavaDoc;
14
15 import org.eclipse.jface.action.IAction;
16 import org.eclipse.jface.action.IMenuManager;
17
18 import org.eclipse.ui.IActionBars;
19 import org.eclipse.ui.IEditorPart;
20 import org.eclipse.ui.IWorkbenchActionConstants;
21 import org.eclipse.ui.actions.ActionFactory;
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.JdtActionConstants;
29
30 public class CompilationUnitEditorActionContributor extends BasicCompilationUnitEditorActionContributor {
31
32     private RetargetTextEditorAction fToggleInsertModeAction;
33
34     public CompilationUnitEditorActionContributor() {
35         super();
36
37         ResourceBundle JavaDoc b= JavaEditorMessages.getBundleForConstructedKeys();
38
39         fToggleInsertModeAction= new RetargetTextEditorAction(b, "CompilationUnitEditorActionContributor.ToggleInsertMode.", IAction.AS_CHECK_BOX); //$NON-NLS-1$
40
fToggleInsertModeAction.setActionDefinitionId(ITextEditorActionDefinitionIds.TOGGLE_INSERT_MODE);
41     }
42
43
44     /*
45      * @see org.eclipse.jdt.internal.ui.javaeditor.BasicEditorActionContributor#contributeToMenu(org.eclipse.jface.action.IMenuManager)
46      */

47     public void contributeToMenu(IMenuManager menu) {
48         super.contributeToMenu(menu);
49
50         IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
51         if (editMenu != null) {
52             editMenu.appendToGroup(IContextMenuConstants.GROUP_ADDITIONS, fToggleInsertModeAction);
53         }
54     }
55
56     /*
57      * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
58      */

59     public void setActiveEditor(IEditorPart part) {
60         super.setActiveEditor(part);
61
62         ITextEditor textEditor= null;
63         if (part instanceof ITextEditor)
64             textEditor= (ITextEditor) part;
65
66         // Source menu.
67
IActionBars bars= getActionBars();
68         bars.setGlobalActionHandler(JdtActionConstants.COMMENT, getAction(textEditor, "Comment")); //$NON-NLS-1$
69
bars.setGlobalActionHandler(JdtActionConstants.UNCOMMENT, getAction(textEditor, "Uncomment")); //$NON-NLS-1$
70
bars.setGlobalActionHandler(JdtActionConstants.TOGGLE_COMMENT, getAction(textEditor, "ToggleComment")); //$NON-NLS-1$
71
bars.setGlobalActionHandler(JdtActionConstants.FORMAT, getAction(textEditor, "Format")); //$NON-NLS-1$
72
bars.setGlobalActionHandler(JdtActionConstants.FORMAT_ELEMENT, getAction(textEditor, "QuickFormat")); //$NON-NLS-1$
73
bars.setGlobalActionHandler(JdtActionConstants.ADD_BLOCK_COMMENT, getAction(textEditor, "AddBlockComment")); //$NON-NLS-1$
74
bars.setGlobalActionHandler(JdtActionConstants.REMOVE_BLOCK_COMMENT, getAction(textEditor, "RemoveBlockComment")); //$NON-NLS-1$
75
bars.setGlobalActionHandler(JdtActionConstants.INDENT, getAction(textEditor, "Indent")); //$NON-NLS-1$
76

77         IAction action= getAction(textEditor, ActionFactory.REFRESH.getId());
78         bars.setGlobalActionHandler(ActionFactory.REFRESH.getId(), action);
79
80         fToggleInsertModeAction.setAction(getAction(textEditor, ITextEditorActionConstants.TOGGLE_INSERT_MODE));
81     }
82 }
83
Popular Tags