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