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      @Override
76      public String getName() {
77          return name;
78      }
79  
80      @Override
81      public String getLabel() {
82          return label;
83      }
84  
85      /**
86       * @deprecated since 5.1. Use {@link info.magnolia.i18nsystem.I18nizer} mechanism instead.
87       */
88      @Override
89      @Deprecated
90      public String getI18nBasename() {
91          return i18nBasename;
92      }
93  
94      @Override
95      public String getDescription() {
96          return description;
97      }
98  
99      @Override
100     public String getType() {
101         return type;
102     }
103 
104     @Override
105     public boolean isRequired() {
106         return required;
107     }
108 
109     @Override
110     public String getRequiredErrorMessage() {
111         return requiredErrorMessage;
112     }
113 
114     @Override
115     public List<FieldValidatorDefinition> getValidators() {
116         return validators;
117     }
118 
119     @Override
120     public String getDefaultValue() {
121         return this.defaultValue;
122     }
123 
124     @Override
125     public boolean isReadOnly() {
126         return this.readOnly;
127     }
128 
129     @Override
130     public boolean isI18n() {
131         return i18n;
132     }
133 
134     @Override
135     public String getStyleName() {
136         return styleName;
137     }
138 
139     public void setStyleName(String styleName) {
140         this.styleName = styleName;
141     }
142 
143     public void setI18n(boolean i18n) {
144         this.i18n = i18n;
145     }
146 
147     public void setRequiredErrorMessage(String requiredErrorMessage) {
148         this.requiredErrorMessage = requiredErrorMessage;
149     }
150 
151     public void setReadOnly(boolean readOnly) {
152         this.readOnly = readOnly;
153     }
154 
155     public void setName(String name) {
156         this.name = name;
157     }
158 
159     public void setLabel(String label) {
160         this.label = label;
161     }
162 
163     /**
164      * @deprecated since 5.1. Use {@link info.magnolia.i18nsystem.I18nizer} mechanism instead.
165      */
166     @Deprecated
167     public void setI18nBasename(String i18nBasename) {
168         this.i18nBasename = i18nBasename;
169     }
170 
171     public void setDescription(String description) {
172         this.description = description;
173     }
174 
175     public void setType(String type) {
176         this.type = type;
177     }
178 
179     public void setRequired(boolean required) {
180         this.required = required;
181     }
182 
183     public void setValidators(List<FieldValidatorDefinition> validators) {
184         this.validators = validators;
185     }
186 
187     public void addValidator(FieldValidatorDefinition validator) {
188         validators.add(validator);
189     }
190 
191     public void setDefaultValue(String defaultValue) {
192         this.defaultValue = defaultValue;
193     }
194 
195     @Override
196     public Class<? extends Transformer<?>> getTransformerClass() {
197         return transformerClass;
198     }
199 
200     public void setTransformerClass(Class<? extends Transformer<?>> transformerClass) {
201         this.transformerClass = transformerClass;
202     }
203 
204     @Override
205     public Class<?> getConverterClass() {
206         return converterClass;
207     }
208 
209     public void setConverterClass(Class<?> converterClass) {
210         this.converterClass = converterClass;
211     }
212 
213 }