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.apt.annotation.Preliminary;
23  import org.apache.myfaces.tobago.context.Markup;
24  import org.apache.myfaces.tobago.internal.component.AbstractUISplitLayout;
25  import org.apache.myfaces.tobago.layout.Orientation;
26  import org.apache.myfaces.tobago.renderkit.RendererBase;
27  import org.apache.myfaces.tobago.renderkit.css.BootstrapClass;
28  import org.apache.myfaces.tobago.renderkit.css.TobagoClass;
29  import org.apache.myfaces.tobago.renderkit.html.CustomAttributes;
30  import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
31  import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
32  import org.apache.myfaces.tobago.renderkit.html.HtmlInputTypes;
33  import org.apache.myfaces.tobago.util.ComponentUtils;
34  import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
35  import org.slf4j.Logger;
36  import org.slf4j.LoggerFactory;
37  
38  import javax.faces.context.FacesContext;
39  import java.io.IOException;
40  import java.lang.invoke.MethodHandles;
41  
42  /**
43   * <p>
44   * WARNING: This component is preliminary and may be changed without a major release.
45   * </p>
46   */
47  @Preliminary
48  public class SplitLayoutRenderer<T extends AbstractUISplitLayout> extends RendererBase<T> {
49  
50    private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
51  
52    private static final String SUFFIX_SIZES = ComponentUtils.SUB_SEPARATOR + "sizes";
53  
54    @Override
55    public void decodeInternal(final FacesContext facesContext, final T component) {
56      final String sourceId = facesContext.getExternalContext().getRequestParameterMap().get("javax.faces.source");
57      final String clientId = component.getClientId() + SUFFIX_SIZES;
58      if (clientId.equals(sourceId)) {
59        // only decode and update layout at resize request
60  //      final Map<String, String> parameterMap = facesContext.getExternalContext().getRequestParameterMap();
61  //      final String position = parameterMap.get(clientId + SUFFIX_SIZES);
62        LOG.warn("todo update layout");
63        //      ((AbstractUISplitLayout) component).updateLayout(Integer.parseInt(position));
64      }
65    }
66  
67    @Override
68    public void encodeBeginInternal(final FacesContext facesContext, final T component) throws IOException {
69  
70      final TobagoResponseWriter writer = getResponseWriter(facesContext);
71      final Markup markup = component.getMarkup();
72  
73      writer.startElement(HtmlElements.TOBAGO_SPLIT_LAYOUT);
74      writer.writeIdAttribute(component.getClientId(facesContext));
75      writer.writeClassAttribute(
76          component.isHorizontal() ? BootstrapClass.FLEX_ROW : BootstrapClass.FLEX_COLUMN,
77          markup != null && markup.contains(Markup.SPREAD) ? TobagoClass.SPREAD : null);
78      writer.writeAttribute(CustomAttributes.ORIENTATION,
79          component.isHorizontal() ? Orientation.HORIZONTAL : Orientation.VERTICAL, false);
80    }
81  
82    @Override
83    public void encodeEndInternal(final FacesContext facesContext, final T component) throws IOException {
84  
85      final TobagoResponseWriter writer = getResponseWriter(facesContext);
86  
87      writer.startElement(HtmlElements.INPUT);
88      writer.writeNameAttribute(component.getClientId(facesContext) + SUFFIX_SIZES);
89      writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.HIDDEN);
90  //    writer.writeAttribute(HtmlAttributes.VALUE, sizes);
91      writer.endElement(HtmlElements.INPUT);
92  
93      writer.endElement(HtmlElements.TOBAGO_SPLIT_LAYOUT);
94    }
95  }