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