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 import org.apache.myfaces.tobago.component.UIGridLayout;
24 import org.apache.myfaces.tobago.layout.Measure;
25
26 import javax.faces.view.facelets.FaceletContext;
27 import javax.faces.view.facelets.MetaRule;
28 import javax.faces.view.facelets.Metadata;
29 import javax.faces.view.facelets.MetadataTarget;
30 import javax.faces.view.facelets.TagAttribute;
31
32 public class GridLayoutRule extends MetaRule {
33
34 public static final GridLayoutRule INSTANCE = new GridLayoutRule();
35
36 public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget metadataTarget) {
37 if (metadataTarget.isTargetInstanceOf(UIGridLayout.class)) {
38 if (attribute.isLiteral()) {
39 if (Attributes.COLUMN_SPACING.equals(name)) {
40 return new ColumnSpacingMapper(attribute);
41 }
42 if (Attributes.ROW_SPACING.equals(name)) {
43 return new RowSpacingMapper(attribute);
44 }
45 if (Attributes.CELLSPACING.equals(name)) {
46 return new CellspacingMapper(attribute);
47 }
48 if (Attributes.MARGIN_LEFT.equals(name)) {
49 return new MarginLeftMapper(attribute);
50 }
51 if (Attributes.MARGIN_TOP.equals(name)) {
52 return new MarginTopMapper(attribute);
53 }
54 if (Attributes.MARGIN_RIGHT.equals(name)) {
55 return new MarginRightMapper(attribute);
56 }
57 if (Attributes.MARGIN_BOTTOM.equals(name)) {
58 return new MarginBottomMapper(attribute);
59 }
60 if (Attributes.MARGIN.equals(name)) {
61 return new MarginMapper(attribute);
62 }
63 }
64 }
65 return null;
66 }
67
68 static final class ColumnSpacingMapper extends Metadata {
69 private final TagAttribute attribute;
70
71 ColumnSpacingMapper(TagAttribute attribute) {
72 this.attribute = attribute;
73 }
74
75 public void applyMetadata(FaceletContext ctx, Object instance) {
76 UIGridLayout gridLayout = (UIGridLayout) instance;
77 gridLayout.setColumnSpacing(Measure.parse(attribute.getValue()));
78 }
79 }
80
81 static final class RowSpacingMapper extends Metadata {
82 private final TagAttribute attribute;
83
84 RowSpacingMapper(TagAttribute attribute) {
85 this.attribute = attribute;
86 }
87
88 public void applyMetadata(FaceletContext ctx, Object instance) {
89 UIGridLayout gridLayout = (UIGridLayout) instance;
90 gridLayout.setRowSpacing(Measure.parse(attribute.getValue()));
91 }
92 }
93
94 static final class CellspacingMapper extends Metadata {
95 private final TagAttribute attribute;
96
97 CellspacingMapper(TagAttribute attribute) {
98 this.attribute = attribute;
99 }
100
101 public void applyMetadata(FaceletContext ctx, Object instance) {
102 UIGridLayout gridLayout = (UIGridLayout) instance;
103 gridLayout.setCellspacing(Measure.parse(attribute.getValue()));
104 }
105 }
106
107 static final class MarginLeftMapper extends Metadata {
108 private final TagAttribute attribute;
109
110 MarginLeftMapper(TagAttribute attribute) {
111 this.attribute = attribute;
112 }
113
114 public void applyMetadata(FaceletContext ctx, Object instance) {
115 UIGridLayout gridLayout = (UIGridLayout) instance;
116 gridLayout.setMarginLeft(Measure.valueOf(attribute.getValue()));
117 }
118 }
119
120 static final class MarginTopMapper extends Metadata {
121 private final TagAttribute attribute;
122
123 MarginTopMapper(TagAttribute attribute) {
124 this.attribute = attribute;
125 }
126
127 public void applyMetadata(FaceletContext ctx, Object instance) {
128 UIGridLayout gridLayout = (UIGridLayout) instance;
129 gridLayout.setMarginTop(Measure.valueOf(attribute.getValue()));
130 }
131 }
132
133 static final class MarginRightMapper extends Metadata {
134 private final TagAttribute attribute;
135
136 MarginRightMapper(TagAttribute attribute) {
137 this.attribute = attribute;
138 }
139
140 public void applyMetadata(FaceletContext ctx, Object instance) {
141 UIGridLayout gridLayout = (UIGridLayout) instance;
142 gridLayout.setMarginRight(Measure.valueOf(attribute.getValue()));
143 }
144 }
145
146 static final class MarginBottomMapper extends Metadata {
147 private final TagAttribute attribute;
148
149 MarginBottomMapper(TagAttribute attribute) {
150 this.attribute = attribute;
151 }
152
153 public void applyMetadata(FaceletContext ctx, Object instance) {
154 UIGridLayout gridLayout = (UIGridLayout) instance;
155 gridLayout.setMarginBottom(Measure.valueOf(attribute.getValue()));
156 }
157 }
158
159 static final class MarginMapper extends Metadata {
160 private final TagAttribute attribute;
161
162 MarginMapper(TagAttribute attribute) {
163 this.attribute = attribute;
164 }
165
166 public void applyMetadata(FaceletContext ctx, Object instance) {
167 UIGridLayout gridLayout = (UIGridLayout) instance;
168 gridLayout.setMargin(Measure.valueOf(attribute.getValue()));
169 }
170 }
171 }