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.renderkit.renderer;
21  
22  import org.apache.myfaces.tobago.context.Markup;
23  import org.apache.myfaces.tobago.internal.component.AbstractUIPanel;
24  import org.apache.myfaces.tobago.internal.component.AbstractUIReload;
25  import org.apache.myfaces.tobago.internal.util.HtmlRendererUtils;
26  import org.apache.myfaces.tobago.model.CollapseMode;
27  import org.apache.myfaces.tobago.renderkit.css.TobagoClass;
28  import org.apache.myfaces.tobago.renderkit.html.DataAttributes;
29  import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
30  import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
31  import org.apache.myfaces.tobago.util.ComponentUtils;
32  import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
33  
34  import javax.faces.context.FacesContext;
35  import java.io.IOException;
36  
37  public class PanelRenderer<T extends AbstractUIPanel> extends CollapsiblePanelRendererBase<T> {
38  
39    @Override
40    public void encodeBeginInternal(final FacesContext facesContext, final T component) throws IOException {
41  
42      final TobagoResponseWriter writer = getResponseWriter(facesContext);
43      final String clientId = component.getClientId(facesContext);
44      final boolean collapsed = component.isCollapsed();
45      final Markup markup = component.getMarkup();
46      final AbstractUIReload reload = ComponentUtils.getReloadFacet(component);
47  
48      writer.startElement(HtmlElements.TOBAGO_PANEL);
49      writer.writeIdAttribute(clientId);
50  
51      writer.writeClassAttribute(
52          collapsed ? TobagoClass.COLLAPSED : null,
53          TobagoClass.PANEL.createMarkup(markup),
54          component.getCustomClass(),
55          markup != null && markup.contains(Markup.SPREAD) ? TobagoClass.SPREAD : null);
56  
57      HtmlRendererUtils.writeDataAttributes(facesContext, writer, component);
58      final String tip = component.getTip();
59      if (tip != null) {
60        writer.writeAttribute(HtmlAttributes.TITLE, tip, true);
61      }
62  
63      if (reload != null && reload.isRendered()) {
64        writer.writeAttribute(DataAttributes.RELOAD, reload.getFrequency());
65      }
66  
67      if (component.getCollapsedMode() != CollapseMode.none) {
68        encodeHidden(writer, clientId, collapsed);
69      }
70  
71      encodeBehavior(writer, facesContext, component);
72    }
73  
74    @Override
75    public void encodeEndInternal(final FacesContext facesContext, final T component) throws IOException {
76      final TobagoResponseWriter writer = getResponseWriter(facesContext);
77      writer.endElement(HtmlElements.TOBAGO_PANEL);
78    }
79  }