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.Date; |
19 | |
|
20 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
21 | |
import org.kuali.student.common.ui.client.widgets.KSCheckBox; |
22 | |
import org.kuali.student.core.assembly.data.Data; |
23 | |
import org.kuali.student.core.assembly.data.QueryPath; |
24 | |
|
25 | |
import com.google.gwt.core.client.GWT; |
26 | |
import com.google.gwt.user.client.ui.HasValue; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | 0 | public class HasValueBinding extends ModelWidgetBindingSupport<HasValue> { |
35 | |
|
36 | 0 | public static HasValueBinding INSTANCE = new HasValueBinding(); |
37 | |
|
38 | 0 | private HasValueBinding() {} |
39 | |
|
40 | |
@Override |
41 | |
public void setModelValue(HasValue object, DataModel model, String path) { |
42 | 0 | QueryPath qPath = QueryPath.parse(path); |
43 | 0 | Object value = object.getValue(); |
44 | 0 | if (!nullsafeEquals(model.get(qPath), value)) { |
45 | 0 | setDirtyFlag(model, qPath); |
46 | |
} |
47 | |
|
48 | 0 | if (value instanceof String) { |
49 | 0 | model.set(qPath, (String) value); |
50 | 0 | } else if (value instanceof Character) { |
51 | 0 | model.set(qPath, value.toString()); |
52 | 0 | } else if (value instanceof Integer) { |
53 | 0 | model.set(qPath, (Integer) value); |
54 | 0 | } else if (value instanceof Long) { |
55 | 0 | model.set(qPath, (Long) value); |
56 | 0 | } else if (value instanceof Float) { |
57 | 0 | model.set(qPath, (Float) value); |
58 | 0 | } else if (value instanceof Double) { |
59 | 0 | model.set(qPath, (Double) value); |
60 | 0 | } else if (value instanceof Byte) { |
61 | 0 | model.set(qPath, ((Byte) value).intValue()); |
62 | 0 | } else if (value instanceof Boolean) { |
63 | 0 | model.set(qPath, (Boolean) value); |
64 | 0 | } else if (value instanceof Date) { |
65 | 0 | model.set(qPath, (Date) value); |
66 | 0 | } else if (value instanceof Data.Value){ |
67 | 0 | model.set(qPath, (Data.Value) value); |
68 | 0 | } else if (value == null){ |
69 | 0 | String s = null; |
70 | 0 | model.set(qPath, s); |
71 | |
} |
72 | |
|
73 | 0 | } |
74 | |
|
75 | |
@Override |
76 | |
public void setWidgetValue(HasValue object, DataModel model, String path) { |
77 | 0 | QueryPath qPath = QueryPath.parse(path); |
78 | 0 | Object value = model.get(qPath); |
79 | |
|
80 | 0 | if (value != null && object != null) { |
81 | 0 | object.setValue(value); |
82 | 0 | } else if (object != null) { |
83 | |
try { |
84 | 0 | if (object instanceof KSCheckBox) { |
85 | 0 | object.setValue(false); |
86 | |
} else { |
87 | 0 | object.setValue(""); |
88 | |
} |
89 | 0 | } catch (RuntimeException e) { |
90 | 0 | GWT.log("Warning: Ignoring error attempting to setValue for " + object.getClass().getName(), e); |
91 | 0 | } |
92 | |
} |
93 | 0 | } |
94 | |
|
95 | |
} |