KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.HashMap JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import javax.faces.component.UICommand;
23 import javax.faces.context.FacesContext;
24 import javax.faces.el.ValueBinding;
25
26 /**
27  * @author kevinr
28  */

29 public class UIActionLink extends UICommand
30 {
31    // ------------------------------------------------------------------------------
32
// Construction
33

34    /**
35     * Default Constructor
36     */

37    public UIActionLink()
38    {
39       setRendererType("org.alfresco.faces.ActionLinkRenderer");
40    }
41    
42    
43    // ------------------------------------------------------------------------------
44
// Component implementation
45

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

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

57    public void restoreState(FacesContext context, Object JavaDoc state)
58    {
59       Object JavaDoc values[] = (Object JavaDoc[])state;
60       // standard component attributes are restored by the super class
61
super.restoreState(context, values[0]);
62       this.padding = (Integer JavaDoc)values[1];
63       this.image = (String JavaDoc)values[2];
64       this.showLink = (Boolean JavaDoc)values[3];
65       this.params = (Map JavaDoc)values[4];
66       this.href = (String JavaDoc)values[5];
67       this.tooltip = (String JavaDoc)values[6];
68       this.target = (String JavaDoc)values[7];
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[8];
77       // standard component attributes are saved by the super class
78
values[0] = super.saveState(context);
79       values[1] = this.padding;
80       values[2] = this.image;
81       values[3] = this.showLink;
82       values[4] = this.params;
83       values[5] = this.href;
84       values[6] = this.tooltip;
85       values[7] = this.target;
86       return (values);
87    }
88
89    
90    // ------------------------------------------------------------------------------
91
// Strongly typed component property accessors
92

93    /**
94     * Return the current child parameter map for this action link instance.
95     * This map is filled with name/value pairs from any child UIParameter components.
96     *
97     * @return Map of name/value pairs
98     */

99    public Map JavaDoc<String JavaDoc, String JavaDoc> getParameterMap()
100    {
101       if (this.params == null)
102       {
103          this.params = new HashMap JavaDoc<String JavaDoc, String JavaDoc>(3, 1.0f);
104       }
105       return this.params;
106    }
107    
108    /**
109     * Get whether to show the link as well as the image if specified
110     *
111     * @return true to show the link as well as the image if specified
112     */

113    public boolean getShowLink()
114    {
115       ValueBinding vb = getValueBinding("showLink");
116       if (vb != null)
117       {
118          this.showLink = (Boolean JavaDoc)vb.getValue(getFacesContext());
119       }
120       
121       if (this.showLink != null)
122       {
123          return this.showLink.booleanValue();
124       }
125       else
126       {
127          // return default
128
return true;
129       }
130    }
131    
132    /**
133     * Set whether to show the link as well as the image if specified
134     *
135     * @param showLink Whether to show the link as well as the image if specified
136     */

137    public void setShowLink(boolean showLink)
138    {
139       this.showLink = Boolean.valueOf(showLink);
140    }
141    
142    /**
143     * Get the padding value for rendering this component in a table.
144     *
145     * @return the padding in pixels, if set != 0 then a table will be rendering around the items
146     */

147    public int getPadding()
148    {
149       ValueBinding vb = getValueBinding("padding");
150       if (vb != null)
151       {
152          this.padding = (Integer JavaDoc)vb.getValue(getFacesContext());
153       }
154       
155       if (this.padding != null)
156       {
157          return this.padding.intValue();
158       }
159       else
160       {
161          // return default
162
return 0;
163       }
164    }
165    
166    /**
167     * Set the padding value for rendering this component in a table.
168     *
169     * @param padding value in pixels, if set != 0 then a table will be rendering around the items
170     */

171    public void setPadding(int padding)
172    {
173       this.padding = padding;
174    }
175    
176    /**
177     * Return the Image path to use for this actionlink.
178     * If an image is specified, it is shown in additon to the value text unless
179     * the 'showLink' property is set to 'false'.
180     *
181     * @return the image path to display
182     */

183    public String JavaDoc getImage()
184    {
185       ValueBinding vb = getValueBinding("image");
186       if (vb != null)
187       {
188          this.image = (String JavaDoc)vb.getValue(getFacesContext());
189       }
190       
191       return this.image;
192    }
193    
194    /**
195     * Set the Image path to use for this actionlink.
196     * If an image is specified, it is shown in additon to the value text unless
197     * the 'showLink' property is set to 'false'.
198     *
199     * @param image Image path to display
200     */

201    public void setImage(String JavaDoc image)
202    {
203       this.image = image;
204    }
205    
206    /**
207     * @return Returns the href.
208     */

209    public String JavaDoc getHref()
210    {
211       ValueBinding vb = getValueBinding("href");
212       if (vb != null)
213       {
214          this.href = (String JavaDoc)vb.getValue(getFacesContext());
215       }
216       
217       return this.href;
218    }
219    
220    /**
221     * @param href The href to set.
222     */

223    public void setHref(String JavaDoc href)
224    {
225       this.href = href;
226    }
227    
228    /**
229     * Get the tooltip title text
230     *
231     * @return the tooltip
232     */

233    public String JavaDoc getTooltip()
234    {
235       ValueBinding vb = getValueBinding("tooltip");
236       if (vb != null)
237       {
238          this.tooltip = (String JavaDoc)vb.getValue(getFacesContext());
239       }
240       
241       return this.tooltip;
242    }
243
244    /**
245     * Set the tooltip title text
246     *
247     * @param tooltip the tooltip
248     */

249    public void setTooltip(String JavaDoc tooltip)
250    {
251       this.tooltip = tooltip;
252    }
253    
254    /**
255     * Get the target
256     *
257     * @return the target
258     */

259    public String JavaDoc getTarget()
260    {
261       ValueBinding vb = getValueBinding("target");
262       if (vb != null)
263       {
264          this.target = (String JavaDoc)vb.getValue(getFacesContext());
265       }
266       
267       return this.target;
268    }
269
270    /**
271     * Set the target
272     *
273     * @param target the target
274     */

275    public void setTarget(String JavaDoc target)
276    {
277       this.target = target;
278    }
279    
280    /**
281     * Returns the onclick handler
282     *
283     * @return The onclick handler
284     */

285    public String JavaDoc getOnclick()
286    {
287       ValueBinding vb = getValueBinding("onclick");
288       if (vb != null)
289       {
290          this.onclick = (String JavaDoc)vb.getValue(getFacesContext());
291       }
292       
293       return this.onclick;
294    }
295
296    /**
297     * Sets the onclick handler
298     *
299     * @param onclick The onclick handler
300     */

301    public void setOnclick(String JavaDoc onclick)
302    {
303       this.onclick = onclick;
304    }
305    
306    
307    // ------------------------------------------------------------------------------
308
// Private data
309

310    /** the padding value in pixels, if set != 0 then a table will be rendered around the items */
311    private Integer JavaDoc padding = null;
312    
313    /** True to show the link as well as the image if specified */
314    private Boolean JavaDoc showLink = null;
315    
316    /** If an image is specified, it is shown in additon to the value text */
317    private String JavaDoc image = null;
318    
319    /** static href to use instead of an action/actionlistener */
320    private String JavaDoc href = null;
321    
322    /** tooltip title text to display on the action link */
323    private String JavaDoc tooltip = null;
324    
325    /** the target reference */
326    private String JavaDoc target = null;
327    
328    /** the onclick handler */
329    private String JavaDoc onclick = null;
330    
331    /** Map of child param name/values pairs */
332    private Map JavaDoc<String JavaDoc, String JavaDoc> params = null;
333 }
334
Popular Tags