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;
21  
22  import org.apache.myfaces.tobago.component.Facets;
23  import org.apache.myfaces.tobago.component.UIBox;
24  import org.apache.myfaces.tobago.component.UIMenuBar;
25  import org.apache.myfaces.tobago.config.Configurable;
26  import org.apache.myfaces.tobago.layout.Measure;
27  import org.apache.myfaces.tobago.util.ComponentUtils;
28  import org.slf4j.Logger;
29  import org.slf4j.LoggerFactory;
30  
31  import javax.faces.component.UIComponent;
32  import javax.faces.context.FacesContext;
33  import java.io.IOException;
34  
35  public abstract class BoxRendererBase extends LayoutComponentRendererBase {
36  
37    private static final Logger LOG = LoggerFactory.getLogger(BoxRendererBase.class);
38  
39    public boolean getRendersChildren() {
40      return true;
41    }
42  
43    @Override
44    public Measure getBorderTop(final FacesContext facesContext, final Configurable component) {
45  
46      Measure borderTop = super.getBorderTop(facesContext, component);
47      if (ComponentUtils.findFacetDescendant((UIComponent) component, Facets.MENUBAR, UIMenuBar.class) != null) {
48        borderTop = borderTop.add(19); // todo: get via theme config
49      }
50      return borderTop;
51    }
52  
53    @Override
54    public Measure getMinimumHeight(final FacesContext facesContext, final Configurable component) {
55      if (component instanceof UIBox && ((UIBox) component).isCollapsed()) {
56        return getBorderTop(facesContext, component);
57      }
58      return super.getMinimumHeight(facesContext, component);
59    }
60  
61    @Override
62    public Measure getMaximumHeight(final FacesContext facesContext, final Configurable component) {
63      if (component instanceof UIBox && ((UIBox) component).isCollapsed()) {
64        return getBorderTop(facesContext, component);
65      }
66      return super.getMaximumHeight(facesContext, component);
67    }
68  
69    protected UIMenuBar getMenuBarFacet(final UIComponent component) {
70      return (UIMenuBar) component.getFacet(Facets.MENUBAR);
71    }
72  
73    @Override
74    public void encodeChildren(final FacesContext facesContext, final UIComponent component) throws IOException {
75      if (component instanceof UIBox && ((UIBox) component).isCollapsed()) {
76        return;
77      }
78      super.encodeChildren(facesContext, component);
79    }
80  }