1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.tobago.facelets;
21
22 import org.apache.myfaces.tobago.component.Attributes;
23
24 import javax.faces.component.UIComponent;
25 import javax.faces.view.facelets.FaceletContext;
26 import javax.faces.view.facelets.TagAttribute;
27 import javax.faces.view.facelets.TagConfig;
28 import javax.faces.view.facelets.TagHandler;
29 import java.io.IOException;
30 import java.util.Map;
31
32
33
34
35 public class GridLayoutConstraintHandler extends TagHandler {
36
37 private final TagAttribute columnSpan;
38 private final TagAttribute rowSpan;
39 private final TagAttribute gridColumn;
40 private final TagAttribute gridRow;
41
42 public GridLayoutConstraintHandler(final TagConfig config) {
43 super(config);
44
45 final TagAttribute oldColumn = getAttribute(Attributes.column.getName());
46 final TagAttribute newColumn = getAttribute(Attributes.columnSpan.getName());
47 columnSpan = newColumn != null ? newColumn : oldColumn;
48
49 final TagAttribute oldRow = getAttribute(Attributes.row.getName());
50 final TagAttribute newRow = getAttribute(Attributes.rowSpan.getName());
51 rowSpan = newRow != null ? newRow : oldRow;
52
53 gridColumn = getAttribute(Attributes.gridColumn.getName());
54
55 gridRow = getAttribute(Attributes.gridRow.getName());
56 }
57
58 @Override
59 public void apply(final FaceletContext faceletContext, final UIComponent parent) throws IOException {
60 final Map<String, Object> attributes = parent.getAttributes();
61
62 if (columnSpan != null) {
63 if (columnSpan.isLiteral()) {
64 attributes.put(Attributes.columnSpan.getName(), Integer.valueOf(columnSpan.getValue()));
65 } else {
66 parent.setValueExpression(Attributes.columnSpan.getName(),
67 columnSpan.getValueExpression(faceletContext, Integer.TYPE));
68 }
69 }
70
71 if (rowSpan != null) {
72 if (rowSpan.isLiteral()) {
73 attributes.put(Attributes.rowSpan.getName(), Integer.valueOf(rowSpan.getValue()));
74 } else {
75 parent.setValueExpression(Attributes.rowSpan.getName(),
76 rowSpan.getValueExpression(faceletContext, Integer.TYPE));
77 }
78 }
79
80 if (gridColumn != null) {
81 if (gridColumn.isLiteral()) {
82 attributes.put(Attributes.gridColumn.getName(), Integer.valueOf(gridColumn.getValue()));
83 } else {
84 parent.setValueExpression(Attributes.gridColumn.getName(),
85 gridColumn.getValueExpression(faceletContext, Integer.TYPE));
86 }
87 }
88
89 if (gridRow != null) {
90 if (gridRow.isLiteral()) {
91 attributes.put(Attributes.gridRow.getName(), Integer.valueOf(gridRow.getValue()));
92 } else {
93 parent.setValueExpression(Attributes.gridRow.getName(),
94 gridRow.getValueExpression(faceletContext, Integer.TYPE));
95 }
96 }
97 }
98 }