Coverage Report - org.kuali.rice.krad.uif.field.LabelField
 
Classes in this File Line Coverage Branch Coverage Complexity
LabelField
0%
0/26
0%
0/2
1.077
 
 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.field;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.krad.uif.UifConstants.Position;
 20  
 import org.kuali.rice.krad.uif.component.Component;
 21  
 import org.kuali.rice.krad.uif.view.View;
 22  
 
 23  
 import java.util.List;
 24  
 
 25  
 /**
 26  
  * Contains a label for another <code>Field</code> instance
 27  
  *
 28  
  * <p>
 29  
  * The <code>LabelField</code> exists so that the label can be placed separate
 30  
  * from the component in a layout manager such as the
 31  
  * <code>GridLayoutManager</code>. It addition it can be used to style the label
 32  
  * (from the inherited styleClass and style properties)
 33  
  * </p>
 34  
  * 
 35  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 36  
  */
 37  
 public class LabelField extends FieldBase {
 38  
     private static final long serialVersionUID = -6491546893195180114L;
 39  
 
 40  
     private String labelText;
 41  
     private String labelForComponentId;
 42  
 
 43  
     private boolean renderColon;
 44  
 
 45  
     private Position requiredMessagePlacement;
 46  
     private MessageField requiredMessageField;
 47  
 
 48  0
     public LabelField() {
 49  0
         renderColon = true;
 50  
 
 51  0
         requiredMessagePlacement = Position.LEFT;
 52  0
     }
 53  
 
 54  
     /**
 55  
          * The following finalization is performed:
 56  
          *
 57  
          * <ul>
 58  
          * <li>If label text is blank, set render to false for field</li>
 59  
          *
 60  
          * @see org.kuali.rice.krad.uif.component.ComponentBase#performFinalize(org.kuali.rice.krad.uif.view.View,
 61  
          *      java.lang.Object, org.kuali.rice.krad.uif.component.Component)
 62  
          */
 63  
     @Override
 64  
     public void performFinalize(View view, Object model, Component parent) {
 65  0
         super.performFinalize(view, model, parent);
 66  
 
 67  0
         if (StringUtils.isBlank(getLabelText())) {
 68  0
             setRender(false);
 69  
         }
 70  0
     }
 71  
 
 72  
     /**
 73  
      * @see org.kuali.rice.krad.uif.component.ComponentBase#getComponentsForLifecycle()
 74  
      */
 75  
     @Override
 76  
     public List<Component> getComponentsForLifecycle() {
 77  0
         List<Component> components = super.getComponentsForLifecycle();
 78  
 
 79  0
         components.add(requiredMessageField);
 80  
 
 81  0
         return components;
 82  
     }
 83  
 
 84  
     /**
 85  
      * Indicates the id for the component the label applies to
 86  
      * <p>
 87  
      * Used for setting the labelFor attribute of the corresponding HTML
 88  
      * element. Note this gets set automatically by the framework during the
 89  
      * initialize phase
 90  
      * </p>
 91  
      * 
 92  
      * @return String component id
 93  
      */
 94  
     public String getLabelForComponentId() {
 95  0
         return this.labelForComponentId;
 96  
     }
 97  
 
 98  
     /**
 99  
      * Setter for the component id the label applies to
 100  
      * 
 101  
      * @param labelForComponentId
 102  
      */
 103  
     public void setLabelForComponentId(String labelForComponentId) {
 104  0
         this.labelForComponentId = labelForComponentId;
 105  0
     }
 106  
 
 107  
     /**
 108  
      * Text that will display as the label
 109  
      * 
 110  
      * @return String label text
 111  
      */
 112  
     public String getLabelText() {
 113  0
         return this.labelText;
 114  
     }
 115  
 
 116  
     /**
 117  
      * Setter for the label text
 118  
      * 
 119  
      * @param labelText
 120  
      */
 121  
     public void setLabelText(String labelText) {
 122  0
         this.labelText = labelText;
 123  0
     }
 124  
 
 125  
     /**
 126  
      * Indicates whether a colon should be rendered after the label text,
 127  
      * generally used when the label appears to the left of the field's control
 128  
      * or value
 129  
      * 
 130  
      * @return boolean true if a colon should be rendered, false if it should
 131  
      *         not be
 132  
      */
 133  
     public boolean isRenderColon() {
 134  0
         return this.renderColon;
 135  
     }
 136  
 
 137  
     /**
 138  
      * Setter for the render colon indicator
 139  
      * 
 140  
      * @param renderColon
 141  
      */
 142  
     public void setRenderColon(boolean renderColon) {
 143  0
         this.renderColon = renderColon;
 144  0
     }
 145  
 
 146  
     /**
 147  
      * <code>MessageField</code> instance that will display a required indicator
 148  
      * 
 149  
      * <p>
 150  
      * To indicate a field must have a value (required input) the required
 151  
      * message field can be set to display an indicator or message along with
 152  
      * the label. The message field also dictates the styling of the required
 153  
      * message
 154  
      * </p>
 155  
      * 
 156  
      * @return MessageField instance
 157  
      */
 158  
     public MessageField getRequiredMessageField() {
 159  0
         return this.requiredMessageField;
 160  
     }
 161  
 
 162  
     /**
 163  
      * Setter for the required message field
 164  
      * 
 165  
      * @param requiredMessageField
 166  
      */
 167  
     public void setRequiredMessageField(MessageField requiredMessageField) {
 168  0
         this.requiredMessageField = requiredMessageField;
 169  0
     }
 170  
 
 171  
     /**
 172  
      * Indicates where the required message field should be placed in relation
 173  
      * to the label field, valid options are 'LEFT' and 'RIGHT'
 174  
      * 
 175  
      * @return Position the requiredMessage placement
 176  
      */
 177  
     public Position getRequiredMessagePlacement() {
 178  0
         return this.requiredMessagePlacement;
 179  
     }
 180  
 
 181  
     /**
 182  
      * Setter for the required message field placement
 183  
      * 
 184  
      * @param requiredMessagePlacement
 185  
      */
 186  
     public void setRequiredMessagePlacement(Position requiredMessagePlacement) {
 187  0
         this.requiredMessagePlacement = requiredMessagePlacement;
 188  0
     }
 189  
 
 190  
 }