1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.common.ui.client.configurable.mvc.binding;
17
18 import java.util.Iterator;
19
20 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.DisplayMultiplicityComposite;
21 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityComposite;
22 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityItem;
23 import org.kuali.student.common.ui.client.mvc.DataModel;
24 import org.kuali.student.r1.common.assembly.data.Data;
25 import org.kuali.student.r1.common.assembly.data.QueryPath;
26 import org.kuali.student.r1.common.assembly.data.Data.Property;
27
28
29
30
31
32
33
34
35
36
37 public class MultiplicityCompositeBinding extends ModelWidgetBindingSupport<MultiplicityComposite> {
38 public static MultiplicityCompositeBinding INSTANCE = new MultiplicityCompositeBinding();
39
40 private MultiplicityCompositeBinding() {};
41
42
43
44
45
46 @Override
47 public void setModelValue(MultiplicityComposite mcWidget, DataModel model, String path) {
48 for (MultiplicityItem item : mcWidget.getItems()) {
49 MultiplicityItemBinding.INSTANCE.setModelValue(item, model, path);
50 }
51 for (MultiplicityItem item : mcWidget.getRemovedItems()) {
52
53
54 if(item.isCreated()==false){
55 MultiplicityItemBinding.INSTANCE.setModelValue(item, model, path);
56 }
57 }
58 }
59
60
61
62
63
64 @Override
65 public void setWidgetValue(MultiplicityComposite mcWidget, DataModel model, String path) {
66 mcWidget.clear();
67
68 QueryPath qPath = QueryPath.parse(path);
69 Data data = null;
70 if(model!=null){
71 data = model.get(qPath);
72 }
73
74 if (data != null) {
75 Iterator<Property> itr = data.iterator();
76 while (itr.hasNext()) {
77 Property p = (Property) itr.next();
78
79 if (p.getKey() instanceof Integer && !isItemDeleted(model, path, (Integer)p.getKey(), mcWidget)) {
80 MultiplicityItem item = mcWidget.addItem();
81 item.setCreated(false);
82 item.setItemKey((Integer) p.getKey());
83 MultiplicityItemBinding.INSTANCE.setWidgetValue(item, model, path);
84 } else {
85 mcWidget.incrementItemKey();
86 }
87 }
88 }
89 }
90
91
92
93
94
95
96
97
98 public boolean isItemDeleted(DataModel model, String path, Integer index, MultiplicityComposite mcWidget){
99 boolean isDeleted = false;
100
101
102 if (!(mcWidget instanceof DisplayMultiplicityComposite)) {
103
104 QueryPath runtimeDeletedPath = QueryPath.concat(path, String.valueOf(index), MultiplicityItemBinding.RT_DELETED);
105
106 Boolean runtimeDeleted = model.get(runtimeDeletedPath);
107 if (runtimeDeleted != null){
108 isDeleted = runtimeDeleted;
109 }
110 return isDeleted;
111 }
112
113 return isDeleted;
114 }
115
116
117 }