KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > web > ui > repo > component > shelf > UIShelfGroup


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.repo.component.shelf;
18
19 import java.io.IOException JavaDoc;
20 import java.util.Iterator JavaDoc;
21
22 import javax.faces.component.UIComponent;
23 import javax.faces.context.FacesContext;
24 import javax.faces.context.ResponseWriter;
25 import javax.faces.el.ValueBinding;
26
27 import org.alfresco.web.ui.common.Utils;
28 import org.alfresco.web.ui.common.component.SelfRenderingComponent;
29
30 /**
31  * @author Kevin Roast
32  */

33 public class UIShelfGroup extends SelfRenderingComponent
34 {
35    // ------------------------------------------------------------------------------
36
// Component Impl
37

38    /**
39     * @see javax.faces.component.UIComponent#getFamily()
40     */

41    public String JavaDoc getFamily()
42    {
43       return "org.alfresco.faces.Shelf";
44    }
45
46    /**
47     * @see javax.faces.component.StateHolder#restoreState(javax.faces.context.FacesContext, java.lang.Object)
48     */

49    public void restoreState(FacesContext context, Object JavaDoc state)
50    {
51       Object JavaDoc values[] = (Object JavaDoc[])state;
52       // standard component attributes are restored by the super class
53
super.restoreState(context, values[0]);
54       this.expanded = ((Boolean JavaDoc)values[1]).booleanValue();
55       this.label = (String JavaDoc)values[2];
56    }
57    
58    /**
59     * @see javax.faces.component.StateHolder#saveState(javax.faces.context.FacesContext)
60     */

61    public Object JavaDoc saveState(FacesContext context)
62    {
63       Object JavaDoc values[] = new Object JavaDoc[3];
64       // standard component attributes are saved by the super class
65
values[0] = super.saveState(context);
66       values[1] = (this.expanded ? Boolean.TRUE : Boolean.FALSE);
67       values[2] = this.label;
68       return values;
69    }
70    
71    /**
72     * @see javax.faces.component.UIComponentBase#encodeChildren(javax.faces.context.FacesContext)
73     */

74    public void encodeChildren(FacesContext context) throws IOException JavaDoc
75    {
76       if (isRendered() == false)
77       {
78          return;
79       }
80       
81       ResponseWriter out = context.getResponseWriter();
82       
83       // output each shelf group component in turn
84
out.write("<table cellspacing=0 cellpadding=0 border=0 width=100%>");
85       for (Iterator JavaDoc i=this.getChildren().iterator(); i.hasNext(); /**/)
86       {
87          UIComponent child = (UIComponent)i.next();
88          if (child instanceof UIShelfItem)
89          {
90             // render child items
91
out.write("<tr><td>");
92             Utils.encodeRecursive(context, child);
93             out.write("</tr></td>");
94          }
95       }
96       out.write("</table>");
97    }
98
99    /**
100     * @see javax.faces.component.UIComponentBase#getRendersChildren()
101     */

102    public boolean getRendersChildren()
103    {
104       return true;
105    }
106    
107    
108    // ------------------------------------------------------------------------------
109
// Strongly typed component property accessors
110

111    /**
112     * @return Returns the label.
113     */

114    public String JavaDoc getLabel()
115    {
116       ValueBinding vb = getValueBinding("label");
117       if (vb != null)
118       {
119          this.label = (String JavaDoc)vb.getValue(getFacesContext());
120       }
121       
122       return this.label;
123    }
124
125    /**
126     * @param label The label to set.
127     */

128    public void setLabel(String JavaDoc label)
129    {
130       this.label = label;
131    }
132    
133    /**
134     * Returns whether the component show allow rendering of its child components.
135     */

136    public boolean isExpanded()
137    {
138       ValueBinding vb = getValueBinding("expanded");
139       if (vb != null)
140       {
141          Boolean JavaDoc expanded = (Boolean JavaDoc)vb.getValue(getFacesContext());
142          if (expanded != null)
143          {
144             this.expanded = expanded.booleanValue();
145          }
146       }
147       
148       return this.expanded;
149    }
150    
151    /**
152     * Sets whether the group is expanded
153     */

154    public void setExpanded(boolean expanded)
155    {
156       this.expanded = expanded;
157    }
158    
159    
160    private String JavaDoc label = null;
161    private boolean expanded = false;
162 }
163
Popular Tags