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 java.util.ArrayList;
19 import java.util.List;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
23 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
24 import org.kuali.rice.krad.datadictionary.parse.BeanTags;
25 import org.kuali.rice.krad.uif.CssConstants;
26 import org.kuali.rice.krad.uif.component.Component;
27 import org.kuali.rice.krad.uif.container.Container;
28 import org.kuali.rice.krad.uif.container.Group;
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 @BeanTags({@BeanTag(name = "gridLayout-bean", parent = "Uif-GridLayoutBase"),
46 @BeanTag(name = "twoColumnGridLayout-bean", parent = "Uif-TwoColumnGridLayout"),
47 @BeanTag(name = "fourColumnGridLayout-bean", parent = "Uif-FourColumnGridLayout"),
48 @BeanTag(name = "sixColumnGridLayout-bean", parent = "Uif-SixColumnGridLayout")})
49 public class GridLayoutManager extends LayoutManagerBase {
50 private static final long serialVersionUID = 1890011900375071128L;
51
52 private int numberOfColumns;
53
54 private boolean suppressLineWrapping;
55 private boolean applyAlternatingRowStyles;
56 private boolean applyDefaultCellWidths;
57 private boolean renderFirstRowHeader;
58 private boolean renderAlternatingHeaderColumns;
59 private boolean renderRowFirstCellHeader;
60
61 private List<String> rowCssClasses;
62
63 public GridLayoutManager() {
64 super();
65
66 rowCssClasses = new ArrayList<String>();
67 }
68
69
70
71
72
73
74
75
76
77
78
79
80
81 @Override
82 public void performFinalize(Object model, Component component) {
83 super.performFinalize(model, component);
84
85 Container container = (Container) component;
86
87 if (suppressLineWrapping) {
88 numberOfColumns = container.getItems().size();
89 }
90
91 for (Component item : container.getItems()) {
92 if (!(this instanceof TableLayoutManager)) {
93 item.addWrapperCssClass("uif-gridLayoutCell");
94 }
95 setCellAttributes(item);
96 }
97 }
98
99
100
101
102
103
104
105 protected void setCellAttributes(Component component) {
106 if (StringUtils.isNotBlank(component.getWidth()) && StringUtils.isBlank(component.getCellWidth())) {
107 component.setCellWidth(component.getWidth());
108 component.setWidth("");
109 }
110
111 if (StringUtils.isNotBlank(component.getAlign()) && !StringUtils.contains(component.getWrapperStyle(),
112 CssConstants.TEXT_ALIGN)) {
113 if (component.getWrapperStyle() == null) {
114 component.setWrapperStyle("");
115 }
116
117 component.setWrapperStyle(
118 component.getWrapperStyle() + CssConstants.TEXT_ALIGN + component.getAlign() + ";");
119 component.setAlign("");
120 }
121
122 if (StringUtils.isNotBlank(component.getValign()) && !StringUtils.contains(component.getWrapperStyle(),
123 CssConstants.VERTICAL_ALIGN)) {
124 if (component.getWrapperStyle() == null) {
125 component.setWrapperStyle("");
126 }
127
128 component.setWrapperStyle(
129 component.getWrapperStyle() + CssConstants.VERTICAL_ALIGN + component.getValign() + ";");
130 component.setValign("");
131 }
132 }
133
134
135
136
137 @Override
138 public Class<? extends Container> getSupportedContainer() {
139 return Group.class;
140 }
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159 @BeanTagAttribute(name = "numberOfColumns")
160 public int getNumberOfColumns() {
161 return this.numberOfColumns;
162 }
163
164
165
166
167
168
169 public void setNumberOfColumns(int numberOfColumns) {
170 this.numberOfColumns = numberOfColumns;
171 }
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188 @BeanTagAttribute(name = "suppressLineWrapping")
189 public boolean isSuppressLineWrapping() {
190 return this.suppressLineWrapping;
191 }
192
193
194
195
196
197
198 public void setSuppressLineWrapping(boolean suppressLineWrapping) {
199 this.suppressLineWrapping = suppressLineWrapping;
200 }
201
202
203
204
205
206
207
208
209
210
211
212
213 @BeanTagAttribute(name = "applyAlternatingRowStyles")
214 public boolean isApplyAlternatingRowStyles() {
215 return this.applyAlternatingRowStyles;
216 }
217
218
219
220
221
222
223 public void setApplyAlternatingRowStyles(boolean applyAlternatingRowStyles) {
224 this.applyAlternatingRowStyles = applyAlternatingRowStyles;
225 }
226
227
228
229
230
231
232
233
234
235
236
237
238 @BeanTagAttribute(name = "applyDefaultCellWidths")
239 public boolean isApplyDefaultCellWidths() {
240 return this.applyDefaultCellWidths;
241 }
242
243
244
245
246
247
248 public void setApplyDefaultCellWidths(boolean applyDefaultCellWidths) {
249 this.applyDefaultCellWidths = applyDefaultCellWidths;
250 }
251
252
253
254
255
256
257
258
259
260
261
262
263 @BeanTagAttribute(name = "renderRowFirstCellHeader")
264 public boolean isRenderRowFirstCellHeader() {
265 return renderRowFirstCellHeader;
266 }
267
268
269
270
271
272
273 public void setRenderRowFirstCellHeader(boolean renderRowFirstCellHeader) {
274 this.renderRowFirstCellHeader = renderRowFirstCellHeader;
275 }
276
277
278
279
280
281
282
283
284
285
286
287
288
289 @BeanTagAttribute(name = "renderFirstRowHeader")
290 public boolean isRenderFirstRowHeader() {
291 return renderFirstRowHeader;
292 }
293
294
295
296
297
298
299 public void setRenderFirstRowHeader(boolean renderFirstRowHeader) {
300 this.renderFirstRowHeader = renderFirstRowHeader;
301 }
302
303
304
305
306
307
308
309
310
311
312
313
314 @BeanTagAttribute(name = "renderAlternatingHeaderColumns")
315 public boolean isRenderAlternatingHeaderColumns() {
316 return this.renderAlternatingHeaderColumns;
317 }
318
319
320
321
322
323
324 public void setRenderAlternatingHeaderColumns(boolean renderAlternatingHeaderColumns) {
325 this.renderAlternatingHeaderColumns = renderAlternatingHeaderColumns;
326 }
327
328
329
330
331
332
333
334
335
336
337
338
339
340 @BeanTagAttribute(name = "rowCssClasses", type = BeanTagAttribute.AttributeType.LISTVALUE)
341 public List<String> getRowCssClasses() {
342 return rowCssClasses;
343 }
344
345
346
347
348
349
350 public void setRowCssClasses(List<String> rowCssClasses) {
351 this.rowCssClasses = rowCssClasses;
352 }
353
354
355
356
357 @Override
358 protected <T> void copyProperties(T layoutManager) {
359 super.copyProperties(layoutManager);
360
361 GridLayoutManager gridLayoutManagerCopy = (GridLayoutManager) layoutManager;
362
363 gridLayoutManagerCopy.setNumberOfColumns(this.numberOfColumns);
364 gridLayoutManagerCopy.setSuppressLineWrapping(this.suppressLineWrapping);
365 gridLayoutManagerCopy.setApplyAlternatingRowStyles(this.applyAlternatingRowStyles);
366 gridLayoutManagerCopy.setApplyDefaultCellWidths(this.applyDefaultCellWidths);
367 gridLayoutManagerCopy.setRenderFirstRowHeader(this.renderFirstRowHeader);
368 gridLayoutManagerCopy.setRenderAlternatingHeaderColumns(this.renderAlternatingHeaderColumns);
369 gridLayoutManagerCopy.setRenderRowFirstCellHeader(this.renderRowFirstCellHeader);
370
371 if (rowCssClasses != null) {
372 gridLayoutManagerCopy.setRowCssClasses(new ArrayList<String>(rowCssClasses));
373 }
374 }
375 }