Coverage Report - org.kuali.student.common.ui.client.configurable.mvc.binding.HasValueBinding
 
Classes in this File Line Coverage Branch Coverage Complexity
HasValueBinding
0%
0/43
0%
0/32
6.667
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 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  
  * Model widget binding for HasValue widgets.  HasValue widgets can return any object type, so the
 30  
  * to from translated is done with known/expected types for KS.
 31  
  * @author Kuali Student Team
 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  
         // TODO: Type checking to ensure that the value type of widget matches model defintion
 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  
 }