001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.part;
011:
012: import org.eclipse.jface.action.ICoolBarManager;
013: import org.eclipse.jface.action.IMenuManager;
014: import org.eclipse.jface.action.IStatusLineManager;
015: import org.eclipse.jface.action.IToolBarManager;
016: import org.eclipse.ui.IActionBars;
017: import org.eclipse.ui.IActionBars2;
018: import org.eclipse.ui.IEditorActionBarContributor;
019: import org.eclipse.ui.IEditorPart;
020: import org.eclipse.ui.IWorkbenchPage;
021:
022: /**
023: * Standard implementation of <code>IEditorActionBarContributor</code>.
024: * <p>
025: * If instantiated and used as-is, nothing is contribututed. Clients should
026: * subclass in order to contribute to some or all of the action bars.
027: * <p>
028: * Subclasses may reimplement the following methods:
029: * <ul>
030: * <li><code>contributeToMenu</code> - reimplement to contribute to menu</li>
031: * <li><code>contributeToToolBar</code> - reimplement to contribute to tool
032: * bar</li>
033: * <li><code>contributeToStatusLine</code> - reimplement to contribute to
034: * status line</li>
035: * <li><code>setActiveEditor</code> - reimplement to react to editor changes</li>
036: * </ul>
037: * </p>
038: */
039: public class EditorActionBarContributor implements
040: IEditorActionBarContributor {
041: /**
042: * The action bars; <code>null</code> until <code>init</code> is called.
043: */
044: private IActionBars bars;
045:
046: /**
047: * The workbench page; <code>null</code> until <code>init</code> is called.
048: */
049: private IWorkbenchPage page;
050:
051: /**
052: * Creates an empty editor action bar contributor. The action bars are
053: * furnished later via the <code>init</code> method.
054: */
055: public EditorActionBarContributor() {
056: }
057:
058: /**
059: * Contributes to the given menu.
060: * <p>
061: * The <code>EditorActionBarContributor</code> implementation of this method
062: * does nothing. Subclasses may reimplement to add to the menu portion of this
063: * contribution.
064: * </p>
065: *
066: * @param menuManager the manager that controls the menu
067: */
068: public void contributeToMenu(IMenuManager menuManager) {
069: }
070:
071: /**
072: * Contributes to the given status line.
073: * <p>
074: * The <code>EditorActionBarContributor</code> implementation of this method
075: * does nothing. Subclasses may reimplement to add to the status line portion of
076: * this contribution.
077: * </p>
078: *
079: * @param statusLineManager the manager of the status line
080: */
081: public void contributeToStatusLine(
082: IStatusLineManager statusLineManager) {
083: }
084:
085: /**
086: * Contributes to the given tool bar.
087: * <p>
088: * The <code>EditorActionBarContributor</code> implementation of this method
089: * does nothing. Subclasses may reimplement to add to the tool bar portion of
090: * this contribution.
091: * </p>
092: *
093: * @param toolBarManager the manager that controls the workbench tool bar
094: */
095: public void contributeToToolBar(IToolBarManager toolBarManager) {
096: }
097:
098: /**
099: * Contributes to the given cool bar.
100: * <p>
101: * The <code>EditorActionBarContributor</code> implementation of this method
102: * does nothing. Subclasses may reimplement to add to the cool bar portion of
103: * this contribution. There can only be contributions from a cool bar or a tool bar.
104: * </p>
105: *
106: * @param coolBarManager the manager that controls the workbench cool bar.
107: *
108: * @since 3.0
109: */
110: public void contributeToCoolBar(ICoolBarManager coolBarManager) {
111: }
112:
113: /**
114: * Returns this contributor's action bars.
115: *
116: * @return the action bars
117: */
118: public IActionBars getActionBars() {
119: return bars;
120: }
121:
122: /**
123: * Returns this contributor's workbench page.
124: *
125: * @return the workbench page
126: */
127: public IWorkbenchPage getPage() {
128: return page;
129: }
130:
131: /**
132: * The <code>EditorActionBarContributor</code> implementation of this
133: * <code>IEditorActionBarContributor</code> method does nothing,
134: * subclasses may override.
135: */
136: public void dispose() {
137: }
138:
139: /**
140: * The <code>EditorActionBarContributor</code> implementation of this
141: * <code>IEditorActionBarContributor</code> method remembers the page
142: * then forwards the call to <code>init(IActionBars)</code> for
143: * backward compatibility
144: */
145: public void init(IActionBars bars, IWorkbenchPage page) {
146: this .page = page;
147: init(bars);
148: }
149:
150: /**
151: * This method calls:
152: * <ul>
153: * <li><code>contributeToMenu</code> with <code>bars</code>' menu manager</li>
154: * <li><code>contributeToToolBar</code> with <code>bars</code>' tool bar
155: * manager</li>
156: * <li><code>contributeToCoolBar</code> with <code>bars</code>' cool bar
157: * manager if <code>IActionBars</code> is of extended type <code>IActionBars2</code> </li>
158: * <li><code>contributeToStatusLine</code> with <code>bars</code>' status line
159: * manager</li>
160: * </ul>
161: * The given action bars are also remembered and made accessible via
162: * <code>getActionBars</code>.
163: *
164: * @param bars the action bars
165: */
166: public void init(IActionBars bars) {
167: this .bars = bars;
168: contributeToMenu(bars.getMenuManager());
169: contributeToToolBar(bars.getToolBarManager());
170: if (bars instanceof IActionBars2) {
171: contributeToCoolBar(((IActionBars2) bars)
172: .getCoolBarManager());
173: }
174: contributeToStatusLine(bars.getStatusLineManager());
175:
176: }
177:
178: /**
179: * Sets the active editor for the contributor.
180: * <p>
181: * The <code>EditorActionBarContributor</code> implementation of this method does
182: * nothing. Subclasses may reimplement. This generally entails disconnecting
183: * from the old editor, connecting to the new editor, and updating the actions
184: * to reflect the new editor.
185: * </p>
186: *
187: * @param targetEditor the new target editor
188: */
189: public void setActiveEditor(IEditorPart targetEditor) {
190: }
191: }
|