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 org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityItem; |
19 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.Section; |
20 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.SectionBinding; |
21 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
22 | |
import org.kuali.student.core.assembly.data.QueryPath; |
23 | |
|
24 | |
import com.google.gwt.core.client.GWT; |
25 | |
import com.google.gwt.user.client.ui.Widget; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 0 | public class MultiplicityItemBinding extends ModelWidgetBindingSupport<MultiplicityItem> { |
38 | 0 | public static MultiplicityItemBinding INSTANCE = new MultiplicityItemBinding(); |
39 | |
|
40 | 0 | protected static final String RT_CREATED = "_runtimeData" + QueryPath.getPathSeparator() + "created"; |
41 | 0 | protected static final String RT_UPDATED = "_runtimeData" + QueryPath.getPathSeparator() + "updated"; |
42 | 0 | protected static final String RT_DELETED = "_runtimeData" + QueryPath.getPathSeparator() + "deleted"; |
43 | |
|
44 | 0 | private MultiplicityItemBinding() {}; |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
@Override |
51 | |
public void setModelValue(MultiplicityItem multiplicityItem, DataModel model, String path) { |
52 | |
|
53 | 0 | String itemPath = path + QueryPath.getPathSeparator() + multiplicityItem.getItemKey(); |
54 | 0 | String mutiRuntimePath = itemPath; |
55 | 0 | Widget widget = multiplicityItem.getItemWidget(); |
56 | 0 | if (widget instanceof Section) { |
57 | 0 | itemPath = ""; |
58 | 0 | SectionBinding.INSTANCE.setModelValue((Section) widget, model, itemPath); |
59 | 0 | } else if (widget instanceof ModelWidgetBinding) { |
60 | 0 | ((ModelWidgetBinding) widget).setModelValue(widget, model, path); |
61 | |
} else { |
62 | 0 | GWT.log(itemPath + " has no widget binding.", null); |
63 | |
} |
64 | |
|
65 | |
|
66 | |
QueryPath qPath; |
67 | 0 | if (multiplicityItem.isCreated()) { |
68 | 0 | qPath = QueryPath.parse(mutiRuntimePath + QueryPath.getPathSeparator() + RT_CREATED); |
69 | 0 | } else if (multiplicityItem.isDeleted()) { |
70 | 0 | qPath = QueryPath.parse(mutiRuntimePath + QueryPath.getPathSeparator() + RT_DELETED); |
71 | |
} else { |
72 | 0 | qPath = QueryPath.parse(mutiRuntimePath + QueryPath.getPathSeparator() + RT_UPDATED); |
73 | |
} |
74 | |
try { |
75 | 0 | Boolean oldValue = model.get(qPath); |
76 | 0 | Boolean newValue = true; |
77 | 0 | if (!nullsafeEquals(oldValue, newValue)) { |
78 | 0 | model.set(qPath, newValue); |
79 | 0 | setDirtyFlag(model, qPath); |
80 | |
} |
81 | 0 | } catch (java.lang.IllegalArgumentException e) { |
82 | |
|
83 | 0 | GWT.log("Warning: Ignoring error attempting to setValue for " + widget.getClass().getName() + " path: " + qPath, e); |
84 | 0 | } |
85 | |
|
86 | 0 | } |
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
@Override |
93 | |
public void setWidgetValue(MultiplicityItem multiplicityItem, DataModel model, String path) { |
94 | |
|
95 | 0 | String itemPath =""; |
96 | 0 | Widget widget = multiplicityItem.getItemWidget(); |
97 | 0 | if (widget instanceof Section) { |
98 | 0 | SectionBinding.INSTANCE.setWidgetValue((Section) widget, model, itemPath); |
99 | 0 | } else if (widget instanceof ModelWidgetBinding) { |
100 | 0 | ((ModelWidgetBinding) widget).setWidgetValue(widget, model, path); |
101 | |
} else { |
102 | 0 | GWT.log(itemPath + " has no widget binding.", null); |
103 | |
} |
104 | |
|
105 | 0 | multiplicityItem.setCreated(false); |
106 | 0 | multiplicityItem.setCreated(false); |
107 | 0 | } |
108 | |
|
109 | |
|
110 | |
} |