KickJava   Java API By Example, From Geeks To Geeks.

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


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.context.FacesContext;
20 import javax.faces.el.ValueBinding;
21
22 /**
23  * @author kevinr
24  */

25 public class UIListItem extends SelfRenderingComponent
26 {
27    // ------------------------------------------------------------------------------
28
// Component Impl
29

30    /**
31     * @see javax.faces.component.UIComponent#getFamily()
32     */

33    public String JavaDoc getFamily()
34    {
35       return "org.alfresco.faces.Controls";
36    }
37
38    /**
39     * @see javax.faces.component.StateHolder#saveState(javax.faces.context.FacesContext)
40     */

41    public Object JavaDoc saveState(FacesContext context)
42    {
43       Object JavaDoc values[] = new Object JavaDoc[5];
44       values[0] = super.saveState(context);
45       values[1] = this.value;
46       values[2] = this.disabled;
47       values[3] = this.label;
48       values[4] = this.tooltip;
49       return ((Object JavaDoc) (values));
50    }
51
52    /**
53     * @see javax.faces.component.StateHolder#restoreState(javax.faces.context.FacesContext, java.lang.Object)
54     */

55    public void restoreState(FacesContext context, Object JavaDoc state)
56    {
57       Object JavaDoc values[] = (Object JavaDoc[])state;
58       super.restoreState(context, values[0]);
59       this.value = values[1];
60       this.disabled = (Boolean JavaDoc)values[2];
61       this.label = (String JavaDoc)values[3];
62       this.tooltip = (String JavaDoc)values[4];
63    }
64    
65    
66    // ------------------------------------------------------------------------------
67
// Strongly typed component property accessors
68

69    /**
70     * Get the value - the value is used in a equals() match against the current value in the
71     * parent ModeList component to set the selected item.
72     *
73     * @return the value
74     */

75    public Object JavaDoc getValue()
76    {
77       ValueBinding vb = getValueBinding("value");
78       if (vb != null)
79       {
80          this.value = vb.getValue(getFacesContext());
81       }
82       
83       return this.value;
84    }
85
86    /**
87     * Set the value - the value is used in a equals() match against the current value in the
88     * parent ModeList component to set the selected item.
89     *
90     * @param value the value
91     */

92    public void setValue(Object JavaDoc value)
93    {
94       this.value = value;
95    }
96    
97    /**
98     * Returns the disabled flag
99     *
100     * @return true if the mode list is disabled
101     */

102    public boolean isDisabled()
103    {
104       ValueBinding vb = getValueBinding("disabled");
105       if (vb != null)
106       {
107          this.disabled = (Boolean JavaDoc)vb.getValue(getFacesContext());
108       }
109       
110       if (this.disabled != null)
111       {
112          return this.disabled.booleanValue();
113       }
114       else
115       {
116          // return the default
117
return false;
118       }
119    }
120
121    /**
122     * Sets whether the mode list is disabled
123     *
124     * @param disabled the disabled flag
125     */

126    public void setDisabled(boolean disabled)
127    {
128       this.disabled = disabled;
129    }
130    
131    /**
132     * @return Returns the label.
133     */

134    public String JavaDoc getLabel()
135    {
136       ValueBinding vb = getValueBinding("label");
137       if (vb != null)
138       {
139          this.label = (String JavaDoc)vb.getValue(getFacesContext());
140       }
141       
142       return this.label;
143    }
144
145    /**
146     * @param label The label to set.
147     */

148    public void setLabel(String JavaDoc label)
149    {
150       this.label = label;
151    }
152
153    /**
154     * @return Returns the tooltip.
155     */

156    public String JavaDoc getTooltip()
157    {
158       ValueBinding vb = getValueBinding("tooltip");
159       if (vb != null)
160       {
161          this.tooltip = (String JavaDoc)vb.getValue(getFacesContext());
162       }
163       
164       return this.tooltip;
165    }
166
167    /**
168     * @param tooltip The tooltip to set.
169     */

170    public void setTooltip(String JavaDoc tooltip)
171    {
172       this.tooltip = tooltip;
173    }
174    
175    
176    // ------------------------------------------------------------------------------
177
// Private data
178

179    /** the component value */
180    private Object JavaDoc value = null;
181    
182    /** disabled flag */
183    private Boolean JavaDoc disabled = null;
184    
185    /** the tooltip */
186    private String JavaDoc tooltip;
187
188    /** the label */
189    private String JavaDoc label;
190 }
191
Popular Tags