View Javadoc
1   /**
2    * This file Copyright (c) 2011-2018 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.ui.form.field.definition;
35  
36  import info.magnolia.ui.form.field.transformer.Transformer;
37  import info.magnolia.ui.form.validator.definition.FieldValidatorDefinition;
38  
39  import java.util.ArrayList;
40  import java.util.List;
41  
42  /**
43   * Describes a field in a dialog.
44   */
45  public class ConfiguredFieldDefinition implements FieldDefinition {
46  
47      private String name;
48  
49      private String label;
50  
51      private String i18nBasename;
52  
53      private boolean i18n = false;
54  
55      private String description; // not relevant for controlType=static
56  
57      private String type; // JCR Property type name see javax.jcr.PropertyType
58  
59      private boolean required = false; // Not relevant for checkbox
60  
61      private String requiredErrorMessage = "validation.message.required";
62  
63      private boolean readOnly = false; // Specify if the property has to be saved
64  
65      private String defaultValue; // Specify the default value
66  
67      private String styleName;
68  
69      private List<FieldValidatorDefinition> validators = new ArrayList<FieldValidatorDefinition>();
70  
71      private Class<? extends Transformer<?>> transformerClass;
72  
73      private Class<?> converterClass;
74  
75      /**
76       * Defined only to eliminate to-bean transformation related warnings.
77       *
78       * <p>Note: this field is only specified in the configured definition and doesn't provide a getter as it is
79       * not part of the field definition contract. The use case is simplification of field definitions themselves and
80       * to prevent N2B/M2B mechanisms to report problems of kind "unknown property".</p>
81       * @see info.magnolia.ui.form.fieldtype.resolver.FieldTypeResolver
82       */
83      private String fieldType;
84  
85      @Override
86      public String getName() {
87          return name;
88      }
89  
90      @Override
91      public String getLabel() {
92          return label;
93      }
94  
95      /**
96       * @deprecated since 5.1. Use {@link info.magnolia.i18nsystem.I18nizer} mechanism instead.
97       */
98      @Override
99      @Deprecated
100     public String getI18nBasename() {
101         return i18nBasename;
102     }
103 
104     @Override
105     public String getDescription() {
106         return description;
107     }
108 
109     @Override
110     public String getType() {
111         return type;
112     }
113 
114     @Override
115     public boolean isRequired() {
116         return required;
117     }
118 
119     @Override
120     public String getRequiredErrorMessage() {
121         return requiredErrorMessage;
122     }
123 
124     @Override
125     public List<FieldValidatorDefinition> getValidators() {
126         return validators;
127     }
128 
129     @Override
130     public String getDefaultValue() {
131         return this.defaultValue;
132     }
133 
134     @Override
135     public boolean isReadOnly() {
136         return this.readOnly;
137     }
138 
139     @Override
140     public boolean isI18n() {
141         return i18n;
142     }
143 
144     @Override
145     public String getStyleName() {
146         return styleName;
147     }
148 
149     public void setStyleName(String styleName) {
150         this.styleName = styleName;
151     }
152 
153     public void setI18n(boolean i18n) {
154         this.i18n = i18n;
155     }
156 
157     public void setRequiredErrorMessage(String requiredErrorMessage) {
158         this.requiredErrorMessage = requiredErrorMessage;
159     }
160 
161     public void setReadOnly(boolean readOnly) {
162         this.readOnly = readOnly;
163     }
164 
165     public void setName(String name) {
166         this.name = name;
167     }
168 
169     public void setLabel(String label) {
170         this.label = label;
171     }
172 
173     /**
174      * @deprecated since 5.1. Use {@link info.magnolia.i18nsystem.I18nizer} mechanism instead.
175      */
176     @Deprecated
177     public void setI18nBasename(String i18nBasename) {
178         this.i18nBasename = i18nBasename;
179     }
180 
181     public void setDescription(String description) {
182         this.description = description;
183     }
184 
185     public void setType(String type) {
186         this.type = type;
187     }
188 
189     public void setRequired(boolean required) {
190         this.required = required;
191     }
192 
193     public void setValidators(List<FieldValidatorDefinition> validators) {
194         this.validators = validators;
195     }
196 
197     public void addValidator(FieldValidatorDefinition validator) {
198         validators.add(validator);
199     }
200 
201     public void setDefaultValue(String defaultValue) {
202         this.defaultValue = defaultValue;
203     }
204 
205     @Override
206     public Class<? extends Transformer<?>> getTransformerClass() {
207         return transformerClass;
208     }
209 
210     public void setTransformerClass(Class<? extends Transformer<?>> transformerClass) {
211         this.transformerClass = transformerClass;
212     }
213 
214     @Override
215     public Class<?> getConverterClass() {
216         return converterClass;
217     }
218 
219     public void setConverterClass(Class<?> converterClass) {
220         this.converterClass = converterClass;
221     }
222 
223     public String getFieldType() {
224         return fieldType;
225     }
226 
227     public void setFieldType(String fieldType) {
228         this.fieldType = fieldType;
229     }
230 }