KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > PlaceholderContributionItem


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
12 package org.eclipse.ui.internal;
13
14 import org.eclipse.jface.action.IContributionItem;
15 import org.eclipse.jface.action.IContributionManager;
16 import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.CoolBar;
19 import org.eclipse.swt.widgets.Menu;
20 import org.eclipse.swt.widgets.ToolBar;
21
22 /**
23  * A contribution item that is intended to hold the place of a tool bar
24  * contribution item that has been disposed. This is to ensure that tool bar
25  * contribution items are disposed (freeing their resources), but that layout
26  * information about the item is not lost.
27  *
28  * @since 3.0
29  */

30 final class PlaceholderContributionItem implements IContributionItem {
31
32     /**
33      * The identifier for the replaced contribution item.
34      */

35     private final String JavaDoc id;
36
37     /**
38      * The height of the SWT widget corresponding to the replaced contribution
39      * item.
40      */

41     private final int storedHeight;
42
43     /**
44      * The minimum number of items to display on the replaced contribution
45      * item.
46      */

47     private final int storedMinimumItems;
48
49     /**
50      * Whether the replaced contribution item would display chevrons.
51      */

52     private final boolean storedUseChevron;
53
54     /**
55      * The width of the SWT widget corresponding to the replaced contribution
56      * item.
57      */

58     private final int storedWidth;
59
60     /**
61      * Constructs a new instance of <code>PlaceholderContributionItem</code>
62      * from the item it is intended to replace.
63      *
64      * @param item
65      * The item to be replaced; must not be <code>null</code>.
66      */

67     PlaceholderContributionItem(final IToolBarContributionItem item) {
68         item.saveWidgetState();
69         id = item.getId();
70         storedHeight = item.getCurrentHeight();
71         storedWidth = item.getCurrentWidth();
72         storedMinimumItems = item.getMinimumItemsToShow();
73         storedUseChevron = item.getUseChevron();
74     }
75
76     /*
77      * (non-Javadoc)
78      *
79      * @see org.eclipse.jface.action.IContributionItem#dispose()
80      */

81     public void dispose() {
82         // Do nothing
83
}
84
85     /*
86      * (non-Javadoc)
87      *
88      * @see org.eclipse.jface.action.IContributionItem#fill(org.eclipse.swt.widgets.Composite)
89      */

90     public void fill(Composite parent) {
91         throw new UnsupportedOperationException JavaDoc();
92     }
93
94     /*
95      * (non-Javadoc)
96      *
97      * @see org.eclipse.jface.action.IContributionItem#fill(org.eclipse.swt.widgets.CoolBar,
98      * int)
99      */

100     public void fill(CoolBar parent, int index) {
101         throw new UnsupportedOperationException JavaDoc();
102
103     }
104
105     /*
106      * (non-Javadoc)
107      *
108      * @see org.eclipse.jface.action.IContributionItem#fill(org.eclipse.swt.widgets.Menu,
109      * int)
110      */

111     public void fill(Menu parent, int index) {
112         throw new UnsupportedOperationException JavaDoc();
113
114     }
115
116     /*
117      * (non-Javadoc)
118      *
119      * @see org.eclipse.jface.action.IContributionItem#fill(org.eclipse.swt.widgets.ToolBar,
120      * int)
121      */

122     public void fill(ToolBar parent, int index) {
123         throw new UnsupportedOperationException JavaDoc();
124
125     }
126
127     /**
128      * The height of the replaced contribution item.
129      *
130      * @return The height.
131      */

132     int getHeight() {
133         return storedHeight;
134     }
135
136     /*
137      * (non-Javadoc)
138      *
139      * @see org.eclipse.jface.action.IContributionItem#getId()
140      */

141     public String JavaDoc getId() {
142         return id;
143     }
144
145     /**
146      * The width of the replaced contribution item.
147      *
148      * @return The width.
149      */

150     int getWidth() {
151         return storedWidth;
152     }
153     
154     /**
155      * Returns the minimum number of tool items to show in the cool item.
156      *
157      * @return the minimum number of tool items to show, or <code>SHOW_ALL_ITEMS</code>
158      * if a value was not set
159      * @see #setMinimumItemsToShow(int)
160      * @since 3.2
161      */

162     int getMinimumItemsToShow() {
163         return storedMinimumItems;
164     }
165     
166     /**
167      * Returns whether chevron support is enabled.
168      *
169      * @return <code>true</code> if chevron support is enabled, <code>false</code>
170      * otherwise
171      * @since 3.2
172      */

173     boolean getUseChevron() {
174         return storedUseChevron;
175     }
176
177     /*
178      * (non-Javadoc)
179      *
180      * @see org.eclipse.jface.action.IContributionItem#isDirty()
181      */

182     public boolean isDirty() {
183         return false;
184     }
185
186     /*
187      * (non-Javadoc)
188      *
189      * @see org.eclipse.jface.action.IContributionItem#isDynamic()
190      */

191     public boolean isDynamic() {
192         return false;
193     }
194
195     /*
196      * (non-Javadoc)
197      *
198      * @see org.eclipse.jface.action.IContributionItem#isEnabled()
199      */

200     public boolean isEnabled() {
201         // XXX Auto-generated method stub
202
return false;
203     }
204
205     /*
206      * (non-Javadoc)
207      *
208      * @see org.eclipse.jface.action.IContributionItem#isGroupMarker()
209      */

210     public boolean isGroupMarker() {
211         return false;
212     }
213
214     /*
215      * (non-Javadoc)
216      *
217      * @see org.eclipse.jface.action.IContributionItem#isSeparator()
218      */

219     public boolean isSeparator() {
220         return false;
221     }
222
223     /*
224      * (non-Javadoc)
225      *
226      * @see org.eclipse.jface.action.IContributionItem#isVisible()
227      */

228     public boolean isVisible() {
229         return false;
230     }
231
232     /*
233      * (non-Javadoc)
234      *
235      * @see org.eclipse.jface.action.IContributionItem#saveWidgetState()
236      */

237     public void saveWidgetState() {
238         // Do nothing.
239

240     }
241
242     /*
243      * (non-Javadoc)
244      *
245      * @see org.eclipse.jface.action.IContributionItem#setParent(org.eclipse.jface.action.IContributionManager)
246      */

247     public void setParent(IContributionManager parent) {
248         // Do nothing
249

250     }
251
252     /*
253      * (non-Javadoc)
254      *
255      * @see org.eclipse.jface.action.IContributionItem#setVisible(boolean)
256      */

257     public void setVisible(boolean visible) {
258         // Do nothing.
259
}
260
261     /**
262      * Displays a string representation of this contribution item, which is
263      * really just a function of its identifier.
264      */

265     public String JavaDoc toString() {
266         return "PlaceholderContributionItem(" + id + ")"; //$NON-NLS-1$//$NON-NLS-2$
267
}
268
269     /*
270      * (non-Javadoc)
271      *
272      * @see org.eclipse.jface.action.IContributionItem#update()
273      */

274     public void update() {
275         update(null);
276
277     }
278
279     /*
280      * (non-Javadoc)
281      *
282      * @see org.eclipse.jface.action.IContributionItem#update(java.lang.String)
283      */

284     public void update(String JavaDoc identifier) {
285         // Do nothing
286
}
287 }
288
Popular Tags