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