Coverage Report - org.kuali.student.common.ui.client.configurable.mvc.binding.MultiplicityCompositeBinding
 
Classes in this File Line Coverage Branch Coverage Complexity
MultiplicityCompositeBinding
0%
0/35
0%
0/20
3.75
 
 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.Iterator;
 19  
 
 20  
 import org.kuali.student.common.assembly.data.Data;
 21  
 import org.kuali.student.common.assembly.data.QueryPath;
 22  
 import org.kuali.student.common.assembly.data.Data.Property;
 23  
 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.DisplayMultiplicityComposite;
 24  
 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityComposite;
 25  
 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityItem;
 26  
 import org.kuali.student.common.ui.client.mvc.DataModel;
 27  
 
 28  
 /**
 29  
  * This just goes through each item in the multiplicity composite and calls it's binding
 30  
  * 
 31  
  * @author Kuali Student Team
 32  
  */
 33  
 
 34  
 /**
 35  
  * @deprecated
 36  
  */
 37  0
 public class MultiplicityCompositeBinding extends ModelWidgetBindingSupport<MultiplicityComposite> {
 38  0
     public static MultiplicityCompositeBinding INSTANCE = new MultiplicityCompositeBinding();
 39  
 
 40  0
     private MultiplicityCompositeBinding() {};
 41  
 
 42  
     /**
 43  
      * @see org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBindingSupport#setModelValue(java.lang.Object,
 44  
      *      org.kuali.student.common.ui.client.mvc.DataModel, java.lang.String)
 45  
      */
 46  
     @Override
 47  
     public void setModelValue(MultiplicityComposite mcWidget, DataModel model, String path) {
 48  0
         for (MultiplicityItem item : mcWidget.getItems()) {
 49  0
             MultiplicityItemBinding.INSTANCE.setModelValue(item, model, path);
 50  
         }
 51  0
         for (MultiplicityItem item : mcWidget.getRemovedItems()) {
 52  
             //Check flag to add model binding for only those elements that are either added to the DB or 
 53  
             // loading frm the DB. 
 54  0
             if(item.isCreated()==false){
 55  0
                 MultiplicityItemBinding.INSTANCE.setModelValue(item, model, path);
 56  
             }
 57  
         }
 58  0
     }
 59  
 
 60  
     /**
 61  
      * @see org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBindingSupport#setWidgetValue(java.lang.Object,
 62  
      *      org.kuali.student.common.ui.client.mvc.DataModel, java.lang.String)
 63  
      */
 64  
     @Override
 65  
     public void setWidgetValue(MultiplicityComposite mcWidget, DataModel model, String path) {
 66  0
         mcWidget.clear();
 67  
 
 68  0
         QueryPath qPath = QueryPath.parse(path);
 69  0
         Data data = null;
 70  0
         if(model!=null){
 71  0
                 data = model.get(qPath);
 72  
         }
 73  
 
 74  0
         if (data != null) {
 75  0
             Iterator<Property> itr = data.iterator();
 76  0
             while (itr.hasNext()) {
 77  0
                 Property p = (Property) itr.next();
 78  
 
 79  0
                 if (p.getKey() instanceof Integer && !isItemDeleted(model, path, (Integer)p.getKey(), mcWidget)) {                
 80  0
                     MultiplicityItem item = mcWidget.addItem();
 81  0
                     item.setCreated(false);
 82  0
                     item.setItemKey((Integer) p.getKey());
 83  0
                     MultiplicityItemBinding.INSTANCE.setWidgetValue(item, model, path);
 84  0
                 } else {
 85  0
                         mcWidget.incrementItemKey();
 86  
                 }
 87  0
             }
 88  
         }
 89  0
     }
 90  
     
 91  
     /**
 92  
      * Checks to see if an item at the given index in the multiplicity has been deleted
 93  
      * 
 94  
      * @param model
 95  
      * @param path
 96  
      * @param index
 97  
      */
 98  
     public boolean isItemDeleted(DataModel model, String path, Integer index, MultiplicityComposite mcWidget){
 99  0
             boolean isDeleted = false;
 100  
             
 101  
             // If this is a read only widget deletions aren't possible so no point checking
 102  0
             if (!(mcWidget instanceof DisplayMultiplicityComposite)) {
 103  
 
 104  0
                     QueryPath runtimeDeletedPath = QueryPath.concat(path, String.valueOf(index), MultiplicityItemBinding.RT_DELETED);
 105  
 
 106  0
                     Boolean runtimeDeleted = model.get(runtimeDeletedPath);
 107  0
                     if (runtimeDeleted != null){
 108  0
                             isDeleted = runtimeDeleted;
 109  
                     }
 110  0
                     return isDeleted;
 111  
             }
 112  
           
 113  0
             return isDeleted;
 114  
     }
 115  
 
 116  
 
 117  
 }