View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag;
21  
22  import org.apache.myfaces.tobago.component.UIColumn;
23  import org.apache.myfaces.tobago.component.UILink;
24  import org.apache.myfaces.tobago.component.UIOut;
25  import org.apache.myfaces.tobago.context.Markup;
26  import org.apache.myfaces.tobago.internal.component.AbstractUIMenu;
27  import org.apache.myfaces.tobago.renderkit.LayoutComponentRendererBase;
28  import org.apache.myfaces.tobago.renderkit.util.RenderUtils;
29  import org.apache.myfaces.tobago.util.ComponentUtils;
30  import org.apache.myfaces.tobago.util.FacetUtils;
31  
32  import javax.faces.component.UIComponent;
33  import javax.faces.context.FacesContext;
34  import java.io.IOException;
35  
36  public class ColumnRenderer extends LayoutComponentRendererBase {
37  
38    @Override
39    public void prepareRender(FacesContext facesContext, UIComponent component) throws IOException {
40      super.prepareRender(facesContext, component);
41  
42      final UIColumn column = (UIColumn) component;
43      if (isPure(column)) {
44        ComponentUtils.addCurrentMarkup(column, Markup.PURE);
45      }
46    }
47  
48    /**
49     * Differ between simple content and complex content.
50     * Decide if the content of a cell needs usually the whole possible space or
51     * is the character of the content like flowing text.
52     * In the second case, the style usually sets a padding.<br/>
53     * Pure is needed for &lt;tc:panel>,  &lt;tc:in>, etc.<br/>
54     * Pure is not needed for  &lt;tc:out> and &lt;tc:link>
55     */
56    private boolean isPure(UIColumn column) {
57      for (UIComponent child : column.getChildren()) {
58        if (!(child instanceof UIOut) && !(child instanceof UILink)) {
59          return true;
60        }
61      }
62      return false;
63    }
64  
65    @Override
66    public boolean getPrepareRendersChildren() {
67      return true;
68    }
69  
70    @Override
71    public void prepareRendersChildren(FacesContext facesContext, UIComponent component) throws IOException {
72      AbstractUIMenu dropDownMenu = FacetUtils.getDropDownMenu(component);
73      if (dropDownMenu != null) {
74        RenderUtils.prepareRendererAll(facesContext, dropDownMenu);
75      }
76    }
77  
78    @Override
79    public boolean getRendersChildren() {
80      return true;
81    }
82  }