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.facelets;
21  
22  import org.apache.myfaces.tobago.component.Attributes;
23  import org.apache.myfaces.tobago.component.UIExtensionPanel;
24  
25  import javax.faces.component.UIComponent;
26  import javax.faces.view.facelets.FaceletContext;
27  import javax.faces.view.facelets.TagAttribute;
28  import javax.faces.view.facelets.TagConfig;
29  import javax.faces.view.facelets.TagHandler;
30  import java.io.IOException;
31  import java.util.Map;
32  
33  /**
34   * @deprecated since 3.0.0
35   */
36  @Deprecated
37  public class GridLayoutConstraintHandler extends TagHandler {
38  
39    private final TagAttribute columnSpan;
40    private final TagAttribute rowSpan;
41  
42    public GridLayoutConstraintHandler(final TagConfig config) {
43      super(config);
44      columnSpan = getAttribute(Attributes.columnSpan.getName());
45      rowSpan = getAttribute(Attributes.rowSpan.getName());
46    }
47  
48    @Override
49    public void apply(final FaceletContext faceletContext, UIComponent parent) throws IOException {
50      final Map<String, Object> attributes = parent.getAttributes();
51      if (parent.getParent() != null && parent.getParent() instanceof UIExtensionPanel) {
52        parent = parent.getParent();
53      } else if (attributes.get("tobago.panel") != null
54          && attributes.get("tobago.panel") instanceof UIExtensionPanel) {
55        parent = (UIComponent) attributes.get("tobago.panel");
56      }
57  
58      if (columnSpan != null) {
59        if (columnSpan.isLiteral()) {
60          attributes.put(Attributes.columnSpan.getName(), Integer.valueOf(columnSpan.getValue()));
61        } else {
62          parent.setValueExpression(Attributes.columnSpan.getName(),
63              columnSpan.getValueExpression(faceletContext, Integer.TYPE));
64        }
65      }
66  
67      if (rowSpan != null) {
68        if (rowSpan.isLiteral()) {
69          attributes.put(Attributes.rowSpan.getName(), Integer.valueOf(rowSpan.getValue()));
70        } else {
71          parent.setValueExpression(Attributes.rowSpan.getName(),
72              rowSpan.getValueExpression(faceletContext, Integer.TYPE));
73        }
74      }
75    }
76  }