01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.examples.javaeditor;
11:
12: import org.eclipse.jface.action.*;
13: import org.eclipse.ui.*;
14: import org.eclipse.ui.editors.text.TextEditorActionContributor;
15: import org.eclipse.ui.texteditor.*;
16:
17: /**
18: * Contributes interesting Java actions to the desktop's Edit menu and the toolbar.
19: */
20: public class JavaActionContributor extends TextEditorActionContributor {
21:
22: protected RetargetTextEditorAction fContentAssistProposal;
23: protected RetargetTextEditorAction fContentAssistTip;
24: protected TextEditorAction fTogglePresentation;
25:
26: /**
27: * Default constructor.
28: */
29: public JavaActionContributor() {
30: super ();
31: fContentAssistProposal = new RetargetTextEditorAction(
32: JavaEditorMessages.getResourceBundle(),
33: "ContentAssistProposal."); //$NON-NLS-1$
34: fContentAssistProposal
35: .setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
36: fContentAssistTip = new RetargetTextEditorAction(
37: JavaEditorMessages.getResourceBundle(),
38: "ContentAssistTip."); //$NON-NLS-1$
39: fContentAssistTip
40: .setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
41: fTogglePresentation = new PresentationAction();
42: }
43:
44: /*
45: * @see IEditorActionBarContributor#init(IActionBars)
46: */
47: public void init(IActionBars bars) {
48: super .init(bars);
49:
50: IMenuManager menuManager = bars.getMenuManager();
51: IMenuManager editMenu = menuManager
52: .findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
53: if (editMenu != null) {
54: editMenu.add(new Separator());
55: editMenu.add(fContentAssistProposal);
56: editMenu.add(fContentAssistTip);
57: }
58:
59: IToolBarManager toolBarManager = bars.getToolBarManager();
60: if (toolBarManager != null) {
61: toolBarManager.add(new Separator());
62: toolBarManager.add(fTogglePresentation);
63: }
64: }
65:
66: private void doSetActiveEditor(IEditorPart part) {
67: super .setActiveEditor(part);
68:
69: ITextEditor editor = null;
70: if (part instanceof ITextEditor)
71: editor = (ITextEditor) part;
72:
73: fContentAssistProposal.setAction(getAction(editor,
74: "ContentAssistProposal")); //$NON-NLS-1$
75: fContentAssistTip.setAction(getAction(editor,
76: "ContentAssistTip")); //$NON-NLS-1$
77:
78: fTogglePresentation.setEditor(editor);
79: fTogglePresentation.update();
80: }
81:
82: /*
83: * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
84: */
85: public void setActiveEditor(IEditorPart part) {
86: super .setActiveEditor(part);
87: doSetActiveEditor(part);
88: }
89:
90: /*
91: * @see IEditorActionBarContributor#dispose()
92: */
93: public void dispose() {
94: doSetActiveEditor(null);
95: super.dispose();
96: }
97: }
|