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