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