1
2
3
4
5
6
7
8
9
10
11 package org.kuali.rice.krad.uif.container;
12
13 import org.apache.commons.lang.StringUtils;
14 import org.kuali.rice.core.api.mo.common.active.ImmutableInactivatable;
15 import org.kuali.rice.krad.uif.UifConstants;
16 import org.kuali.rice.krad.uif.UifParameters;
17 import org.kuali.rice.krad.uif.core.ActiveCollectionFilter;
18 import org.kuali.rice.krad.uif.core.BindingInfo;
19 import org.kuali.rice.krad.uif.core.CollectionFilter;
20 import org.kuali.rice.krad.uif.core.Component;
21 import org.kuali.rice.krad.uif.core.DataBinding;
22 import org.kuali.rice.krad.uif.field.ActionField;
23 import org.kuali.rice.krad.uif.field.AttributeField;
24 import org.kuali.rice.krad.uif.field.Field;
25 import org.kuali.rice.krad.uif.field.LabelField;
26 import org.kuali.rice.krad.uif.util.ComponentUtils;
27
28 import java.util.ArrayList;
29 import java.util.List;
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 public class CollectionGroup extends Group implements DataBinding {
52 private static final long serialVersionUID = -6496712566071542452L;
53
54 private Class<?> collectionObjectClass;
55
56 private String propertyName;
57 private BindingInfo bindingInfo;
58
59 private boolean renderAddLine;
60 private String addLinePropertyName;
61 private BindingInfo addLineBindingInfo;
62 private LabelField addLineLabelField;
63 private List<? extends Field> addLineFields;
64 private List<ActionField> addLineActionFields;
65
66 private boolean renderLineActions;
67 private List<ActionField> actionFields;
68
69 private boolean showInactive;
70 private CollectionFilter activeCollectionFilter;
71
72 private List<CollectionGroup> subCollections;
73
74 private CollectionGroupBuilder collectionGroupBuilder;
75
76 public CollectionGroup() {
77 renderAddLine = true;
78 renderLineActions = true;
79 showInactive = false;
80
81 actionFields = new ArrayList<ActionField>();
82 addLineFields = new ArrayList<Field>();
83 addLineActionFields = new ArrayList<ActionField>();
84 subCollections = new ArrayList<CollectionGroup>();
85 }
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102 @Override
103 public void performInitialization(View view) {
104 setFieldBindingObjectPath(getBindingInfo().getBindingObjectPath());
105
106 super.performInitialization(view);
107
108 if (bindingInfo != null) {
109 bindingInfo.setDefaults(view, getPropertyName());
110 }
111
112 if (addLineBindingInfo != null) {
113
114 if (StringUtils.isNotBlank(addLinePropertyName)) {
115 addLineBindingInfo.setDefaults(view, getPropertyName());
116 addLineBindingInfo.setBindingName(addLinePropertyName);
117 if (StringUtils.isNotBlank(getFieldBindByNamePrefix())) {
118 addLineBindingInfo.setBindByNamePrefix(getFieldBindByNamePrefix());
119 }
120 }
121 }
122
123 for (Component item : getItems()) {
124 if (item instanceof AttributeField) {
125 AttributeField field = (AttributeField) item;
126
127 if (StringUtils.isBlank(field.getDictionaryObjectEntry())) {
128 field.setDictionaryObjectEntry(collectionObjectClass.getName());
129 }
130 }
131 }
132
133 if ((addLineFields == null) || addLineFields.isEmpty()) {
134 addLineFields = getItems();
135 }
136
137
138 if (this.activeCollectionFilter == null) {
139 activeCollectionFilter = new ActiveCollectionFilter();
140 }
141
142
143 String collectionPath = "";
144 if (StringUtils.isNotBlank(getBindingInfo().getCollectionPath())) {
145 collectionPath += getBindingInfo().getCollectionPath() + ".";
146 }
147 if (StringUtils.isNotBlank(getBindingInfo().getBindByNamePrefix())) {
148 collectionPath += getBindingInfo().getBindByNamePrefix() + ".";
149 }
150 collectionPath += getBindingInfo().getBindingName();
151
152 List<AttributeField> collectionFields = ComponentUtils.getComponentsOfTypeDeep(getItems(), AttributeField.class);
153 for (AttributeField collectionField : collectionFields) {
154 collectionField.getBindingInfo().setCollectionPath(collectionPath);
155 }
156
157 for (CollectionGroup collectionGroup : getSubCollections()) {
158 collectionGroup.getBindingInfo().setCollectionPath(collectionPath);
159 view.getViewHelperService().performComponentInitialization(view, collectionGroup);
160 }
161
162
163 if (!view.getAbstractTypeClasses().containsKey(collectionPath)) {
164 view.getAbstractTypeClasses().put(collectionPath, getCollectionObjectClass());
165 }
166
167
168
169 for (Component item : getItems()) {
170 view.getViewHelperService().performComponentInitialization(view, item);
171 }
172 }
173
174
175
176
177
178
179
180
181 @Override
182 public void performApplyModel(View view, Object model, Component parent) {
183 super.performApplyModel(view, model, parent);
184
185 pushCollectionGroupToReference();
186
187 performCollectionFiltering(view, model);
188
189 getCollectionGroupBuilder().build(view, model, this);
190
191 pushCollectionGroupToReference();
192 }
193
194
195
196
197
198 protected void pushCollectionGroupToReference() {
199 List<Component> components = this.getNestedComponents();
200
201 ComponentUtils
202 .pushObjectToContext(components, UifConstants.ContextVariableNames.COLLECTION_GROUP,
203 this);
204
205 List<ActionField> actionFields =
206 ComponentUtils.getComponentsOfTypeDeep(components, ActionField.class);
207 for (ActionField actionField : actionFields) {
208 actionField.addActionParameter(UifParameters.SELLECTED_COLLECTION_PATH,
209 this.getBindingInfo().getBindingPath());
210 }
211 }
212
213
214
215
216
217
218
219
220
221
222
223 protected void performCollectionFiltering(View view, Object model) {
224 if (ImmutableInactivatable.class.isAssignableFrom(this.collectionObjectClass) && !showInactive) {
225 this.activeCollectionFilter.filter(view, model, this);
226 }
227 }
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244 public void initializeNewCollectionLine(View view, Object model, CollectionGroup collectionGroup,
245 boolean clearExistingLine) {
246 getCollectionGroupBuilder().initializeNewCollectionLine(view, model, collectionGroup, clearExistingLine);
247 }
248
249
250
251
252 @Override
253 public List<Component> getNestedComponents() {
254 List<Component> components = super.getNestedComponents();
255
256 components.add(addLineLabelField);
257 components.addAll(actionFields);
258 components.addAll(addLineActionFields);
259
260
261
262
263
264 for (Component item : getItems()) {
265 if (components.contains(item)) {
266 components.remove(item);
267 }
268 }
269
270 return components;
271 }
272
273
274
275
276
277
278
279 public Class<?> getCollectionObjectClass() {
280 return this.collectionObjectClass;
281 }
282
283
284
285
286
287
288 public void setCollectionObjectClass(Class<?> collectionObjectClass) {
289 this.collectionObjectClass = collectionObjectClass;
290 }
291
292
293
294
295 public String getPropertyName() {
296 return this.propertyName;
297 }
298
299
300
301
302
303
304 public void setPropertyName(String propertyName) {
305 this.propertyName = propertyName;
306 }
307
308
309
310
311
312
313
314
315 public BindingInfo getBindingInfo() {
316 return this.bindingInfo;
317 }
318
319
320
321
322
323
324 public void setBindingInfo(BindingInfo bindingInfo) {
325 this.bindingInfo = bindingInfo;
326 }
327
328
329
330
331
332
333
334 public List<ActionField> getActionFields() {
335 return this.actionFields;
336 }
337
338
339
340
341
342
343 public void setActionFields(List<ActionField> actionFields) {
344 this.actionFields = actionFields;
345 }
346
347
348
349
350
351
352
353 public boolean isRenderLineActions() {
354 return this.renderLineActions;
355 }
356
357
358
359
360
361
362 public void setRenderLineActions(boolean renderLineActions) {
363 this.renderLineActions = renderLineActions;
364 }
365
366
367
368
369
370
371
372 public boolean isRenderAddLine() {
373 return this.renderAddLine;
374 }
375
376
377
378
379
380
381 public void setRenderAddLine(boolean renderAddLine) {
382 this.renderAddLine = renderAddLine;
383 }
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398 public String getAddLineLabel() {
399 if (getAddLineLabelField() != null) {
400 return getAddLineLabelField().getLabelText();
401 }
402
403 return null;
404 }
405
406
407
408
409
410
411 public void setAddLineLabel(String addLineLabel) {
412 if (getAddLineLabelField() != null) {
413 getAddLineLabelField().setLabelText(addLineLabel);
414 }
415 }
416
417
418
419
420
421
422
423 public LabelField getAddLineLabelField() {
424 return this.addLineLabelField;
425 }
426
427
428
429
430
431
432
433 public void setAddLineLabelField(LabelField addLineLabelField) {
434 this.addLineLabelField = addLineLabelField;
435 }
436
437
438
439
440
441
442
443
444
445 public String getAddLinePropertyName() {
446 return this.addLinePropertyName;
447 }
448
449
450
451
452
453
454 public void setAddLinePropertyName(String addLinePropertyName) {
455 this.addLinePropertyName = addLinePropertyName;
456 }
457
458
459
460
461
462
463
464
465
466
467
468 public BindingInfo getAddLineBindingInfo() {
469 return this.addLineBindingInfo;
470 }
471
472
473
474
475
476
477 public void setAddLineBindingInfo(BindingInfo addLineBindingInfo) {
478 this.addLineBindingInfo = addLineBindingInfo;
479 }
480
481
482
483
484
485
486
487
488 public List<? extends Field> getAddLineFields() {
489 return this.addLineFields;
490 }
491
492
493
494
495
496
497 public void setAddLineFields(List<? extends Field> addLineFields) {
498 this.addLineFields = addLineFields;
499 }
500
501
502
503
504
505
506
507
508 public List<ActionField> getAddLineActionFields() {
509 return this.addLineActionFields;
510 }
511
512
513
514
515
516
517 public void setAddLineActionFields(List<ActionField> addLineActionFields) {
518 this.addLineActionFields = addLineActionFields;
519 }
520
521
522
523
524
525
526
527
528
529
530
531
532
533 public boolean isShowInactive() {
534 return showInactive;
535 }
536
537
538
539
540
541
542 public void setShowInactive(boolean showInactive) {
543 this.showInactive = showInactive;
544 }
545
546
547
548
549
550
551
552 public CollectionFilter getActiveCollectionFilter() {
553 return activeCollectionFilter;
554 }
555
556
557
558
559
560
561
562 public void setActiveCollectionFilter(CollectionFilter activeCollectionFilter) {
563 this.activeCollectionFilter = activeCollectionFilter;
564 }
565
566
567
568
569
570
571
572 public List<CollectionGroup> getSubCollections() {
573 return this.subCollections;
574 }
575
576
577
578
579
580
581 public void setSubCollections(List<CollectionGroup> subCollections) {
582 this.subCollections = subCollections;
583 }
584
585
586
587
588
589
590
591 public CollectionGroupBuilder getCollectionGroupBuilder() {
592 if (this.collectionGroupBuilder == null) {
593 this.collectionGroupBuilder = new CollectionGroupBuilder();
594 }
595 return this.collectionGroupBuilder;
596 }
597
598
599
600
601
602
603 public void setCollectionGroupBuilder(CollectionGroupBuilder collectionGroupBuilder) {
604 this.collectionGroupBuilder = collectionGroupBuilder;
605 }
606
607
608
609
610 @SuppressWarnings("unchecked")
611 @Override
612 public List<? extends Field> getItems() {
613 return (List<? extends Field>) super.getItems();
614 }
615
616 }