Coverage Report - org.kuali.rice.kns.uif.field.FieldBase
 
Classes in this File Line Coverage Branch Coverage Complexity
FieldBase
0%
0/45
0%
0/16
1.562
 
 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(true);
 98  0
                                 String prefixStyle = "";
 99  0
                                 if(StringUtils.isNotBlank(labelField.getRequiredMessageField().getStyle())){
 100  0
                     prefixStyle = labelField.getRequiredMessageField().getStyle();
 101  
                 }
 102  0
                                 labelField.getRequiredMessageField().setStyle(prefixStyle + ";" + "display: none;");
 103  
                         }
 104  
 
 105  0
                         if (StringUtils.equals(labelPlacement, Position.RIGHT)) {
 106  0
                                 labelField.setRenderColon(false);
 107  
                         }
 108  
                 }
 109  0
         }
 110  
 
 111  
         /**
 112  
          * @see org.kuali.rice.kns.uif.core.Component#getComponentTypeName()
 113  
          */
 114  
         @Override
 115  
         public final String getComponentTypeName() {
 116  0
                 return "field";
 117  
         }
 118  
 
 119  
         /**
 120  
          * @see org.kuali.rice.kns.uif.core.ComponentBase#getNestedComponents()
 121  
          */
 122  
         @Override
 123  
         public List<Component> getNestedComponents() {
 124  0
                 List<Component> components = super.getNestedComponents();
 125  
 
 126  0
                 components.add(labelField);
 127  
 
 128  0
                 return components;
 129  
         }
 130  
 
 131  
         /**
 132  
          * @see org.kuali.rice.kns.uif.field.Field#getLabel()
 133  
          */
 134  
         public String getLabel() {
 135  0
                 if (labelField != null) {
 136  0
                         return labelField.getLabelText();
 137  
                 }
 138  
 
 139  0
                 return null;
 140  
         }
 141  
 
 142  
         /**
 143  
          * @see org.kuali.rice.kns.uif.field.Field#setLabel(java.lang.String)
 144  
          */
 145  
         public void setLabel(String label) {
 146  0
                 if (labelField != null) {
 147  0
                         labelField.setLabelText(label);
 148  
                 }
 149  0
         }
 150  
 
 151  
         /**
 152  
          * @see org.kuali.rice.kns.uif.field.Field#getShortLabel()
 153  
          */
 154  
         public String getShortLabel() {
 155  0
                 return this.shortLabel;
 156  
         }
 157  
 
 158  
         /**
 159  
          * @see org.kuali.rice.kns.uif.field.Field#setShortLabel(java.lang.String)
 160  
          */
 161  
         public void setShortLabel(String shortLabel) {
 162  0
                 this.shortLabel = shortLabel;
 163  0
         }
 164  
 
 165  
         /**
 166  
          * Sets whether the label should be displayed
 167  
          * 
 168  
          * <p>
 169  
          * Convenience method for configuration that sets the render indicator on
 170  
          * the fields <code>LabelField</code> instance
 171  
          * </p>
 172  
          * 
 173  
          * @param showLabel
 174  
          *            boolean true if label should be displayed, false if the label
 175  
          *            should not be displayed
 176  
          */
 177  
         public void setShowLabel(boolean showLabel) {
 178  0
                 if (labelField != null) {
 179  0
                         labelField.setRender(showLabel);
 180  
                 }
 181  0
         }
 182  
 
 183  
         /**
 184  
          * @see org.kuali.rice.kns.uif.field.Field#getLabelField()
 185  
          */
 186  
         public LabelField getLabelField() {
 187  0
                 return this.labelField;
 188  
         }
 189  
 
 190  
         /**
 191  
          * @see org.kuali.rice.kns.uif.field.Field#setLabelField(org.kuali.rice.kns.uif.field.LabelField)
 192  
          */
 193  
         public void setLabelField(LabelField labelField) {
 194  0
                 this.labelField = labelField;
 195  0
         }
 196  
 
 197  
         public String getLabelPlacement() {
 198  0
                 return this.labelPlacement;
 199  
         }
 200  
 
 201  
         public void setLabelPlacement(String labelPlacement) {
 202  0
                 this.labelPlacement = labelPlacement;
 203  0
         }
 204  
 
 205  
         /**
 206  
          * @see org.kuali.rice.kns.uif.field.Field#isLabelFieldRendered()
 207  
          */
 208  
         public boolean isLabelFieldRendered() {
 209  0
                 return this.labelFieldRendered;
 210  
         }
 211  
 
 212  
         /**
 213  
          * @see org.kuali.rice.kns.uif.field.Field#setLabelFieldRendered(boolean)
 214  
          */
 215  
         public void setLabelFieldRendered(boolean labelFieldRendered) {
 216  0
                 this.labelFieldRendered = labelFieldRendered;
 217  0
         }
 218  
 }