KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > part > EditorActionBarContributor


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.ui.part;
12
13 import org.eclipse.jface.action.ICoolBarManager;
14 import org.eclipse.jface.action.IMenuManager;
15 import org.eclipse.jface.action.IStatusLineManager;
16 import org.eclipse.jface.action.IToolBarManager;
17 import org.eclipse.ui.IActionBars;
18 import org.eclipse.ui.IActionBars2;
19 import org.eclipse.ui.IEditorActionBarContributor;
20 import org.eclipse.ui.IEditorPart;
21 import org.eclipse.ui.IWorkbenchPage;
22
23 /**
24  * Standard implementation of <code>IEditorActionBarContributor</code>.
25  * <p>
26  * If instantiated and used as-is, nothing is contribututed. Clients should
27  * subclass in order to contribute to some or all of the action bars.
28  * <p>
29  * Subclasses may reimplement the following methods:
30  * <ul>
31  * <li><code>contributeToMenu</code> - reimplement to contribute to menu</li>
32  * <li><code>contributeToToolBar</code> - reimplement to contribute to tool
33  * bar</li>
34  * <li><code>contributeToStatusLine</code> - reimplement to contribute to
35  * status line</li>
36  * <li><code>setActiveEditor</code> - reimplement to react to editor changes</li>
37  * </ul>
38  * </p>
39  */

40 public class EditorActionBarContributor implements IEditorActionBarContributor {
41     /**
42      * The action bars; <code>null</code> until <code>init</code> is called.
43      */

44     private IActionBars bars;
45
46     /**
47      * The workbench page; <code>null</code> until <code>init</code> is called.
48      */

49     private IWorkbenchPage page;
50
51     /**
52      * Creates an empty editor action bar contributor. The action bars are
53      * furnished later via the <code>init</code> method.
54      */

55     public EditorActionBarContributor() {
56     }
57
58     /**
59      * Contributes to the given menu.
60      * <p>
61      * The <code>EditorActionBarContributor</code> implementation of this method
62      * does nothing. Subclasses may reimplement to add to the menu portion of this
63      * contribution.
64      * </p>
65      *
66      * @param menuManager the manager that controls the menu
67      */

68     public void contributeToMenu(IMenuManager menuManager) {
69     }
70
71     /**
72      * Contributes to the given status line.
73      * <p>
74      * The <code>EditorActionBarContributor</code> implementation of this method
75      * does nothing. Subclasses may reimplement to add to the status line portion of
76      * this contribution.
77      * </p>
78      *
79      * @param statusLineManager the manager of the status line
80      */

81     public void contributeToStatusLine(IStatusLineManager statusLineManager) {
82     }
83
84     /**
85      * Contributes to the given tool bar.
86      * <p>
87      * The <code>EditorActionBarContributor</code> implementation of this method
88      * does nothing. Subclasses may reimplement to add to the tool bar portion of
89      * this contribution.
90      * </p>
91      *
92      * @param toolBarManager the manager that controls the workbench tool bar
93      */

94     public void contributeToToolBar(IToolBarManager toolBarManager) {
95     }
96
97     /**
98      * Contributes to the given cool bar.
99      * <p>
100      * The <code>EditorActionBarContributor</code> implementation of this method
101      * does nothing. Subclasses may reimplement to add to the cool bar portion of
102      * this contribution. There can only be conributions from a cool bar or a tool bar.
103      * </p>
104      *
105      * @param coolBarManager the manager that controls the workbench cool bar.
106      *
107      * @since 3.0
108      */

109     public void contributeToCoolBar(ICoolBarManager coolBarManager) {
110     }
111
112     /**
113      * Returns this contributor's action bars.
114      *
115      * @return the action bars
116      */

117     public IActionBars getActionBars() {
118         return bars;
119     }
120
121     /**
122      * Returns this contributor's workbench page.
123      *
124      * @return the workbench page
125      */

126     public IWorkbenchPage getPage() {
127         return page;
128     }
129
130     /**
131      * The <code>EditorActionBarContributor</code> implementation of this
132      * <code>IEditorActionBarContributor</code> method does nothing,
133      * subclasses may override.
134      */

135     public void dispose() {
136     }
137
138     /**
139      * The <code>EditorActionBarContributor</code> implementation of this
140      * <code>IEditorActionBarContributor</code> method remembers the page
141      * then forwards the call to <code>init(IActionBars)</code> for
142      * backward compatibility
143      */

144     public void init(IActionBars bars, IWorkbenchPage page) {
145         this.page = page;
146         init(bars);
147     }
148
149     /**
150      * This method calls:
151      * <ul>
152      * <li><code>contributeToMenu</code> with <code>bars</code>' menu manager</li>
153      * <li><code>contributeToToolBar</code> with <code>bars</code>' tool bar
154      * manager</li>
155      * <li><code>contributeToCoolBar</code> with <code>bars</code>' cool bar
156      * manager if <code>IActionBars</code> is of extended type <code>IActionBars2</code> </li>
157      * <li><code>contributeToStatusLine</code> with <code>bars</code>' status line
158      * manager</li>
159      * </ul>
160      * The given action bars are also remembered and made accessible via
161      * <code>getActionBars</code>.
162      *
163      * @param bars the action bars
164      */

165     public void init(IActionBars bars) {
166         this.bars = bars;
167         contributeToMenu(bars.getMenuManager());
168         contributeToToolBar(bars.getToolBarManager());
169         if (bars instanceof IActionBars2) {
170             contributeToCoolBar(((IActionBars2) bars).getCoolBarManager());
171         }
172         contributeToStatusLine(bars.getStatusLineManager());
173
174     }
175
176     /**
177      * Sets the active editor for the contributor.
178      * <p>
179      * The <code>EditorActionBarContributor</code> implementation of this method does
180      * nothing. Subclasses may reimplement. This generally entails disconnecting
181      * from the old editor, connecting to the new editor, and updating the actions
182      * to reflect the new editor.
183      * </p>
184      *
185      * @param targetEditor the new target editor
186      */

187     public void setActiveEditor(IEditorPart targetEditor) {
188     }
189 }
190
Popular Tags