KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > web > ui > common > component > UIModeList


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.web.ui.common.component;
18
19 import javax.faces.component.UICommand;
20 import javax.faces.component.UIComponent;
21 import javax.faces.context.FacesContext;
22 import javax.faces.el.ValueBinding;
23 import javax.faces.event.AbortProcessingException;
24 import javax.faces.event.ActionEvent;
25 import javax.faces.event.FacesEvent;
26
27 /**
28  * @author Kevin Roast
29  */

30 public class UIModeList extends UICommand
31 {
32    // ------------------------------------------------------------------------------
33
// Construction
34

35    /**
36     * Default constructor
37     */

38    public UIModeList()
39    {
40       setRendererType("org.alfresco.faces.ModeListRenderer");
41    }
42    
43    
44    // ------------------------------------------------------------------------------
45
// Component Impl
46

47    /**
48     * @see javax.faces.component.UIComponent#getFamily()
49     */

50    public String JavaDoc getFamily()
51    {
52       return "org.alfresco.faces.Controls";
53    }
54    
55    /**
56     * @see javax.faces.component.StateHolder#restoreState(javax.faces.context.FacesContext, java.lang.Object)
57     */

58    public void restoreState(FacesContext context, Object JavaDoc state)
59    {
60       Object JavaDoc values[] = (Object JavaDoc[])state;
61       // standard component attributes are restored by the super class
62
super.restoreState(context, values[0]);
63       this.iconColumnWidth = (Integer JavaDoc)values[1];
64       this.horizontal = (Boolean JavaDoc)values[2];
65       this.disabled = (Boolean JavaDoc)values[3];
66       this.label = (String JavaDoc)values[4];
67       this.menu = (Boolean JavaDoc)values[5];
68       this.menuImage = (String JavaDoc)values[6];
69    }
70    
71    /**
72     * @see javax.faces.component.StateHolder#saveState(javax.faces.context.FacesContext)
73     */

74    public Object JavaDoc saveState(FacesContext context)
75    {
76       Object JavaDoc values[] = new Object JavaDoc[7];
77       // standard component attributes are saved by the super class
78
values[0] = super.saveState(context);
79       values[1] = this.iconColumnWidth;
80       values[2] = this.horizontal;
81       values[3] = this.disabled;
82       values[4] = this.label;
83       values[5] = this.menu;
84       values[6] = this.menuImage;
85       return (values);
86    }
87    
88    /**
89     * @see javax.faces.component.UICommand#broadcast(javax.faces.event.FacesEvent)
90     */

91    public void broadcast(FacesEvent event) throws AbortProcessingException
92    {
93       if (event instanceof ModeListItemSelectedEvent)
94       {
95          // found an event for us, update the value for this component
96
setValue( ((ModeListItemSelectedEvent)event).SelectedValue );
97       }
98       
99       // default ActionEvent processing for a UICommand
100
super.broadcast(event);
101    }
102    
103    
104    // ------------------------------------------------------------------------------
105
// Strongly typed property accessors
106

107    /**
108     * Get the horizontal rendering flag
109     *
110     * @return true for horizontal rendering, false otherwise
111     */

112    public boolean isHorizontal()
113    {
114       ValueBinding vb = getValueBinding("horizontal");
115       if (vb != null)
116       {
117          this.horizontal = (Boolean JavaDoc)vb.getValue(getFacesContext());
118       }
119       
120       if (this.horizontal != null)
121       {
122          return this.horizontal.booleanValue();
123       }
124       else
125       {
126          // return the default
127
return false;
128       }
129    }
130
131    /**
132     * Set true for horizontal rendering, false otherwise
133     *
134     * @param horizontal the horizontal
135     */

136    public void setHorizontal(boolean horizontal)
137    {
138       this.horizontal = horizontal;
139    }
140    
141    /**
142     * Get the icon column width
143     *
144     * @return the icon column width
145     */

146    public int getIconColumnWidth()
147    {
148       ValueBinding vb = getValueBinding("iconColumnWidth");
149       if (vb != null)
150       {
151          this.iconColumnWidth = (Integer JavaDoc)vb.getValue(getFacesContext());
152       }
153       
154       if (this.iconColumnWidth != null)
155       {
156          return this.iconColumnWidth.intValue();
157       }
158       else
159       {
160          // return the default
161
return 20;
162       }
163    }
164
165    /**
166     * Set the icon column width
167     *
168     * @param iconColumnWidth the icon column width
169     */

170    public void setIconColumnWidth(int iconColumnWidth)
171    {
172       this.iconColumnWidth = Integer.valueOf(iconColumnWidth);
173    }
174
175    /**
176     * Returns the disabled flag
177     *
178     * @return true if the mode list is disabled
179     */

180    public boolean isDisabled()
181    {
182       ValueBinding vb = getValueBinding("disabled");
183       if (vb != null)
184       {
185          this.disabled = (Boolean JavaDoc)vb.getValue(getFacesContext());
186       }
187       
188       if (this.disabled != null)
189       {
190          return this.disabled.booleanValue();
191       }
192       else
193       {
194          // return the default
195
return false;
196       }
197    }
198
199    /**
200     * Sets whether the mode list is disabled
201     *
202     * @param disabled the disabled flag
203     */

204    public void setDisabled(boolean disabled)
205    {
206       this.disabled = disabled;
207    }
208    
209    /**
210     * Returns the menu rendering flag
211     *
212     * @return true if the menu rendering mode is to be used
213     */

214    public boolean isMenu()
215    {
216       ValueBinding vb = getValueBinding("menu");
217       if (vb != null)
218       {
219          this.menu = (Boolean JavaDoc)vb.getValue(getFacesContext());
220       }
221       
222       if (this.menu != null)
223       {
224          return this.menu.booleanValue();
225       }
226       else
227       {
228          // return the default
229
return false;
230       }
231    }
232
233    /**
234     * Sets whether the mode list is a menu
235     *
236     * @param menu the menu flag
237     */

238    public void setMenu(boolean menu)
239    {
240       this.menu = menu;
241    }
242    
243    /**
244     * @return Returns the label.
245     */

246    public String JavaDoc getLabel()
247    {
248       ValueBinding vb = getValueBinding("label");
249       if (vb != null)
250       {
251          this.label = (String JavaDoc)vb.getValue(getFacesContext());
252       }
253       
254       return this.label;
255    }
256
257    /**
258     * @param label The label to set.
259     */

260    public void setLabel(String JavaDoc label)
261    {
262       this.label = label;
263    }
264    
265    /**
266     * @return Returns the menu image.
267     */

268    public String JavaDoc getMenuImage()
269    {
270       ValueBinding vb = getValueBinding("menuImage");
271       if (vb != null)
272       {
273          this.menuImage = (String JavaDoc)vb.getValue(getFacesContext());
274       }
275       
276       return this.menuImage;
277    }
278
279    /**
280     * @param menuImage The menu image to set.
281     */

282    public void setMenuImage(String JavaDoc menuImage)
283    {
284       this.menuImage = menuImage;
285    }
286    
287    
288    // ------------------------------------------------------------------------------
289
// Private data
290

291    /** the icon column width */
292    private Integer JavaDoc iconColumnWidth;
293
294    /** true for horizontal rendering, false otherwise */
295    private Boolean JavaDoc horizontal = null;
296    
297    /** disabled flag */
298    private Boolean JavaDoc disabled = null;
299    
300    /** menu rendering flag */
301    private Boolean JavaDoc menu = null;
302    
303    /** menu image to use */
304    private String JavaDoc menuImage = null;
305    
306    /** the label */
307    private String JavaDoc label;
308    
309    
310    // ------------------------------------------------------------------------------
311
// Inner classes
312

313    /**
314     * Class representing a change in selection for a ModeList component.
315     */

316    public static class ModeListItemSelectedEvent extends ActionEvent
317    {
318       private static final long serialVersionUID = 3618135654274774322L;
319
320       public ModeListItemSelectedEvent(UIComponent component, Object JavaDoc selectedValue)
321       {
322          super(component);
323          SelectedValue = selectedValue;
324       }
325       
326       public Object JavaDoc SelectedValue = null;
327    }
328 }
329
Popular Tags