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