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.internal;
011:
012: import org.eclipse.jface.action.IContributionItem;
013: import org.eclipse.jface.action.IContributionManager;
014: import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
015: import org.eclipse.swt.widgets.Composite;
016: import org.eclipse.swt.widgets.CoolBar;
017: import org.eclipse.swt.widgets.Menu;
018: import org.eclipse.swt.widgets.ToolBar;
019:
020: /**
021: * A contribution item that is intended to hold the place of a tool bar
022: * contribution item that has been disposed. This is to ensure that tool bar
023: * contribution items are disposed (freeing their resources), but that layout
024: * information about the item is not lost.
025: *
026: * @since 3.0
027: */
028: final class PlaceholderContributionItem implements IContributionItem {
029:
030: /**
031: * The identifier for the replaced contribution item.
032: */
033: private final String id;
034:
035: /**
036: * The height of the SWT widget corresponding to the replaced contribution
037: * item.
038: */
039: private final int storedHeight;
040:
041: /**
042: * The minimum number of items to display on the replaced contribution
043: * item.
044: */
045: private final int storedMinimumItems;
046:
047: /**
048: * Whether the replaced contribution item would display chevrons.
049: */
050: private final boolean storedUseChevron;
051:
052: /**
053: * The width of the SWT widget corresponding to the replaced contribution
054: * item.
055: */
056: private final int storedWidth;
057:
058: /**
059: * Constructs a new instance of <code>PlaceholderContributionItem</code>
060: * from the item it is intended to replace.
061: *
062: * @param item
063: * The item to be replaced; must not be <code>null</code>.
064: */
065: PlaceholderContributionItem(final IToolBarContributionItem item) {
066: item.saveWidgetState();
067: id = item.getId();
068: storedHeight = item.getCurrentHeight();
069: storedWidth = item.getCurrentWidth();
070: storedMinimumItems = item.getMinimumItemsToShow();
071: storedUseChevron = item.getUseChevron();
072: }
073:
074: /*
075: * (non-Javadoc)
076: *
077: * @see org.eclipse.jface.action.IContributionItem#dispose()
078: */
079: public void dispose() {
080: // Do nothing
081: }
082:
083: /*
084: * (non-Javadoc)
085: *
086: * @see org.eclipse.jface.action.IContributionItem#fill(org.eclipse.swt.widgets.Composite)
087: */
088: public void fill(Composite parent) {
089: throw new UnsupportedOperationException();
090: }
091:
092: /*
093: * (non-Javadoc)
094: *
095: * @see org.eclipse.jface.action.IContributionItem#fill(org.eclipse.swt.widgets.CoolBar,
096: * int)
097: */
098: public void fill(CoolBar parent, int index) {
099: throw new UnsupportedOperationException();
100:
101: }
102:
103: /*
104: * (non-Javadoc)
105: *
106: * @see org.eclipse.jface.action.IContributionItem#fill(org.eclipse.swt.widgets.Menu,
107: * int)
108: */
109: public void fill(Menu parent, int index) {
110: throw new UnsupportedOperationException();
111:
112: }
113:
114: /*
115: * (non-Javadoc)
116: *
117: * @see org.eclipse.jface.action.IContributionItem#fill(org.eclipse.swt.widgets.ToolBar,
118: * int)
119: */
120: public void fill(ToolBar parent, int index) {
121: throw new UnsupportedOperationException();
122:
123: }
124:
125: /**
126: * The height of the replaced contribution item.
127: *
128: * @return The height.
129: */
130: int getHeight() {
131: return storedHeight;
132: }
133:
134: /*
135: * (non-Javadoc)
136: *
137: * @see org.eclipse.jface.action.IContributionItem#getId()
138: */
139: public String getId() {
140: return id;
141: }
142:
143: /**
144: * The width of the replaced contribution item.
145: *
146: * @return The width.
147: */
148: int getWidth() {
149: return storedWidth;
150: }
151:
152: /**
153: * Returns the minimum number of tool items to show in the cool item.
154: *
155: * @return the minimum number of tool items to show, or <code>SHOW_ALL_ITEMS</code>
156: * if a value was not set
157: * @see #setMinimumItemsToShow(int)
158: * @since 3.2
159: */
160: int getMinimumItemsToShow() {
161: return storedMinimumItems;
162: }
163:
164: /**
165: * Returns whether chevron support is enabled.
166: *
167: * @return <code>true</code> if chevron support is enabled, <code>false</code>
168: * otherwise
169: * @since 3.2
170: */
171: boolean getUseChevron() {
172: return storedUseChevron;
173: }
174:
175: /*
176: * (non-Javadoc)
177: *
178: * @see org.eclipse.jface.action.IContributionItem#isDirty()
179: */
180: public boolean isDirty() {
181: return false;
182: }
183:
184: /*
185: * (non-Javadoc)
186: *
187: * @see org.eclipse.jface.action.IContributionItem#isDynamic()
188: */
189: public boolean isDynamic() {
190: return false;
191: }
192:
193: /*
194: * (non-Javadoc)
195: *
196: * @see org.eclipse.jface.action.IContributionItem#isEnabled()
197: */
198: public boolean isEnabled() {
199: // XXX Auto-generated method stub
200: return false;
201: }
202:
203: /*
204: * (non-Javadoc)
205: *
206: * @see org.eclipse.jface.action.IContributionItem#isGroupMarker()
207: */
208: public boolean isGroupMarker() {
209: return false;
210: }
211:
212: /*
213: * (non-Javadoc)
214: *
215: * @see org.eclipse.jface.action.IContributionItem#isSeparator()
216: */
217: public boolean isSeparator() {
218: return false;
219: }
220:
221: /*
222: * (non-Javadoc)
223: *
224: * @see org.eclipse.jface.action.IContributionItem#isVisible()
225: */
226: public boolean isVisible() {
227: return false;
228: }
229:
230: /*
231: * (non-Javadoc)
232: *
233: * @see org.eclipse.jface.action.IContributionItem#saveWidgetState()
234: */
235: public void saveWidgetState() {
236: // Do nothing.
237:
238: }
239:
240: /*
241: * (non-Javadoc)
242: *
243: * @see org.eclipse.jface.action.IContributionItem#setParent(org.eclipse.jface.action.IContributionManager)
244: */
245: public void setParent(IContributionManager parent) {
246: // Do nothing
247:
248: }
249:
250: /*
251: * (non-Javadoc)
252: *
253: * @see org.eclipse.jface.action.IContributionItem#setVisible(boolean)
254: */
255: public void setVisible(boolean visible) {
256: // Do nothing.
257: }
258:
259: /**
260: * Displays a string representation of this contribution item, which is
261: * really just a function of its identifier.
262: */
263: public String toString() {
264: return "PlaceholderContributionItem(" + id + ")"; //$NON-NLS-1$//$NON-NLS-2$
265: }
266:
267: /*
268: * (non-Javadoc)
269: *
270: * @see org.eclipse.jface.action.IContributionItem#update()
271: */
272: public void update() {
273: update(null);
274:
275: }
276:
277: /*
278: * (non-Javadoc)
279: *
280: * @see org.eclipse.jface.action.IContributionItem#update(java.lang.String)
281: */
282: public void update(String identifier) {
283: // Do nothing
284: }
285: }
|