001/**
002 * Copyright 2005-2016 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;
022
023/**
024 * Represents a HTML TextArea control. Generally used for values that are very
025 * large (such as a description)
026 *
027 * @author Kuali Rice Team (rice.collab@kuali.org)
028 */
029public class TextAreaControl extends ControlBase {
030    private static final long serialVersionUID = -4664558047325456844L;
031
032    private int rows;
033    private int cols;
034    private Integer maxLength;
035    private Integer minLength;
036
037    private boolean textExpand;
038    private String watermarkText = StringUtils.EMPTY;
039
040    public TextAreaControl() {
041        super();
042    }
043
044    /**
045     * The following actions are performed:
046     *
047     * <ul>
048     * <li>Defaults maxLength, minLength (if not set) to maxLength of parent field</li>
049     * </ul>
050     *
051     * @see org.kuali.rice.krad.uif.component.ComponentBase#performFinalize(org.kuali.rice.krad.uif.view.View,
052     *      java.lang.Object, org.kuali.rice.krad.uif.component.Component)
053     */
054    @Override
055    public void performFinalize(View view, Object model, Component parent) {
056        super.performFinalize(view, model, parent);
057
058        if (parent instanceof InputField) {
059            InputField field = (InputField) parent;
060            if (getMaxLength() == null) {
061                setMaxLength(field.getMaxLength());
062            }
063
064            if (getMinLength() == null) {
065                setMinLength(field.getMinLength());
066            }
067        }
068    }
069
070    /**
071     * Number of rows the control should span (horizontal length)
072     *
073     * @return int number of rows
074     */
075    public int getRows() {
076        return this.rows;
077    }
078
079    public void setRows(int rows) {
080        this.rows = rows;
081    }
082
083    /**
084     * Number of columns the control should span (vertical length)
085     *
086     * @return int number of columns
087     */
088    public int getCols() {
089        return this.cols;
090    }
091
092    public void setCols(int cols) {
093        this.cols = cols;
094    }
095
096    /**
097     * Maximum number of characters that can be inputted
098     *
099     * <p>If not set on control, max length of field will be used</p>
100     *
101     * @return int max number of characters
102     */
103    public Integer getMaxLength() {
104        return maxLength;
105    }
106
107    /**
108     * Setter for the max number of input characters
109     *
110     * @param maxLength
111     */
112    public void setMaxLength(Integer maxLength) {
113        this.maxLength = maxLength;
114    }
115
116    /**
117     * Minimum number of characters that can be inputted
118     *
119     * <p>If not set on control, min length of field will be used</p>
120     *
121     * @return int max number of characters
122     */
123    public Integer getMinLength() {
124        return minLength;
125    }
126
127    /**
128     * Setter for the min number of input characters
129     *
130     * @param minLength
131     */
132    public void setMinLength(Integer minLength) {
133        this.minLength = minLength;
134    }
135
136    /**
137     * @return the watermarkText
138     */
139    public String getWatermarkText() {
140        return this.watermarkText;
141    }
142
143    /**
144     * @param watermarkText the watermarkText to set
145     */
146    public void setWatermarkText(String watermarkText) {
147        //to avoid users from putting in the same value as the watermark adding some spaces here
148        //see watermark troubleshooting for more info
149        if (StringUtils.isNotEmpty(watermarkText)) {
150            watermarkText = watermarkText + "   ";
151        }
152        this.watermarkText = watermarkText;
153    }
154
155    /**
156     * If set to true, this control will have a button which can be clicked to expand the text area through
157     * a popup window so the user has more space to type and see the data they are entering in this text field
158     *
159     * @return the textExpand
160     */
161    public boolean isTextExpand() {
162        return this.textExpand;
163    }
164
165    /**
166     * Setter for the text expand flag
167     *
168     * @param textExpand the textExpand to set
169     */
170    public void setTextExpand(boolean textExpand) {
171        this.textExpand = textExpand;
172    }
173
174
175}