001/** 002 * Copyright 2005-2015 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.uif.field.InputField; 020import org.kuali.rice.krad.uif.view.View; 021import org.kuali.rice.krad.uif.component.Component; 022import org.kuali.rice.krad.uif.widget.DatePicker; 023 024import java.util.List; 025 026/** 027 * Represents a HTML Text control, generally rendered as a input field of type 028 * 'text'. This can display and receive a single value 029 * 030 * @author Kuali Rice Team (rice.collab@kuali.org) 031 */ 032public class TextControl extends ControlBase implements SizedControl { 033 private static final long serialVersionUID = -8267606288443759880L; 034 035 private int size; 036 private Integer maxLength; 037 private Integer minLength; 038 039 private DatePicker datePicker; 040 private String watermarkText = StringUtils.EMPTY; 041 private boolean textExpand; 042 043 public TextControl() { 044 super(); 045 } 046 047 /** 048 * @see org.kuali.rice.krad.uif.component.ComponentBase#getComponentsForLifecycle() 049 */ 050 @Override 051 public List<Component> getComponentsForLifecycle() { 052 List<Component> components = super.getComponentsForLifecycle(); 053 054 components.add(datePicker); 055 056 return components; 057 } 058 059 /** 060 * The following actions are performed: 061 * 062 * <ul> 063 * <li>Defaults maxLength, minLength (if not set) to maxLength of parent field</li> 064 * </ul> 065 * 066 * @see org.kuali.rice.krad.uif.component.ComponentBase#performFinalize(org.kuali.rice.krad.uif.view.View, 067 * java.lang.Object, org.kuali.rice.krad.uif.component.Component) 068 */ 069 @Override 070 public void performFinalize(View view, Object model, Component parent) { 071 super.performFinalize(view, model, parent); 072 073 if (parent instanceof InputField) { 074 InputField field = (InputField) parent; 075 if (getMaxLength() == null) { 076 setMaxLength(field.getMaxLength()); 077 } 078 079 if (getMinLength() == null) { 080 setMinLength(field.getMinLength()); 081 } 082 } 083 } 084 085 /** 086 * @see org.kuali.rice.krad.uif.control.SizedControl#getSize() 087 */ 088 public int getSize() { 089 return this.size; 090 } 091 092 /** 093 * @see org.kuali.rice.krad.uif.control.SizedControl#setSize(int) 094 */ 095 public void setSize(int size) { 096 this.size = size; 097 } 098 099 /** 100 * Maximum number of characters that can be inputted 101 * 102 * <p>If not set on control, max length of field will be used</p> 103 * 104 * @return int max number of characters 105 */ 106 public Integer getMaxLength() { 107 return maxLength; 108 } 109 110 /** 111 * Setter for the max number of input characters 112 * 113 * @param maxLength 114 */ 115 public void setMaxLength(Integer maxLength) { 116 this.maxLength = maxLength; 117 } 118 119 /** 120 * Minimum number of characters that can be inputted 121 * 122 * <p>If not set on control, min length of field will be used</p> 123 * 124 * @return int max number of characters 125 */ 126 public Integer getMinLength() { 127 return minLength; 128 } 129 130 /** 131 * Setter for the min number of input characters 132 * 133 * @param minLength 134 */ 135 public void setMinLength(Integer minLength) { 136 this.minLength = minLength; 137 } 138 139 /** 140 * Renders a calendar that can be used to select a date value for the text 141 * control. The <code>Calendar</code> instance contains configuration such 142 * as the date format string 143 * 144 * @return Calendar 145 */ 146 public DatePicker getDatePicker() { 147 return this.datePicker; 148 } 149 150 public void setDatePicker(DatePicker datePicker) { 151 this.datePicker = datePicker; 152 } 153 154 /** 155 * Gets the watermark text for this TextControl. 156 * <p> 157 * A watermark typically appears as light gray text within the text input element whenever the 158 * element is empty and does not have focus. This provides a hint to the user as to what the input 159 * is used for, or the type of input that is required. 160 * </p> 161 * @return the watermarkText 162 */ 163 public String getWatermarkText() { 164 return this.watermarkText; 165 } 166 167 /** 168 * Sets the watermark text for this TextControl 169 * @param watermarkText the watermarkText to set 170 */ 171 public void setWatermarkText(String watermarkText) { 172 //to avoid users from putting in the same value as the watermark adding some spaces here 173 //see watermark troubleshooting for more info 174 if (StringUtils.isNotEmpty(watermarkText)) { 175 watermarkText = watermarkText + " "; 176 } 177 this.watermarkText = watermarkText; 178 } 179 180 /** 181 * If set to true, this control will have a button which can be clicked to expand the text area through 182 * a popup window so the user has more space to type and see the data they are entering in this text field. 183 * 184 * @return the textExpand 185 */ 186 public boolean isTextExpand() { 187 return this.textExpand; 188 } 189 190 /** 191 * Sets whether this control will have a button to expand the text area through a popup window. 192 * @param textExpand the textExpand to set 193 */ 194 public void setTextExpand(boolean textExpand) { 195 this.textExpand = textExpand; 196 } 197 198 199}