| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| FieldBase |
|
| 1.6875;1.688 |
| 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.view.View; | |
| 21 | import org.kuali.rice.krad.uif.component.Component; | |
| 22 | import org.kuali.rice.krad.uif.component.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 Position 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.component.ComponentBase#performInitialization(org.kuali.rice.krad.uif.view.View, java.lang.Object) | |
| 65 | */ | |
| 66 | @Override | |
| 67 | public void performInitialization(View view, Object model) { | |
| 68 | 0 | super.performInitialization(view, model); |
| 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.component.ComponentBase#performFinalize(org.kuali.rice.krad.uif.view.View, | |
| 84 | * java.lang.Object, org.kuali.rice.krad.uif.component.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 | } 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 (labelPlacement.equals(Position.RIGHT)) { |
| 106 | 0 | labelField.setRenderColon(false); |
| 107 | } | |
| 108 | } | |
| 109 | 0 | } |
| 110 | ||
| 111 | /** | |
| 112 | * @see org.kuali.rice.krad.uif.component.Component#getComponentTypeName() | |
| 113 | */ | |
| 114 | @Override | |
| 115 | public final String getComponentTypeName() { | |
| 116 | 0 | return "field"; |
| 117 | } | |
| 118 | ||
| 119 | /** | |
| 120 | * @see org.kuali.rice.krad.uif.component.ComponentBase#getComponentsForLifecycle() | |
| 121 | */ | |
| 122 | @Override | |
| 123 | public List<Component> getComponentsForLifecycle() { | |
| 124 | 0 | List<Component> components = super.getComponentsForLifecycle(); |
| 125 | ||
| 126 | 0 | components.add(labelField); |
| 127 | ||
| 128 | 0 | return components; |
| 129 | } | |
| 130 | ||
| 131 | /** | |
| 132 | * @see org.kuali.rice.krad.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.krad.uif.field.Field#setLabel(java.lang.String) | |
| 144 | */ | |
| 145 | public void setLabel(String label) { | |
| 146 | 0 | if (StringUtils.isNotBlank(label) && labelField == null) { |
| 147 | 0 | labelField = ComponentFactory.getLabelField(); |
| 148 | } | |
| 149 | ||
| 150 | 0 | if (labelField != null) { |
| 151 | 0 | labelField.setLabelText(label); |
| 152 | } | |
| 153 | 0 | } |
| 154 | ||
| 155 | /** | |
| 156 | * @see org.kuali.rice.krad.uif.field.Field#getShortLabel() | |
| 157 | */ | |
| 158 | public String getShortLabel() { | |
| 159 | 0 | return this.shortLabel; |
| 160 | } | |
| 161 | ||
| 162 | /** | |
| 163 | * @see org.kuali.rice.krad.uif.field.Field#setShortLabel(java.lang.String) | |
| 164 | */ | |
| 165 | public void setShortLabel(String shortLabel) { | |
| 166 | 0 | this.shortLabel = shortLabel; |
| 167 | 0 | } |
| 168 | ||
| 169 | /** | |
| 170 | * Sets whether the label should be displayed | |
| 171 | * | |
| 172 | * <p> | |
| 173 | * Convenience method for configuration that sets the render indicator on | |
| 174 | * the fields <code>LabelField</code> instance | |
| 175 | * </p> | |
| 176 | * | |
| 177 | * @param showLabel boolean true if label should be displayed, false if the label | |
| 178 | * should not be displayed | |
| 179 | */ | |
| 180 | public void setShowLabel(boolean showLabel) { | |
| 181 | 0 | if (labelField != null) { |
| 182 | 0 | labelField.setRender(showLabel); |
| 183 | } | |
| 184 | 0 | } |
| 185 | ||
| 186 | /** | |
| 187 | * @see org.kuali.rice.krad.uif.field.Field#getLabelField() | |
| 188 | */ | |
| 189 | public LabelField getLabelField() { | |
| 190 | 0 | return this.labelField; |
| 191 | } | |
| 192 | ||
| 193 | /** | |
| 194 | * @see org.kuali.rice.krad.uif.field.Field#setLabelField(org.kuali.rice.krad.uif.field.LabelField) | |
| 195 | */ | |
| 196 | public void setLabelField(LabelField labelField) { | |
| 197 | 0 | this.labelField = labelField; |
| 198 | 0 | } |
| 199 | ||
| 200 | /** | |
| 201 | * Indicates where the label is placed in relation to the field (valid options are | |
| 202 | * LEFT, RIGHT, BOTTOM, and TOP | |
| 203 | * | |
| 204 | * @return Position position of label | |
| 205 | */ | |
| 206 | public Position getLabelPlacement() { | |
| 207 | 0 | return this.labelPlacement; |
| 208 | } | |
| 209 | ||
| 210 | /** | |
| 211 | * Setter for the label's position in relation to the field (control if editable) | |
| 212 | * | |
| 213 | * @param labelPlacement | |
| 214 | */ | |
| 215 | public void setLabelPlacement(Position labelPlacement) { | |
| 216 | 0 | this.labelPlacement = labelPlacement; |
| 217 | 0 | } |
| 218 | ||
| 219 | /** | |
| 220 | * @see org.kuali.rice.krad.uif.field.Field#isLabelFieldRendered() | |
| 221 | */ | |
| 222 | public boolean isLabelFieldRendered() { | |
| 223 | 0 | return this.labelFieldRendered; |
| 224 | } | |
| 225 | ||
| 226 | /** | |
| 227 | * @see org.kuali.rice.krad.uif.field.Field#setLabelFieldRendered(boolean) | |
| 228 | */ | |
| 229 | public void setLabelFieldRendered(boolean labelFieldRendered) { | |
| 230 | 0 | this.labelFieldRendered = labelFieldRendered; |
| 231 | 0 | } |
| 232 | } |