Coverage Report - org.kuali.rice.krad.uif.modifier.LabelFieldSeparateModifier
 
Classes in this File Line Coverage Branch Coverage Complexity
LabelFieldSeparateModifier
0%
0/29
0%
0/24
5.667
 
 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.modifier;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.krad.uif.container.Group;
 20  
 import org.kuali.rice.krad.uif.view.View;
 21  
 import org.kuali.rice.krad.uif.component.Component;
 22  
 import org.kuali.rice.krad.uif.field.Field;
 23  
 
 24  
 import java.util.ArrayList;
 25  
 import java.util.HashSet;
 26  
 import java.util.List;
 27  
 import java.util.Set;
 28  
 
 29  
 /**
 30  
  * Pulls <code>LabelField</code> instances out of a contained field so they will
 31  
  * be placed separately in the <code>LayoutManager</code>
 32  
  * 
 33  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 34  
  */
 35  
 public class LabelFieldSeparateModifier extends ComponentModifierBase {
 36  
         private static final long serialVersionUID = -4304947796868636298L;
 37  
 
 38  
         public LabelFieldSeparateModifier() {
 39  0
                 super();
 40  0
         }
 41  
 
 42  
         /**
 43  
          * Iterates through the <code>Group</code> items and if the label field is
 44  
          * not null and should be rendered, adds it to the new field list
 45  
          * immediately before the <code>Field</code> item the label applies to.
 46  
          * Finally the new list of components is set on the group
 47  
          * 
 48  
          * @see org.kuali.rice.krad.uif.modifier.ComponentModifier#performModification(org.kuali.rice.krad.uif.view.View,
 49  
          *      java.lang.Object, org.kuali.rice.krad.uif.component.Component)
 50  
          */
 51  
         @Override
 52  
         public void performModification(View view, Object model, Component component) {
 53  0
                 if ((component != null) && !(component instanceof Group)) {
 54  0
                         throw new IllegalArgumentException("Compare field initializer only support Group components, found type: "
 55  
                                         + component.getClass());
 56  
                 }
 57  
 
 58  0
                 if (component == null) {
 59  0
                         return;
 60  
                 }
 61  
 
 62  
                 // list that will be built
 63  0
                 List<Component> groupFields = new ArrayList<Component>();
 64  
 
 65  0
                 Group group = (Group) component;
 66  0
                 for (Component item : group.getItems()) {
 67  0
                         if (item instanceof Field) {
 68  0
                                 Field field = (Field) item;
 69  
 
 70  
                                 // pull out label field
 71  0
                                 if (field.getLabelField() != null && field.getLabelField().isRender()) {
 72  0
                                     field.getLabelField().addStyleClass("displayWith-" + field.getFactoryId());
 73  0
                     if (!field.isRender() && StringUtils.isBlank(field.getProgressiveRender())) {
 74  0
                        field.getLabelField().setRender(false);
 75  
                     }
 76  0
                     else if(!field.isRender() && StringUtils.isNotBlank(field.getProgressiveRender())){
 77  0
                        field.getLabelField().setRender(true);
 78  0
                        String prefixStyle = "";
 79  0
                        if(StringUtils.isNotBlank(field.getLabelField().getStyle())){
 80  0
                            prefixStyle = field.getLabelField().getStyle();
 81  
                        }
 82  0
                        field.getLabelField().setStyle(prefixStyle + ";" + "display: none;");
 83  
                     }
 84  
 
 85  0
                                         groupFields.add(field.getLabelField());
 86  
 
 87  
                                         // set boolean to indicate label field should not be
 88  
                                         // rendered with the attribute
 89  0
                                         field.setLabelFieldRendered(true);
 90  
                                 }
 91  
                         }
 92  
 
 93  0
                         groupFields.add(item);
 94  
                 }
 95  
 
 96  
                 // update group
 97  0
                 group.setItems(groupFields);
 98  0
         }
 99  
 
 100  
         /**
 101  
          * @see org.kuali.rice.krad.uif.modifier.ComponentModifier#getSupportedComponents()
 102  
          */
 103  
         @Override
 104  
         public Set<Class<? extends Component>> getSupportedComponents() {
 105  0
                 Set<Class<? extends Component>> components = new HashSet<Class<? extends Component>>();
 106  0
                 components.add(Group.class);
 107  
 
 108  0
                 return components;
 109  
         }
 110  
 
 111  
 }