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 if ((addLineFields == null) || addLineFields.isEmpty()) {
153 addLineFields = getItems();
154 }
155
156
157 if (this.activeCollectionFilter == null) {
158 activeCollectionFilter = new ActiveCollectionFilter();
159 }
160
161
162 String collectionPath = "";
163 if (StringUtils.isNotBlank(getBindingInfo().getCollectionPath())) {
164 collectionPath += getBindingInfo().getCollectionPath() + ".";
165 }
166 if (StringUtils.isNotBlank(getBindingInfo().getBindByNamePrefix())) {
167 collectionPath += getBindingInfo().getBindByNamePrefix() + ".";
168 }
169 collectionPath += getBindingInfo().getBindingName();
170
171 List<DataField> collectionFields = ComponentUtils.getComponentsOfTypeDeep(getItems(), DataField.class);
172 for (DataField collectionField : collectionFields) {
173 collectionField.getBindingInfo().setCollectionPath(collectionPath);
174 }
175
176
177 if (!view.getAbstractTypeClasses().containsKey(collectionPath)) {
178 view.getAbstractTypeClasses().put(collectionPath, getCollectionObjectClass());
179 }
180
181
182
183 for (Component item : getItems()) {
184 view.getViewHelperService().performComponentInitialization(view, model, item);
185 }
186
187 for (CollectionGroup collectionGroup : getSubCollections()) {
188 collectionGroup.getBindingInfo().setCollectionPath(collectionPath);
189 view.getViewHelperService().performComponentInitialization(view, model, collectionGroup);
190 }
191 }
192
193
194
195
196
197
198
199
200 @Override
201 public void performApplyModel(View view, Object model, Component parent) {
202 super.performApplyModel(view, model, parent);
203
204 pushCollectionGroupToReference();
205
206
207 if (isRender()) {
208 getCollectionGroupBuilder().build(view, model, this);
209 }
210
211
212 pushCollectionGroupToReference();
213 }
214
215
216
217
218
219 protected void pushCollectionGroupToReference() {
220 List<Component> components = this.getComponentsForLifecycle();
221
222 ComponentUtils.pushObjectToContext(components, UifConstants.ContextVariableNames.COLLECTION_GROUP, this);
223
224 List<ActionField> actionFields = ComponentUtils.getComponentsOfTypeDeep(components, ActionField.class);
225 for (ActionField actionField : actionFields) {
226 actionField.addActionParameter(UifParameters.SELLECTED_COLLECTION_PATH,
227 this.getBindingInfo().getBindingPath());
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> getComponentsForLifecycle() {
254 List<Component> components = super.getComponentsForLifecycle();
255
256 components.add(addLineLabelField);
257 components.add(collectionLookup);
258
259
260
261
262 for (Component item : getItems()) {
263 if (components.contains(item)) {
264 components.remove(item);
265 }
266 }
267
268 return components;
269 }
270
271
272
273
274 @Override
275 public List<Component> getComponentPrototypes() {
276 List<Component> components = super.getComponentPrototypes();
277
278 components.addAll(actionFields);
279 components.addAll(addLineActionFields);
280 components.addAll(getItems());
281 components.addAll(getSubCollections());
282
283 return components;
284 }
285
286
287
288
289
290
291
292 public Class<?> getCollectionObjectClass() {
293 return this.collectionObjectClass;
294 }
295
296
297
298
299
300
301 public void setCollectionObjectClass(Class<?> collectionObjectClass) {
302 this.collectionObjectClass = collectionObjectClass;
303 }
304
305
306
307
308 public String getPropertyName() {
309 return this.propertyName;
310 }
311
312
313
314
315
316
317 public void setPropertyName(String propertyName) {
318 this.propertyName = propertyName;
319 }
320
321
322
323
324
325
326
327
328 public BindingInfo getBindingInfo() {
329 return this.bindingInfo;
330 }
331
332
333
334
335
336
337 public void setBindingInfo(BindingInfo bindingInfo) {
338 this.bindingInfo = bindingInfo;
339 }
340
341
342
343
344
345
346
347 public List<ActionField> getActionFields() {
348 return this.actionFields;
349 }
350
351
352
353
354
355
356 public void setActionFields(List<ActionField> actionFields) {
357 this.actionFields = actionFields;
358 }
359
360
361
362
363
364
365
366 public boolean isRenderLineActions() {
367 return this.renderLineActions;
368 }
369
370
371
372
373
374
375 public void setRenderLineActions(boolean renderLineActions) {
376 this.renderLineActions = renderLineActions;
377 }
378
379
380
381
382
383
384
385 public boolean isRenderAddLine() {
386 return this.renderAddLine;
387 }
388
389
390
391
392
393
394 public void setRenderAddLine(boolean renderAddLine) {
395 this.renderAddLine = renderAddLine;
396 }
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411 public String getAddLineLabel() {
412 if (getAddLineLabelField() != null) {
413 return getAddLineLabelField().getLabelText();
414 }
415
416 return null;
417 }
418
419
420
421
422
423
424 public void setAddLineLabel(String addLineLabel) {
425 if (getAddLineLabelField() != null) {
426 getAddLineLabelField().setLabelText(addLineLabel);
427 }
428 }
429
430
431
432
433
434
435
436 public LabelField getAddLineLabelField() {
437 return this.addLineLabelField;
438 }
439
440
441
442
443
444
445
446 public void setAddLineLabelField(LabelField addLineLabelField) {
447 this.addLineLabelField = addLineLabelField;
448 }
449
450
451
452
453
454
455
456
457
458 public String getAddLinePropertyName() {
459 return this.addLinePropertyName;
460 }
461
462
463
464
465
466
467 public void setAddLinePropertyName(String addLinePropertyName) {
468 this.addLinePropertyName = addLinePropertyName;
469 }
470
471
472
473
474
475
476
477
478
479
480
481 public BindingInfo getAddLineBindingInfo() {
482 return this.addLineBindingInfo;
483 }
484
485
486
487
488
489
490 public void setAddLineBindingInfo(BindingInfo addLineBindingInfo) {
491 this.addLineBindingInfo = addLineBindingInfo;
492 }
493
494
495
496
497
498
499
500
501 public List<? extends Component> getAddLineFields() {
502 return this.addLineFields;
503 }
504
505
506
507
508
509
510 public void setAddLineFields(List<? extends Component> addLineFields) {
511 this.addLineFields = addLineFields;
512 }
513
514
515
516
517
518
519
520
521 public List<ActionField> getAddLineActionFields() {
522 return this.addLineActionFields;
523 }
524
525
526
527
528
529
530 public void setAddLineActionFields(List<ActionField> addLineActionFields) {
531 this.addLineActionFields = addLineActionFields;
532 }
533
534
535
536
537
538
539
540
541
542
543
544
545 public boolean isRenderSelectField() {
546 return renderSelectField;
547 }
548
549
550
551
552
553
554 public void setRenderSelectField(boolean renderSelectField) {
555 this.renderSelectField = renderSelectField;
556 }
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576 public String getSelectPropertyName() {
577 return selectPropertyName;
578 }
579
580
581
582
583
584
585 public void setSelectPropertyName(String selectPropertyName) {
586 this.selectPropertyName = selectPropertyName;
587 }
588
589
590
591
592
593
594
595
596
597
598
599
600 public QuickFinder getCollectionLookup() {
601 return collectionLookup;
602 }
603
604
605
606
607
608
609 public void setCollectionLookup(QuickFinder collectionLookup) {
610 this.collectionLookup = collectionLookup;
611 }
612
613
614
615
616
617
618
619
620
621
622
623
624
625 public boolean isShowInactive() {
626 return showInactive;
627 }
628
629
630
631
632
633
634 public void setShowInactive(boolean showInactive) {
635 this.showInactive = showInactive;
636 }
637
638
639
640
641
642
643
644 public CollectionFilter getActiveCollectionFilter() {
645 return activeCollectionFilter;
646 }
647
648
649
650
651
652
653
654 public void setActiveCollectionFilter(CollectionFilter activeCollectionFilter) {
655 this.activeCollectionFilter = activeCollectionFilter;
656 }
657
658
659
660
661
662
663
664 public List<CollectionFilter> getFilters() {
665 return filters;
666 }
667
668
669
670
671
672
673 public void setFilters(List<CollectionFilter> filters) {
674 this.filters = filters;
675 }
676
677
678
679
680
681
682
683 public List<CollectionGroup> getSubCollections() {
684 return this.subCollections;
685 }
686
687
688
689
690
691
692 public void setSubCollections(List<CollectionGroup> subCollections) {
693 this.subCollections = subCollections;
694 }
695
696
697
698
699
700
701
702
703
704
705 public String getSubCollectionSuffix() {
706 return subCollectionSuffix;
707 }
708
709
710
711
712
713
714
715 public void setSubCollectionSuffix(String subCollectionSuffix) {
716 this.subCollectionSuffix = subCollectionSuffix;
717 }
718
719
720
721
722
723
724 @Override
725 public CollectionGroupSecurity getComponentSecurity() {
726 return (CollectionGroupSecurity) super.getComponentSecurity();
727 }
728
729
730
731
732
733
734 @Override
735 public void setComponentSecurity(ComponentSecurity componentSecurity) {
736 if (!(componentSecurity instanceof CollectionGroupSecurity)) {
737 throw new RiceRuntimeException(
738 "Component security for CollectionGroup should be instance of CollectionGroupSecurity");
739 }
740
741 super.setComponentSecurity(componentSecurity);
742 }
743
744 @Override
745 protected Class<? extends ComponentSecurity> getComponentSecurityClass() {
746 return CollectionGroupSecurity.class;
747 }
748
749
750
751
752
753
754
755 public CollectionGroupBuilder getCollectionGroupBuilder() {
756 if (this.collectionGroupBuilder == null) {
757 this.collectionGroupBuilder = new CollectionGroupBuilder();
758 }
759 return this.collectionGroupBuilder;
760 }
761
762
763
764
765
766
767 public void setCollectionGroupBuilder(CollectionGroupBuilder collectionGroupBuilder) {
768 this.collectionGroupBuilder = collectionGroupBuilder;
769 }
770
771
772
773
774 public void setShowHideInactiveButton(boolean showHideInactiveButton) {
775 this.showHideInactiveButton = showHideInactiveButton;
776 }
777
778
779
780
781 public boolean isShowHideInactiveButton() {
782 return showHideInactiveButton;
783 }
784
785 }