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