1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.layout;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21 import org.kuali.rice.krad.uif.CssConstants;
22 import org.kuali.rice.krad.uif.component.Component;
23 import org.kuali.rice.krad.uif.container.Container;
24 import org.kuali.rice.krad.uif.element.Label;
25 import org.kuali.rice.krad.uif.field.Field;
26 import org.kuali.rice.krad.uif.field.InputField;
27 import org.kuali.rice.krad.uif.util.LifecycleElement;
28
29 import java.util.ArrayList;
30 import java.util.List;
31
32
33
34
35
36
37
38
39
40 @BeanTag(name = "cssGridLabelColumnLayout", parent = "Uif-CssGridLabelColumnLayout")
41 public class CssGridLabelColumnLayoutManager extends CssGridLayoutManagerBase {
42 private static final long serialVersionUID = 3100360397450755904L;
43
44 private int numberOfLabelColumns = 1;
45 private String labelColumnCssClass = "";
46
47 private CssGridSizes labelColumnSizes;
48 private CssGridSizes fieldColumnSizes;
49
50
51 protected int xsCurrentFieldSize;
52 protected int smCurrentFieldSize;
53 protected int mdCurrentFieldSize;
54 protected int lgCurrentFieldSize;
55
56 public CssGridLabelColumnLayoutManager() {
57 super();
58 labelColumnSizes = new CssGridSizes();
59 fieldColumnSizes = new CssGridSizes();
60 }
61
62
63
64
65
66
67 @Override
68 public void performFinalize(Object model, LifecycleElement component) {
69 super.performFinalize(model, component);
70
71 Container container = (Container) component;
72 cellItems = new ArrayList<Component>();
73 processSeparateLabelLayout(container);
74 }
75
76
77
78
79
80
81
82
83 private void processSeparateLabelLayout(Container container) {
84
85 int labelColumnSize = 3;
86 int fieldColumnSize = 9;
87 if (numberOfLabelColumns > 1) {
88 labelColumnSize = (NUMBER_OF_COLUMNS / numberOfLabelColumns) * 1 / 3;
89 fieldColumnSize = (NUMBER_OF_COLUMNS / numberOfLabelColumns) * 2 / 3;
90 }
91
92 for (Component item : container.getItems()) {
93
94 if (!(item instanceof Field)) {
95 throw new RuntimeException("Must use fields "
96 + " for CssGridLabelColumnLayouts. Item class: "
97 + item.getClass().getName()
98 +
99 " in Container id: "
100 + container.getId());
101 } else if (((Field) item).getFieldLabel() == null) {
102 throw new RuntimeException(
103 "Label must exist on fields in CssGridLabelColumnLayoutManager. Item class: " + item.getClass()
104 .getName() + " in Container id: " + container.getId());
105 }
106
107 xsCurrentFieldSize = 0;
108 smCurrentFieldSize = 0;
109 mdCurrentFieldSize = 0;
110 lgCurrentFieldSize = 0;
111
112 Field field = (Field) item;
113 Label label = separateLabel(field);
114
115
116 List<String> cellCssClasses = label.getWrapperCssClasses();
117 if (cellCssClasses == null) {
118 label.setWrapperCssClasses(new ArrayList<String>());
119 cellCssClasses = label.getWrapperCssClasses();
120 }
121
122 cellCssClasses.add(0, labelColumnCssClass);
123 calculateCssClassAndSize(label, cellCssClasses, labelColumnSizes, labelColumnSize);
124
125
126 addLeftClearCssClass(cellCssClasses);
127 cellCssClassAttributes.add(getCellStyleClassesAsString(cellCssClasses));
128
129
130 cellItems.add(label);
131
132
133 cellCssClasses = field.getWrapperCssClasses();
134 if (cellCssClasses == null) {
135 field.setWrapperCssClasses(new ArrayList<String>());
136 cellCssClasses = field.getWrapperCssClasses();
137 }
138
139 calculateCssClassAndSize(field, cellCssClasses, fieldColumnSizes, fieldColumnSize);
140
141
142
143
144
145 if (xsCurrentFieldSize > 0 && xsCurrentFieldSize <= CssGridLayoutManagerBase.NUMBER_OF_COLUMNS) {
146 label.addStyleClass(CssConstants.CssGrid.XS_FLOAT_RIGHT);
147 } else if (smCurrentFieldSize > 0 && smCurrentFieldSize <= CssGridLayoutManagerBase.NUMBER_OF_COLUMNS) {
148 label.addStyleClass(CssConstants.CssGrid.SM_FLOAT_RIGHT);
149 } else if (mdCurrentFieldSize > 0 && mdCurrentFieldSize <= CssGridLayoutManagerBase.NUMBER_OF_COLUMNS) {
150 label.addStyleClass(CssConstants.CssGrid.MD_FLOAT_RIGHT);
151 } else if (lgCurrentFieldSize > 0 && lgCurrentFieldSize <= CssGridLayoutManagerBase.NUMBER_OF_COLUMNS) {
152 label.addStyleClass(CssConstants.CssGrid.LG_FLOAT_RIGHT);
153 }
154
155
156 addLeftClearCssClass(cellCssClasses);
157 cellCssClassAttributes.add(getCellStyleClassesAsString(cellCssClasses));
158
159
160 cellItems.add(field);
161 }
162
163 }
164
165
166
167
168
169
170
171 @Override
172 protected void calculateCssClassAndSize(Component item, List<String> cellCssClasses, CssGridSizes defaultSizes,
173 int basicSize) {
174 int xsPrevTotalSize = xsTotalSize;
175 int smPrevTotalSize = smTotalSize;
176 int mdPrevTotalSize = mdTotalSize;
177 int lgPrevTotalSize = lgTotalSize;
178
179 super.calculateCssClassAndSize(item, cellCssClasses, defaultSizes, basicSize);
180
181 xsCurrentFieldSize += xsTotalSize - xsPrevTotalSize;
182 smCurrentFieldSize += smTotalSize - smPrevTotalSize;
183 mdCurrentFieldSize += mdTotalSize - mdPrevTotalSize;
184 lgCurrentFieldSize += lgTotalSize - lgPrevTotalSize;
185 }
186
187
188
189
190
191
192
193
194 private Label separateLabel(Field field) {
195 Label label;
196 field.setLabelLeft(false);
197
198
199 field.getFieldLabel().addStyleClass("displayWith-" + field.getId());
200 if (!field.isRender() && StringUtils.isBlank(field.getProgressiveRender())) {
201 field.getFieldLabel().setRender(false);
202 } else if (!field.isRender() && StringUtils.isNotBlank(field.getProgressiveRender())) {
203 field.getFieldLabel().setRender(true);
204 String prefixStyle = "";
205 if (StringUtils.isNotBlank(field.getFieldLabel().getStyle())) {
206 prefixStyle = field.getFieldLabel().getStyle();
207 }
208 field.getFieldLabel().setStyle(prefixStyle + ";" + "display: none;");
209 }
210
211 label = field.getFieldLabel();
212
213 if (field instanceof InputField && field.getRequired() != null && field.getRequired()) {
214 label.setRenderRequiredIndicator(true);
215 }
216
217
218
219 field.setLabelRendered(true);
220
221 return label;
222 }
223
224
225
226
227
228
229 @BeanTagAttribute
230 public String getLabelColumnCssClass() {
231 return labelColumnCssClass;
232 }
233
234
235
236
237
238
239 public void setLabelColumnCssClass(String labelColumnCssClass) {
240 this.labelColumnCssClass = labelColumnCssClass;
241 }
242
243
244
245
246
247
248
249
250
251
252
253 @BeanTagAttribute
254 public int getNumberOfLabelColumns() {
255 return numberOfLabelColumns;
256 }
257
258
259
260
261
262
263 public void setNumberOfLabelColumns(int numberOfLabelColumns) {
264 this.numberOfLabelColumns = numberOfLabelColumns;
265 }
266
267
268
269
270
271
272
273
274
275
276
277
278
279 @BeanTagAttribute(name = "labelColumnSizes", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
280 public CssGridSizes getLabelColumnSizes() {
281 return labelColumnSizes;
282 }
283
284
285
286
287 public void setLabelColumnSizes(CssGridSizes labelColumnSizes) {
288 this.labelColumnSizes = labelColumnSizes;
289 }
290
291
292
293
294
295
296
297
298
299
300
301
302
303 @BeanTagAttribute(name = "fieldColumnSizes", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
304 public CssGridSizes getFieldColumnSizes() {
305 return fieldColumnSizes;
306 }
307
308
309
310
311 public void setFieldColumnSizes(CssGridSizes fieldColumnSizes) {
312 this.fieldColumnSizes = fieldColumnSizes;
313 }
314 }