KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > web > ui > repo > renderer > property > PropertyRenderer


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.renderer.property;
18
19 import java.io.IOException JavaDoc;
20 import java.util.List JavaDoc;
21
22 import javax.faces.component.UIComponent;
23 import javax.faces.context.FacesContext;
24 import javax.faces.context.ResponseWriter;
25
26 import org.alfresco.web.ui.common.Utils;
27 import org.alfresco.web.ui.common.renderer.BaseRenderer;
28 import org.alfresco.web.ui.repo.component.property.UIProperty;
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31
32 /**
33  * Renderer for the UIProperty component
34  *
35  * @author gavinc
36  */

37 public class PropertyRenderer extends BaseRenderer
38 {
39    private static Log logger = LogFactory.getLog(PropertyRenderer.class);
40    
41    /**
42     * @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
43     */

44    public void encodeBegin(FacesContext context, UIComponent component) throws IOException JavaDoc
45    {
46       if (component.isRendered() == false)
47       {
48          return;
49       }
50
51       // NOTE: we close off the first <td> generated by the property sheet's grid renderer
52
context.getResponseWriter().write("</td>");
53    }
54
55    /**
56     * @see javax.faces.render.Renderer#encodeChildren(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
57     */

58    public void encodeChildren(FacesContext context, UIComponent component) throws IOException JavaDoc
59    {
60       if (component.isRendered() == false)
61       {
62          return;
63       }
64       
65       UIProperty property = (UIProperty)component;
66       ResponseWriter out = context.getResponseWriter();
67       
68       // make sure there are exactly 2 child components
69
int count = property.getChildCount();
70       
71       if (count == 2)
72       {
73          // get the label and the control
74
List JavaDoc<UIComponent> kids = property.getChildren();
75          UIComponent label = kids.get(0);
76          UIComponent control = kids.get(1);
77          
78          // place a style class on the label column if necessary
79
String JavaDoc labelStylceClass = (String JavaDoc)property.getParent().getAttributes().get("labelStyleClass");
80          out.write("</td><td");
81          if (labelStylceClass != null)
82          {
83             outputAttribute(out, labelStylceClass, "class");
84          }
85          
86          // close the <td>
87
out.write(">");
88          // encode the label
89
Utils.encodeRecursive(context, label);
90          // encode the control
91
out.write("</td><td>");
92          Utils.encodeRecursive(context, control);
93          
94          // NOTE: we'll allow the property sheet's grid renderer close off the last <td>
95
}
96    }
97
98    /**
99     * @see javax.faces.render.Renderer#encodeEnd(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
100     */

101    public void encodeEnd(FacesContext context, UIComponent component) throws IOException JavaDoc
102    {
103       // we don't need to do anything in here
104
}
105
106    /**
107     * @see javax.faces.render.Renderer#getRendersChildren()
108     */

109    public boolean getRendersChildren()
110    {
111       return true;
112    }
113
114 }
115
Popular Tags