001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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: https://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: https://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, 061 /** It is unknown whether the field's content is valid. */ 062 unknown, 063 /** The field's content is valid. */ 064 valid 065 } 066 067 /** 068 * Binds a model object to the form field.<p> 069 * 070 * @param model the model object 071 */ 072 void bind(I_CmsStringModel model); 073 074 /** 075 * Returns the default value for the form field.<p> 076 * 077 * @return the default value for the form field 078 */ 079 Object getDefaultValue(); 080 081 /** 082 * The description of the form field, or null if there is no description.<p> 083 * 084 * @return a description string or null 085 */ 086 String getDescription(); 087 088 /** 089 * Returns the id of this form field, or null if the form field id has not been set. 090 * 091 * If a form field without an id is added to a form, typically it will receive a synthetic id. 092 * 093 * @return the id 094 */ 095 String getId(); 096 097 /** 098 * The label of the form field, or null if there is no label.<p> 099 * 100 * @return a label or null 101 */ 102 String getLabel(); 103 104 /** 105 * Returns the layout data for this field.<p> 106 * 107 * @return the layout data for this field 108 */ 109 LayoutData getLayoutData(); 110 111 /** 112 * Returns the model object for this field. 113 * 114 * @return the model used for this field 115 */ 116 I_CmsStringModel getModel(); 117 118 /** 119 * Returns the model id.<p> 120 * 121 * @return the model id 122 */ 123 String getModelId(); 124 125 /** 126 * Returns the model value.<p> 127 * 128 * @return the model value 129 */ 130 String getModelValue(); 131 132 /** 133 * Returns the validation status of this form field.<p> 134 * 135 * If the field has no validator, this should always return <code>valid</code>. 136 * 137 * @return the validation status 138 */ 139 ValidationStatus getValidationStatus(); 140 141 /** 142 * Returns the validator for this form field, or null if the field has no validator.<p> 143 * 144 * @return a validator or null 145 */ 146 I_CmsValidator getValidator(); 147 148 /** 149 * Returns the widget used by this form field.<p> 150 * 151 * @return a widget 152 */ 153 I_CmsFormWidget getWidget(); 154 155 /** 156 * Sets the id of this form field.<p> 157 * 158 * @param id the new id 159 */ 160 void setId(String id); 161 162 /** 163 * Updates the validation status of this form field.<p> 164 * 165 * This will only have an effect if the field has a validator.<p> 166 * 167 * @param status the new validation status 168 */ 169 void setValidationStatus(ValidationStatus status); 170 171 /** 172 * Sets the validator for this form field.<p> 173 * 174 * @param validator the new validator 175 */ 176 void setValidator(I_CmsValidator validator); 177 178 /** 179 * Removes the binding to this form field's model.<p> 180 */ 181 void unbind(); 182 183}