Coverage Report - org.kuali.rice.krad.uif.layout.CollectionLayoutUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
CollectionLayoutUtils
0%
0/23
0%
0/10
3.5
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.krad.uif.layout;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
 20  
 import org.kuali.rice.krad.uif.UifConstants;
 21  
 import org.kuali.rice.krad.uif.UifPropertyPaths;
 22  
 import org.kuali.rice.krad.uif.component.DataBinding;
 23  
 import org.kuali.rice.krad.uif.container.CollectionGroup;
 24  
 import org.kuali.rice.krad.uif.control.Control;
 25  
 import org.kuali.rice.krad.uif.control.ValueConfiguredControl;
 26  
 import org.kuali.rice.krad.uif.field.InputField;
 27  
 import org.kuali.rice.krad.uif.field.Field;
 28  
 import org.kuali.rice.krad.util.KRADUtils;
 29  
 
 30  
 /**
 31  
  * Utilities for collection layout managers
 32  
  *
 33  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 34  
  */
 35  0
 public class CollectionLayoutUtils {
 36  
 
 37  
     public static void prepareSelectFieldForLine(Field selectField, CollectionGroup collectionGroup, String lineBindingPath,
 38  
             Object line) {
 39  
         // if select property name set use as property name for select field
 40  0
         String selectPropertyName = collectionGroup.getSelectPropertyName();
 41  0
         if (StringUtils.isNotBlank(selectPropertyName)) {
 42  
             // if select property contains form prefix, will bind to form and not each line
 43  0
             if (selectPropertyName.startsWith(UifConstants.NO_BIND_ADJUST_PREFIX)) {
 44  0
                 selectPropertyName = StringUtils.removeStart(selectPropertyName, UifConstants.NO_BIND_ADJUST_PREFIX);
 45  0
                 ((DataBinding) selectField).getBindingInfo().setBindingName(selectPropertyName);
 46  0
                 ((DataBinding) selectField).getBindingInfo().setBindToForm(true);
 47  
 
 48  0
                 setControlValueToLineIdentifier(selectField, line);
 49  
             } else {
 50  0
                 ((DataBinding) selectField).getBindingInfo().setBindingName(selectPropertyName);
 51  0
                 ((DataBinding) selectField).getBindingInfo().setBindByNamePrefix(lineBindingPath);
 52  
             }
 53  
         } else {
 54  
             // select property name not given, use UifFormBase#selectedCollectionLines
 55  0
             String collectionLineKey = KRADUtils.translateToMapSafeKey(
 56  
                     collectionGroup.getBindingInfo().getBindingPath());
 57  0
             String selectBindingPath = UifPropertyPaths.SELECTED_COLLECTION_LINES + "['" + collectionLineKey + "']";
 58  
 
 59  0
             ((DataBinding) selectField).getBindingInfo().setBindingName(selectBindingPath);
 60  0
             ((DataBinding) selectField).getBindingInfo().setBindToForm(true);
 61  
 
 62  0
             setControlValueToLineIdentifier(selectField, line);
 63  
         }
 64  0
     }
 65  
 
 66  
     protected static void setControlValueToLineIdentifier(Field selectField, Object line) {
 67  0
         if (selectField instanceof InputField) {
 68  0
             Control selectControl = ((InputField) selectField).getControl();
 69  
 
 70  0
             selectControl.addStyleClass("kr-select-line");
 71  
 
 72  0
             if ((selectControl != null) && (selectControl instanceof ValueConfiguredControl)) {
 73  0
                 String lineIdentifier =
 74  
                         KRADServiceLocatorWeb.getDataObjectMetaDataService().getDataObjectIdentifierString(line);
 75  0
                 ((ValueConfiguredControl) selectControl).setValue(lineIdentifier);
 76  
             }
 77  
         }
 78  0
     }
 79  
 }