001/** 002 * Copyright 2005-2018 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.uif.control; 017 018import org.apache.commons.lang.StringUtils; 019import org.kuali.rice.krad.datadictionary.parse.BeanTag; 020import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute; 021import org.kuali.rice.krad.datadictionary.parse.BeanTags; 022import org.kuali.rice.krad.uif.component.Component; 023import org.kuali.rice.krad.uif.field.InputField; 024import org.kuali.rice.krad.uif.util.LifecycleElement; 025import org.kuali.rice.krad.uif.widget.DatePicker; 026 027/** 028 * Represents a HTML Text control, generally rendered as a input field of type 029 * 'text'. This can display and receive a single value 030 * 031 * @author Kuali Rice Team (rice.collab@kuali.org) 032 */ 033@BeanTags({@BeanTag(name = "textControl", parent = "Uif-TextControl"), 034 @BeanTag(name = "smallTextControl", parent = "Uif-SmallTextControl"), 035 @BeanTag(name = "mediumTextControl", parent = "Uif-MediumTextControl"), 036 @BeanTag(name = "largeTextControl", parent = "Uif-LargeTextControl"), 037 @BeanTag(name = "currencyTextControl", parent = "Uif-CurrencyTextControl"), 038 @BeanTag(name = "dateControl", parent = "Uif-DateControl")}) 039public class TextControlBase extends ControlBase implements TextControl, SizedControl { 040 private static final long serialVersionUID = -8267606288443759880L; 041 042 private int size; 043 private Integer maxLength; 044 private Integer minLength; 045 046 private DatePicker datePicker; 047 private String watermarkText = StringUtils.EMPTY; 048 private boolean textExpand; 049 050 public TextControlBase() { 051 super(); 052 } 053 054 /** 055 * The following actions are performed: 056 * 057 * <ul> 058 * <li>Defaults maxLength, minLength (if not set) to maxLength of parent field</li> 059 * </ul> 060 * 061 * {@inheritDoc} 062 */ 063 @Override 064 public void performFinalize(Object model, LifecycleElement parent) { 065 super.performFinalize(model, parent); 066 067 if (parent instanceof InputField) { 068 InputField field = (InputField) parent; 069 if (getMaxLength() == null) { 070 setMaxLength(field.getMaxLength()); 071 } 072 073 if (getMinLength() == null) { 074 setMinLength(field.getMinLength()); 075 } 076 077 if (textExpand || (datePicker != null && datePicker.isRender())) { 078 field.setRenderInputAddonGroup(true); 079 } 080 } 081 } 082 083 /** 084 * {@inheritDoc} 085 */ 086 @Override 087 @BeanTagAttribute 088 public int getSize() { 089 return this.size; 090 } 091 092 /** 093 * @see TextControlBase#getSize() 094 */ 095 @Override 096 public void setSize(int size) { 097 this.size = size; 098 } 099 100 /** 101 * {@inheritDoc} 102 */ 103 @Override 104 @BeanTagAttribute 105 public Integer getMaxLength() { 106 return maxLength; 107 } 108 109 /** 110 * @see TextControlBase#getMaxLength() 111 */ 112 @Override 113 public void setMaxLength(Integer maxLength) { 114 this.maxLength = maxLength; 115 } 116 117 /** 118 * {@inheritDoc} 119 */ 120 @Override 121 @BeanTagAttribute 122 public Integer getMinLength() { 123 return minLength; 124 } 125 126 /** 127 * @see TextControlBase#getMinLength() 128 */ 129 @Override 130 public void setMinLength(Integer minLength) { 131 this.minLength = minLength; 132 } 133 134 /** 135 * {@inheritDoc} 136 */ 137 @Override 138 @BeanTagAttribute(type = BeanTagAttribute.AttributeType.DIRECTORBYTYPE) 139 public DatePicker getDatePicker() { 140 return this.datePicker; 141 } 142 143 /** 144 * @see TextControlBase#getDatePicker() 145 */ 146 @Override 147 public void setDatePicker(DatePicker datePicker) { 148 this.datePicker = datePicker; 149 } 150 151 /** 152 * {@inheritDoc} 153 */ 154 @Override 155 @BeanTagAttribute 156 public boolean isTextExpand() { 157 return this.textExpand; 158 } 159 160 /** 161 * @see TextControlBase#isTextExpand() 162 */ 163 @Override 164 public void setTextExpand(boolean textExpand) { 165 this.textExpand = textExpand; 166 } 167 168 /** 169 * {@inheritDoc} 170 */ 171 @Override 172 @BeanTagAttribute(name = "watermarkText") 173 public String getWatermarkText() { 174 return this.watermarkText; 175 } 176 177 /** 178 * @see TextControlBase#getWatermarkText() 179 */ 180 @Override 181 public void setWatermarkText(String watermarkText) { 182 //to avoid users from putting in the same value as the watermark adding some spaces here 183 //see watermark troubleshooting for more info 184 if (StringUtils.isNotEmpty(watermarkText)) { 185 watermarkText = watermarkText + " "; 186 } 187 188 this.watermarkText = watermarkText; 189 } 190}