Coverage Report - org.kuali.rice.kns.uif.field.FieldBase
 
Classes in this File Line Coverage Branch Coverage Complexity
FieldBase
0%
0/41
0%
0/14
1.5
 
 1  
 /*
 2  
  * Copyright 2007 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.field;
 17  
 
 18  
 import java.util.List;
 19  
 
 20  
 import org.apache.commons.lang.StringUtils;
 21  
 import org.kuali.rice.kns.uif.UifConstants.Position;
 22  
 import org.kuali.rice.kns.uif.container.View;
 23  
 import org.kuali.rice.kns.uif.core.Component;
 24  
 import org.kuali.rice.kns.uif.core.ComponentBase;
 25  
 
 26  
 /**
 27  
  * Base class for <code>Field</code> implementations
 28  
  * 
 29  
  * <p>
 30  
  * Sets the component type name so that all field templates have a fixed
 31  
  * contract
 32  
  * </p>
 33  
  * 
 34  
  * <p>
 35  
  * Holds a nested <code>LabelField</code> with configuration for rendering the
 36  
  * label and configuration on label placement.
 37  
  * </p>
 38  
  * 
 39  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 40  
  */
 41  
 public class FieldBase extends ComponentBase implements Field {
 42  
         private static final long serialVersionUID = -5888414844802862760L;
 43  
 
 44  
         private String shortLabel;
 45  
 
 46  
         private LabelField labelField;
 47  
 
 48  
         private String labelPlacement;
 49  
         private boolean labelFieldRendered;
 50  
 
 51  0
         public FieldBase() {
 52  0
                 labelFieldRendered = false;
 53  
 
 54  0
                 labelPlacement = Position.LEFT;
 55  0
         }
 56  
 
 57  
         /**
 58  
          * The following initialization is performed:
 59  
          * 
 60  
          * <ul>
 61  
          * </ul>
 62  
          * 
 63  
          * @see org.kuali.rice.kns.uif.core.ComponentBase#performInitialization(org.kuali.rice.kns.uif.container.View)
 64  
          */
 65  
         @Override
 66  
         public void performInitialization(View view) {
 67  0
                 super.performInitialization(view);
 68  0
         }
 69  
 
 70  
         /**
 71  
          * The following finalization is performed:
 72  
          * 
 73  
          * <ul>
 74  
          * <li>Set the labelForComponentId to this component id</li>
 75  
          * <li>Set the label text on the label field from the field's label property
 76  
          * </li>
 77  
          * <li>Set the render property on the label's required message field if this
 78  
          * field is marked as required</li>
 79  
          * <li>If label placement is right, set render colon to false</li>
 80  
          * </ul>
 81  
          * 
 82  
          * @see org.kuali.rice.kns.uif.core.ComponentBase#performFinalize(org.kuali.rice.kns.uif.container.View,
 83  
          *      java.lang.Object, org.kuali.rice.kns.uif.core.Component)
 84  
          */
 85  
         @Override
 86  
         public void performFinalize(View view, Object model, Component parent) {
 87  0
                 super.performFinalize(view, model, parent);
 88  
 
 89  0
                 if (labelField != null) {
 90  0
                         labelField.setLabelForComponentId(this.getId());
 91  
 
 92  0
                         if ((getRequired() != null) && getRequired().booleanValue()) {
 93  0
                                 labelField.getRequiredMessageField().setRender(true);
 94  
                         }
 95  
                         else {
 96  0
                                 setRequired(new Boolean(false));
 97  0
                                 labelField.getRequiredMessageField().setRender(false);
 98  
                         }
 99  
 
 100  0
                         if (StringUtils.equals(labelPlacement, Position.RIGHT)) {
 101  0
                                 labelField.setRenderColon(false);
 102  
                         }
 103  
                 }
 104  0
         }
 105  
 
 106  
         /**
 107  
          * @see org.kuali.rice.kns.uif.core.Component#getComponentTypeName()
 108  
          */
 109  
         @Override
 110  
         public final String getComponentTypeName() {
 111  0
                 return "field";
 112  
         }
 113  
 
 114  
         /**
 115  
          * @see org.kuali.rice.kns.uif.core.ComponentBase#getNestedComponents()
 116  
          */
 117  
         @Override
 118  
         public List<Component> getNestedComponents() {
 119  0
                 List<Component> components = super.getNestedComponents();
 120  
 
 121  0
                 components.add(labelField);
 122  
 
 123  0
                 return components;
 124  
         }
 125  
 
 126  
         /**
 127  
          * @see org.kuali.rice.kns.uif.field.Field#getLabel()
 128  
          */
 129  
         public String getLabel() {
 130  0
                 if (labelField != null) {
 131  0
                         return labelField.getLabelText();
 132  
                 }
 133  
 
 134  0
                 return null;
 135  
         }
 136  
 
 137  
         /**
 138  
          * @see org.kuali.rice.kns.uif.field.Field#setLabel(java.lang.String)
 139  
          */
 140  
         public void setLabel(String label) {
 141  0
                 if (labelField != null) {
 142  0
                         labelField.setLabelText(label);
 143  
                 }
 144  0
         }
 145  
 
 146  
         /**
 147  
          * @see org.kuali.rice.kns.uif.field.Field#getShortLabel()
 148  
          */
 149  
         public String getShortLabel() {
 150  0
                 return this.shortLabel;
 151  
         }
 152  
 
 153  
         /**
 154  
          * @see org.kuali.rice.kns.uif.field.Field#setShortLabel(java.lang.String)
 155  
          */
 156  
         public void setShortLabel(String shortLabel) {
 157  0
                 this.shortLabel = shortLabel;
 158  0
         }
 159  
 
 160  
         /**
 161  
          * Sets whether the label should be displayed
 162  
          * 
 163  
          * <p>
 164  
          * Convenience method for configuration that sets the render indicator on
 165  
          * the fields <code>LabelField</code> instance
 166  
          * </p>
 167  
          * 
 168  
          * @param showLabel
 169  
          *            boolean true if label should be displayed, false if the label
 170  
          *            should not be displayed
 171  
          */
 172  
         public void setShowLabel(boolean showLabel) {
 173  0
                 if (labelField != null) {
 174  0
                         labelField.setRender(showLabel);
 175  
                 }
 176  0
         }
 177  
 
 178  
         /**
 179  
          * @see org.kuali.rice.kns.uif.field.Field#getLabelField()
 180  
          */
 181  
         public LabelField getLabelField() {
 182  0
                 return this.labelField;
 183  
         }
 184  
 
 185  
         /**
 186  
          * @see org.kuali.rice.kns.uif.field.Field#setLabelField(org.kuali.rice.kns.uif.field.LabelField)
 187  
          */
 188  
         public void setLabelField(LabelField labelField) {
 189  0
                 this.labelField = labelField;
 190  0
         }
 191  
 
 192  
         public String getLabelPlacement() {
 193  0
                 return this.labelPlacement;
 194  
         }
 195  
 
 196  
         public void setLabelPlacement(String labelPlacement) {
 197  0
                 this.labelPlacement = labelPlacement;
 198  0
         }
 199  
 
 200  
         /**
 201  
          * @see org.kuali.rice.kns.uif.field.Field#isLabelFieldRendered()
 202  
          */
 203  
         public boolean isLabelFieldRendered() {
 204  0
                 return this.labelFieldRendered;
 205  
         }
 206  
 
 207  
         /**
 208  
          * @see org.kuali.rice.kns.uif.field.Field#setLabelFieldRendered(boolean)
 209  
          */
 210  
         public void setLabelFieldRendered(boolean labelFieldRendered) {
 211  0
                 this.labelFieldRendered = labelFieldRendered;
 212  0
         }
 213  
 
 214  
 }