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.MultiplicityGroup;
21 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityGroupItem;
22 import org.kuali.student.common.ui.client.mvc.DataModel;
23 import org.kuali.student.r1.common.assembly.data.Data;
24 import org.kuali.student.r1.common.assembly.data.QueryPath;
25 import org.kuali.student.r1.common.assembly.data.Data.Property;
26
27
28
29
30
31
32 public class MultiplicityGroupBinding extends ModelWidgetBindingSupport<MultiplicityGroup> {
33 public static MultiplicityGroupBinding INSTANCE = new MultiplicityGroupBinding();
34
35 public MultiplicityGroupBinding() {};
36
37
38
39
40
41 public void setModelValue(MultiplicityGroup mcWidget, DataModel model, String path) {
42 for (MultiplicityGroupItem item : mcWidget.getItems()) {
43 MultiplicityGroupItemBinding.INSTANCE.setModelValue(item, model, mcWidget.getParentPath());
44 }
45 for (MultiplicityGroupItem item : mcWidget.getRemovedItems()) {
46
47
48 if(item.isCreated()==false){
49 MultiplicityGroupItemBinding.INSTANCE.setModelValue(item, model, path);
50 }
51 }
52 }
53
54
55
56
57
58 public void setWidgetValue(MultiplicityGroup mg, DataModel model, String path) {
59 mg.clear();
60
61 String fieldPath = mg.translatePath(path);
62
63 mg.setParentPath(fieldPath);
64
65 QueryPath qPath = QueryPath.parse(fieldPath);
66 Data data = null;
67 if(model!=null){
68 data = model.get(qPath);
69 }
70
71 if (data != null) {
72 Iterator<Property> itr = data.iterator();
73 while (itr.hasNext()) {
74 Property p = (Property) itr.next();
75
76 if (p.getKey() instanceof Integer && !isItemDeleted(model, path, (Integer)p.getKey(), mg)) {
77 MultiplicityGroupItem mgi = mg.createItem();
78 mgi.setCreated(false);
79 mgi.setItemKey((Integer) p.getKey());
80 MultiplicityGroupItemBinding.INSTANCE.setWidgetValue(mgi, model, fieldPath);
81 } else {
82 mg.incrementItemKey();
83 }
84 }
85 }
86 }
87
88
89
90
91
92
93
94
95 public boolean isItemDeleted(DataModel model, String path, Integer index, MultiplicityGroup mcWidget){
96 boolean isDeleted = false;
97
98
99 if (!mcWidget.getConfig().isUpdateable()) {
100
101 QueryPath runtimeDeletedPath = QueryPath.concat(path, String.valueOf(index), MultiplicityGroupItemBinding.RT_DELETED);
102
103 Boolean runtimeDeleted = model.get(runtimeDeletedPath);
104 if (runtimeDeleted != null){
105 isDeleted = runtimeDeleted;
106 }
107 return isDeleted;
108 }
109
110 return isDeleted;
111 }
112
113
114 }