Coverage Report - org.kuali.student.common.ui.client.configurable.mvc.binding.MultiplicityItemBinding
 
Classes in this File Line Coverage Branch Coverage Complexity
MultiplicityItemBinding
0%
0/39
0%
0/14
3.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 org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityItem;
 19  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.Section;
 20  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.SectionBinding;
 21  
 import org.kuali.student.common.ui.client.mvc.DataModel;
 22  
 import org.kuali.student.core.assembly.data.QueryPath;
 23  
 
 24  
 import com.google.gwt.core.client.GWT;
 25  
 import com.google.gwt.user.client.ui.Widget;
 26  
 
 27  
 /**
 28  
  * This binding simply adds an index key to the multiplicity item's parent path and then calls the binding ModelWidgetBinding
 29  
  * of the underlying multiplicity item's widget.
 30  
  * 
 31  
  * @author Kuali Student Team
 32  
  */
 33  
 
 34  
 /**
 35  
  * @deprecated
 36  
  */
 37  0
 public class MultiplicityItemBinding extends ModelWidgetBindingSupport<MultiplicityItem> {
 38  0
     public static MultiplicityItemBinding INSTANCE = new MultiplicityItemBinding();
 39  
 
 40  0
     protected static final String RT_CREATED = "_runtimeData" + QueryPath.getPathSeparator() + "created";
 41  0
     protected static final String RT_UPDATED = "_runtimeData" + QueryPath.getPathSeparator() + "updated";
 42  0
     protected static final String RT_DELETED = "_runtimeData" + QueryPath.getPathSeparator() + "deleted";
 43  
 
 44  0
     private MultiplicityItemBinding() {};
 45  
 
 46  
     /**
 47  
      * @see org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBindingSupport#setModelValue(java.lang.Object,
 48  
      *      org.kuali.student.common.ui.client.mvc.DataModel, java.lang.String)
 49  
      */
 50  
     @Override
 51  
     public void setModelValue(MultiplicityItem multiplicityItem, DataModel model, String path) {
 52  
         // TODO modify this method to use QueryPath.add to build paths, rather than string manipulation
 53  0
         String itemPath = path + QueryPath.getPathSeparator() + multiplicityItem.getItemKey();
 54  0
             String mutiRuntimePath = itemPath;
 55  0
         Widget widget = multiplicityItem.getItemWidget();
 56  0
         if (widget instanceof Section) {
 57  0
                 itemPath = "";
 58  0
             SectionBinding.INSTANCE.setModelValue((Section) widget, model, itemPath);
 59  0
         } else if (widget instanceof ModelWidgetBinding) {
 60  0
             ((ModelWidgetBinding) widget).setModelValue(widget, model, path);
 61  
         } else {
 62  0
             GWT.log(itemPath + " has no widget binding.", null);
 63  
         }
 64  
 
 65  
         // Multiplicity metadata?
 66  
        QueryPath qPath;
 67  0
         if (multiplicityItem.isCreated()) {
 68  0
             qPath = QueryPath.parse(mutiRuntimePath + QueryPath.getPathSeparator() + RT_CREATED);
 69  0
         } else if (multiplicityItem.isDeleted()) {
 70  0
             qPath = QueryPath.parse(mutiRuntimePath + QueryPath.getPathSeparator() + RT_DELETED);
 71  
         } else {
 72  0
             qPath = QueryPath.parse(mutiRuntimePath + QueryPath.getPathSeparator() + RT_UPDATED);
 73  
         }
 74  
         try {
 75  0
             Boolean oldValue = model.get(qPath);
 76  0
             Boolean newValue = true;
 77  0
             if (!nullsafeEquals(oldValue, newValue)) {
 78  0
                 model.set(qPath, newValue);
 79  0
                 setDirtyFlag(model, qPath);
 80  
             }
 81  0
         } catch (java.lang.IllegalArgumentException e) {
 82  
             // model.get(qPath) will throw this exception if there is no such path
 83  0
             GWT.log("Warning: Ignoring error attempting to setValue for " + widget.getClass().getName() + " path: " + qPath, e);
 84  0
         }
 85  
 
 86  0
     }
 87  
 
 88  
     /**
 89  
      * @see org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBindingSupport#setWidgetValue(java.lang.Object,
 90  
      *      org.kuali.student.common.ui.client.mvc.DataModel, java.lang.String)
 91  
      */
 92  
     @Override
 93  
     public void setWidgetValue(MultiplicityItem multiplicityItem, DataModel model, String path) {
 94  
 //        String itemPath = path + QueryPath.getPathSeparator() + multiplicityItem.getItemKey();
 95  0
         String itemPath ="";
 96  0
         Widget widget = multiplicityItem.getItemWidget();
 97  0
         if (widget instanceof Section) {
 98  0
             SectionBinding.INSTANCE.setWidgetValue((Section) widget, model, itemPath);
 99  0
         } else if (widget instanceof ModelWidgetBinding) {
 100  0
             ((ModelWidgetBinding) widget).setWidgetValue(widget, model, path);
 101  
         } else {
 102  0
             GWT.log(itemPath + " has no widget binding.", null);
 103  
         }
 104  
 
 105  0
         multiplicityItem.setCreated(false);
 106  0
         multiplicityItem.setCreated(false);
 107  0
     }
 108  
     
 109  
     
 110  
 }