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.internal.component;
21  
22  import org.apache.myfaces.tobago.component.ComponentTypes;
23  import org.apache.myfaces.tobago.component.Facets;
24  import org.apache.myfaces.tobago.component.OnComponentPopulated;
25  import org.apache.myfaces.tobago.component.RendererTypes;
26  import org.apache.myfaces.tobago.internal.layout.LayoutUtils;
27  import org.apache.myfaces.tobago.layout.LayoutComponent;
28  import org.apache.myfaces.tobago.layout.LayoutContainer;
29  import org.apache.myfaces.tobago.layout.LayoutManager;
30  import org.apache.myfaces.tobago.util.CreateComponentUtils;
31  
32  import javax.faces.component.UIComponent;
33  import javax.faces.context.FacesContext;
34  import java.io.IOException;
35  import java.util.List;
36  
37  public abstract class AbstractUIPanel extends AbstractUIPanelBase
38      implements OnComponentPopulated, LayoutContainer, LayoutComponent {
39  
40    @Override
41    public void encodeBegin(FacesContext facesContext) throws IOException {
42  
43      super.encodeBegin(facesContext);
44      ((AbstractUILayoutBase) getLayoutManager()).encodeBegin(facesContext);
45    }
46  
47    @Override
48    public void encodeChildren(FacesContext facesContext) throws IOException {
49  
50      ((AbstractUILayoutBase) getLayoutManager()).encodeChildren(facesContext);
51    }
52  
53    @Override
54    public void encodeEnd(FacesContext facesContext) throws IOException {
55  
56      ((AbstractUILayoutBase) getLayoutManager()).encodeEnd(facesContext);
57      super.encodeEnd(facesContext);
58    }
59  
60    public void onComponentPopulated(FacesContext facesContext, UIComponent parent) {
61      if (getLayoutManager() == null) {
62        setLayoutManager(CreateComponentUtils.createAndInitLayout(
63            facesContext, ComponentTypes.GRID_LAYOUT, RendererTypes.GRID_LAYOUT, parent));
64      }
65    }
66  
67    public List<LayoutComponent> getComponents() {
68      return LayoutUtils.findLayoutChildren(this);
69    }
70  
71    public LayoutManager getLayoutManager() {
72      return (LayoutManager) getFacet(Facets.LAYOUT);
73    }
74  
75    public void setLayoutManager(LayoutManager layoutManager) {
76      getFacets().put(Facets.LAYOUT, (AbstractUILayoutBase) layoutManager);
77    }
78  
79    public boolean isLayoutChildren() {
80      return isRendered();
81    }
82  }