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