001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.gwt.client.ui.input;
029
030import org.opencms.gwt.client.validation.I_CmsValidator;
031
032import java.util.HashMap;
033
034/**
035 * The interface for a form field.<p>
036 *
037 * A form field consists of a widget for entering values, some metadata like a label text/description,
038 * and a set of validators for validating the field.
039 *
040 * @since 8.0.0
041 *
042 */
043public interface I_CmsFormField {
044
045    /**
046     * A simple map class containing strings to direct the layout of a form field.<p>
047     */
048    public class LayoutData extends HashMap<String, String> {
049
050        /** Serial id for serialization. */
051        private static final long serialVersionUID = -1938342399843773050L;
052        // nothing new
053    }
054
055    /**
056     * An enum which represents the validation status of a field.<p>
057     */
058    enum ValidationStatus {
059        /** The field's content is invalid. */
060        invalid, /** It is unknown whether the field's content is valid. */
061        unknown, /** The field's content is valid. */
062        valid
063    }
064
065    /**
066     * Binds a model object to the form field.<p>
067     *
068     * @param model the model object
069     */
070    void bind(I_CmsStringModel model);
071
072    /**
073     * Returns the default value for the form field.<p>
074     *
075     * @return the default value for the form field
076     */
077    Object getDefaultValue();
078
079    /**
080     * The description of the form field, or null if there is no description.<p>
081     *
082     * @return a description string or null
083     */
084    String getDescription();
085
086    /**
087     * Returns the id of this form field, or null if the form field id has not been set.
088     *
089     * If a form field without an id is added to a form, typically it will receive a synthetic id.
090     *
091     * @return the id
092     */
093    String getId();
094
095    /**
096     * The label of the form field, or null if there is no label.<p>
097     *
098     * @return a label or null
099     */
100    String getLabel();
101
102    /**
103     * Returns the layout data for this field.<p>
104     *
105     * @return the layout data for this field
106     */
107    LayoutData getLayoutData();
108
109    /**
110     * Returns the model object for this field.
111     *
112     * @return the model used for this field
113     */
114    I_CmsStringModel getModel();
115
116    /**
117     * Returns the model id.<p>
118     *
119     * @return the model id
120     */
121    String getModelId();
122
123    /**
124     * Returns the model value.<p>
125     *
126     * @return the model value
127     */
128    String getModelValue();
129
130    /**
131     * Returns the validation status of this form field.<p>
132     *
133     * If the field has no validator, this should always return <code>valid</code>.
134     *
135     * @return the validation status
136     */
137    ValidationStatus getValidationStatus();
138
139    /**
140     * Returns the validator for this form field, or null if the field has no validator.<p>
141     *
142     * @return a validator or null
143     */
144    I_CmsValidator getValidator();
145
146    /**
147     * Returns the widget used by this form field.<p>
148     *
149     * @return a widget
150     */
151    I_CmsFormWidget getWidget();
152
153    /**
154     * Sets the id of this form field.<p>
155     *
156     * @param id the new id
157     */
158    void setId(String id);
159
160    /**
161     * Updates the validation status of this form field.<p>
162     *
163     * This will only have an effect if the field has a validator.<p>
164     *
165     * @param status the new validation status
166     */
167    void setValidationStatus(ValidationStatus status);
168
169    /**
170     * Sets the validator for this form field.<p>
171     *
172     * @param validator the new validator
173     */
174    void setValidator(I_CmsValidator validator);
175
176    /**
177     * Removes the binding to this form field's model.<p>
178     */
179    void unbind();
180
181}