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