KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > action > SubContributionItem


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.jface.action;
12
13 import org.eclipse.swt.widgets.Composite;
14 import org.eclipse.swt.widgets.CoolBar;
15 import org.eclipse.swt.widgets.Menu;
16 import org.eclipse.swt.widgets.ToolBar;
17
18 /**
19  * A <code>SubContributionItem</code> is a wrapper for an <code>IContributionItem</code>.
20  * It is used within a <code>SubContributionManager</code> to control the visibility
21  * of items.
22  * <p>
23  * This class is not intended to be subclassed.
24  * </p>
25  */

26 public class SubContributionItem implements IContributionItem {
27     /**
28      * The visibility of the item.
29      */

30     private boolean visible;
31
32     /**
33      * The inner item for this contribution.
34      */

35     private IContributionItem innerItem;
36
37     /**
38      * Creates a new <code>SubContributionItem</code>.
39      * @param item the contribution item to be wrapped
40      */

41     public SubContributionItem(IContributionItem item) {
42         innerItem = item;
43     }
44
45     /**
46      * The default implementation of this <code>IContributionItem</code>
47      * delegates to the inner item. Subclasses may override.
48      */

49     public void dispose() {
50         innerItem.dispose();
51     }
52
53     /* (non-Javadoc)
54      * Method declared on IContributionItem.
55      */

56     public void fill(Composite parent) {
57         if (visible) {
58             innerItem.fill(parent);
59         }
60     }
61
62     /* (non-Javadoc)
63      * Method declared on IContributionItem.
64      */

65     public void fill(Menu parent, int index) {
66         if (visible) {
67             innerItem.fill(parent, index);
68         }
69     }
70
71     /* (non-Javadoc)
72      * Method declared on IContributionItem.
73      */

74     public void fill(ToolBar parent, int index) {
75         if (visible) {
76             innerItem.fill(parent, index);
77         }
78     }
79
80     /* (non-Javadoc)
81      * Method declared on IContributionItem.
82      */

83     public String JavaDoc getId() {
84         return innerItem.getId();
85     }
86
87     /**
88      * Returns the inner contribution item.
89      *
90      * @return the inner contribution item
91      */

92     public IContributionItem getInnerItem() {
93         return innerItem;
94     }
95
96     /* (non-Javadoc)
97      * Method declared on IContributionItem.
98      */

99     public boolean isEnabled() {
100         return innerItem.isEnabled();
101     }
102
103     /* (non-Javadoc)
104      * Method declared on IContributionItem.
105      */

106     public boolean isDirty() {
107         return innerItem.isDirty();
108     }
109
110     /* (non-Javadoc)
111      * Method declared on IContributionItem.
112      */

113     public boolean isDynamic() {
114         return innerItem.isDynamic();
115     }
116
117     /* (non-Javadoc)
118      * Method declared on IContributionItem.
119      */

120     public boolean isGroupMarker() {
121         return innerItem.isGroupMarker();
122     }
123
124     /* (non-Javadoc)
125      * Method declared on IContributionItem.
126      */

127     public boolean isSeparator() {
128         return innerItem.isSeparator();
129     }
130
131     /* (non-Javadoc)
132      * Method declared on IContributionItem.
133      */

134     public boolean isVisible() {
135         return visible && innerItem.isVisible();
136     }
137
138     /* (non-Javadoc)
139      * Method declared on IContributionItem.
140      */

141     public void setParent(IContributionManager parent) {
142         // do nothing, the parent of our inner item
143
// is its SubContributionManager
144
}
145
146     /* (non-Javadoc)
147      * Method declared on IContributionItem.
148      */

149     public void setVisible(boolean visible) {
150         this.visible = visible;
151     }
152
153     /* (non-Javadoc)
154      * Method declared on IContributionItem.
155      */

156     public void update() {
157         innerItem.update();
158     }
159
160     /* (non-Javadoc)
161      * Method declared on IContributionItem.
162      */

163     public void update(String JavaDoc id) {
164         innerItem.update(id);
165     }
166
167     /* (non-Javadoc)
168      * @see org.eclipse.jface.action.IContributionItem#fill(org.eclipse.swt.widgets.CoolBar, int)
169      */

170     public void fill(CoolBar parent, int index) {
171         if (visible) {
172             innerItem.fill(parent, index);
173         }
174     }
175
176     /* (non-Javadoc)
177      * @see org.eclipse.jface.action.IContributionItem#saveWidgetState()
178      */

179     public void saveWidgetState() {
180     }
181
182 }
183
Popular Tags