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.service.KRADServiceLocatorWeb;
20 import org.kuali.rice.krad.uif.component.KeepExpression;
21 import org.kuali.rice.krad.uif.container.CollectionGroup;
22 import org.kuali.rice.krad.uif.container.Container;
23 import org.kuali.rice.krad.uif.container.Group;
24 import org.kuali.rice.krad.uif.field.FieldGroup;
25 import org.kuali.rice.krad.uif.view.View;
26 import org.kuali.rice.krad.uif.component.Component;
27 import org.kuali.rice.krad.uif.component.DataBinding;
28 import org.kuali.rice.krad.uif.field.ActionField;
29 import org.kuali.rice.krad.uif.field.Field;
30 import org.kuali.rice.krad.uif.util.ComponentUtils;
31 import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
32
33 import java.util.ArrayList;
34 import java.util.List;
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 public class StackedLayoutManager extends LayoutManagerBase implements CollectionLayoutManager {
56 private static final long serialVersionUID = 4602368505430238846L;
57
58 @KeepExpression
59 private String summaryTitle;
60 private List<String> summaryFields;
61
62 private Group addLineGroup;
63 private Group lineGroupPrototype;
64 private FieldGroup subCollectionFieldGroupPrototype;
65 private Field selectFieldPrototype;
66 private Group wrapperGroup;
67
68 private List<Group> stackedGroups;
69
70 public StackedLayoutManager() {
71 super();
72
73 summaryFields = new ArrayList<String>();
74 stackedGroups = new ArrayList<Group>();
75 }
76
77
78
79
80
81
82
83
84
85
86
87 @Override
88 public void performInitialization(View view, Object model, Container container) {
89 super.performInitialization(view, model, container);
90
91 stackedGroups = new ArrayList<Group>();
92
93 if (addLineGroup != null) {
94 view.getViewHelperService().performComponentInitialization(view, model, addLineGroup);
95 }
96 view.getViewHelperService().performComponentInitialization(view, model, lineGroupPrototype);
97 view.getViewHelperService().performComponentInitialization(view, model, subCollectionFieldGroupPrototype);
98 view.getViewHelperService().performComponentInitialization(view, model, selectFieldPrototype);
99 }
100
101
102
103
104
105
106
107
108
109
110
111 @Override
112 public void performApplyModel(View view, Object model, Container container) {
113 super.performApplyModel(view, model, container);
114
115 if (wrapperGroup != null) {
116 wrapperGroup.setItems(stackedGroups);
117 }
118 }
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133 public void buildLine(View view, Object model, CollectionGroup collectionGroup, List<Field> lineFields,
134 List<FieldGroup> subCollectionFields, String bindingPath, List<ActionField> actions, String idSuffix,
135 Object currentLine, int lineIndex) {
136 boolean isAddLine = lineIndex == -1;
137
138
139 Group lineGroup = null;
140 if (isAddLine) {
141 stackedGroups = new ArrayList<Group>();
142
143 if (addLineGroup == null) {
144 lineGroup = ComponentUtils.copy(lineGroupPrototype, idSuffix);
145 } else {
146 lineGroup = ComponentUtils.copy(getAddLineGroup(), idSuffix);
147 }
148 } else {
149 lineGroup = ComponentUtils.copy(lineGroupPrototype, idSuffix);
150 }
151
152 ComponentUtils.updateContextForLine(lineGroup, currentLine, lineIndex);
153
154
155 String headerText = "";
156 if (isAddLine) {
157 headerText = collectionGroup.getAddLineLabel();
158 } else {
159
160 List<Object> modelCollection = ObjectPropertyUtils.getPropertyValue(model,
161 ((DataBinding) collectionGroup).getBindingInfo().getBindingPath());
162
163 headerText = buildLineHeaderText(modelCollection.get(lineIndex), lineGroup);
164 }
165
166
167 if (StringUtils.isNotBlank(headerText)) {
168 lineGroup.getHeader().setHeaderText(headerText);
169 }
170
171
172 List<Field> groupFields = new ArrayList<Field>();
173 groupFields.addAll(lineFields);
174 groupFields.addAll(subCollectionFields);
175
176 lineGroup.setItems(groupFields);
177
178
179 if (collectionGroup.isRenderLineActions() && !collectionGroup.isReadOnly() && (lineGroup.getFooter() != null)) {
180 lineGroup.getFooter().setItems(actions);
181 }
182
183 stackedGroups.add(lineGroup);
184 }
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205 protected String buildLineHeaderText(Object line, Group lineGroup) {
206
207 if (KRADServiceLocatorWeb.getExpressionEvaluatorService().containsElPlaceholder(summaryTitle)) {
208 lineGroup.getPropertyExpressions().put("title", summaryTitle);
209 return null;
210 }
211
212
213 String summaryFieldString = "";
214 for (String summaryField : summaryFields) {
215 Object summaryFieldValue = ObjectPropertyUtils.getPropertyValue(line, summaryField);
216 if (StringUtils.isNotBlank(summaryFieldString)) {
217 summaryFieldString += " - ";
218 }
219
220 if (summaryFieldValue != null) {
221 summaryFieldString += summaryFieldValue;
222 } else {
223 summaryFieldString += "Null";
224 }
225 }
226
227 String headerText = summaryTitle;
228 if (StringUtils.isNotBlank(summaryFieldString)) {
229 headerText += " ( " + summaryFieldString + " )";
230 }
231
232 return headerText;
233 }
234
235
236
237
238 @Override
239 public Class<? extends Container> getSupportedContainer() {
240 return CollectionGroup.class;
241 }
242
243
244
245
246 @Override
247 public List<Component> getComponentsForLifecycle() {
248 List<Component> components = super.getComponentsForLifecycle();
249
250 if (wrapperGroup != null) {
251 components.add(wrapperGroup);
252 } else {
253 components.addAll(stackedGroups);
254 }
255
256 return components;
257 }
258
259
260
261
262 @Override
263 public List<Component> getComponentPrototypes() {
264 List<Component> components = super.getComponentPrototypes();
265
266 components.add(addLineGroup);
267 components.add(lineGroupPrototype);
268 components.add(subCollectionFieldGroupPrototype);
269 components.add(selectFieldPrototype);
270
271 return components;
272 }
273
274
275
276
277
278
279
280
281 public String getSummaryTitle() {
282 return this.summaryTitle;
283 }
284
285
286
287
288
289
290 public void setSummaryTitle(String summaryTitle) {
291 this.summaryTitle = summaryTitle;
292 }
293
294
295
296
297
298
299
300
301
302
303 public List<String> getSummaryFields() {
304 return this.summaryFields;
305 }
306
307
308
309
310
311
312 public void setSummaryFields(List<String> summaryFields) {
313 this.summaryFields = summaryFields;
314 }
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329 public Group getAddLineGroup() {
330 return this.addLineGroup;
331 }
332
333
334
335
336
337
338 public void setAddLineGroup(Group addLineGroup) {
339 this.addLineGroup = addLineGroup;
340 }
341
342
343
344
345
346
347
348
349 public Group getLineGroupPrototype() {
350 return this.lineGroupPrototype;
351 }
352
353
354
355
356
357
358 public void setLineGroupPrototype(Group lineGroupPrototype) {
359 this.lineGroupPrototype = lineGroupPrototype;
360 }
361
362
363
364
365 public FieldGroup getSubCollectionFieldGroupPrototype() {
366 return this.subCollectionFieldGroupPrototype;
367 }
368
369
370
371
372
373
374 public void setSubCollectionFieldGroupPrototype(FieldGroup subCollectionFieldGroupPrototype) {
375 this.subCollectionFieldGroupPrototype = subCollectionFieldGroupPrototype;
376 }
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391 public Field getSelectFieldPrototype() {
392 return selectFieldPrototype;
393 }
394
395
396
397
398
399
400 public void setSelectFieldPrototype(Field selectFieldPrototype) {
401 this.selectFieldPrototype = selectFieldPrototype;
402 }
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419 public Group getWrapperGroup() {
420 return wrapperGroup;
421 }
422
423
424
425
426
427
428 public void setWrapperGroup(Group wrapperGroup) {
429 this.wrapperGroup = wrapperGroup;
430 }
431
432
433
434
435
436
437 public List<Group> getStackedGroups() {
438 return this.stackedGroups;
439 }
440
441
442
443
444
445
446 public void setStackedGroups(List<Group> stackedGroups) {
447 this.stackedGroups = stackedGroups;
448 }
449
450 }