KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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  * An abstract base implementation for contribution items.
20  */

21 public abstract class ContributionItem implements IContributionItem {
22
23     /**
24      * The identifier for this contribution item, of <code>null</code> if none.
25      */

26     private String JavaDoc id = null;
27
28     /**
29      * Indicates this item is visible in its manager; <code>true</code>
30      * by default.
31      */

32     private boolean visible = true;
33
34     /**
35      * The parent contribution manager for this item
36      */

37     private IContributionManager parent;
38
39     /**
40      * Creates a contribution item with a <code>null</code> id.
41      * Calls <code>this(String)</code> with <code>null</code>.
42      */

43     protected ContributionItem() {
44         this(null);
45     }
46
47     /**
48      * Creates a contribution item with the given (optional) id.
49      * The given id is used to find items in a contribution manager,
50      * and for positioning items relative to other items.
51      *
52      * @param id the contribution item identifier, or <code>null</code>
53      */

54     protected ContributionItem(String JavaDoc id) {
55         this.id = id;
56     }
57
58     /**
59      * The default implementation of this <code>IContributionItem</code>
60      * method does nothing. Subclasses may override.
61      */

62     public void dispose() {
63     }
64
65     /**
66      * The default implementation of this <code>IContributionItem</code>
67      * method does nothing. Subclasses may override.
68      */

69     public void fill(Composite parent) {
70     }
71
72     /**
73      * The default implementation of this <code>IContributionItem</code>
74      * method does nothing. Subclasses may override.
75      */

76     public void fill(Menu menu, int index) {
77     }
78
79     /**
80      * The default implementation of this <code>IContributionItem</code>
81      * method does nothing. Subclasses may override.
82      */

83     public void fill(ToolBar parent, int index) {
84     }
85
86     /**
87      * The default implementation of this <code>IContributionItem</code>
88      * method does nothing. Subclasses may override.
89      *
90      * @since 3.0
91      */

92     public void fill(CoolBar parent, int index) {
93     }
94
95     /**
96      * The default implementation of this <code>IContributionItem</code>
97      * method does nothing. Subclasses may override.
98      *
99      * @since 3.0
100      */

101     public void saveWidgetState() {
102     }
103
104     /* (non-Javadoc)
105      * Method declared on IContributionItem.
106      */

107     public String JavaDoc getId() {
108         return id;
109     }
110
111     /**
112      * Returns the parent contribution manager, or <code>null</code> if this
113      * contribution item is not currently added to a contribution manager.
114      *
115      * @return the parent contribution manager, or <code>null</code>
116      * @since 2.0
117      */

118     public IContributionManager getParent() {
119         return parent;
120     }
121
122     /**
123      * The default implementation of this <code>IContributionItem</code>
124      * method returns <code>false</code>. Subclasses may override.
125      */

126     public boolean isDirty() {
127         // @issue should this be false instead of calling isDynamic()?
128
return isDynamic();
129     }
130
131     /**
132      * The default implementation of this <code>IContributionItem</code>
133      * method returns <code>true</code>. Subclasses may override.
134      */

135     public boolean isEnabled() {
136         return true;
137     }
138
139     /**
140      * The default implementation of this <code>IContributionItem</code>
141      * method returns <code>false</code>. Subclasses may override.
142      */

143     public boolean isDynamic() {
144         return false;
145     }
146
147     /**
148      * The default implementation of this <code>IContributionItem</code>
149      * method returns <code>false</code>. Subclasses may override.
150      */

151     public boolean isGroupMarker() {
152         return false;
153     }
154
155     /**
156      * The default implementation of this <code>IContributionItem</code>
157      * method returns <code>false</code>. Subclasses may override.
158      */

159     public boolean isSeparator() {
160         return false;
161     }
162
163     /**
164      * The default implementation of this <code>IContributionItem</code>
165      * method returns the value recorded in an internal state variable,
166      * which is <code>true</code> by default. <code>setVisible</code>
167      * should be used to change this setting.
168      */

169     public boolean isVisible() {
170         return visible;
171     }
172
173     /**
174      * The default implementation of this <code>IContributionItem</code>
175      * method stores the value in an internal state variable,
176      * which is <code>true</code> by default.
177      */

178     public void setVisible(boolean visible) {
179         this.visible = visible;
180     }
181
182     /**
183      * Returns a string representation of this contribution item
184      * suitable only for debugging.
185      */

186     public String JavaDoc toString() {
187         return getClass().getName() + "(id=" + getId() + ")";//$NON-NLS-2$//$NON-NLS-1$
188
}
189
190     /**
191      * The default implementation of this <code>IContributionItem</code>
192      * method does nothing. Subclasses may override.
193      */

194     public void update() {
195     }
196
197     /* (non-Javadoc)
198      * Method declared on IContributionItem.
199      */

200     public void setParent(IContributionManager parent) {
201         this.parent = parent;
202     }
203
204     /**
205      * The <code>ContributionItem</code> implementation of this
206      * method declared on <code>IContributionItem</code> does nothing.
207      * Subclasses should override to update their state.
208      */

209     public void update(String JavaDoc id) {
210     }
211 }
212
Popular Tags