View Javadoc

1   /**
2    * This file Copyright (c) 2011-2014 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  import com.vaadin.data.util.converter.Converter;
43  
44  /**
45   * Describes a field in a dialog.
46   */
47  public class ConfiguredFieldDefinition implements FieldDefinition {
48  
49      private String name;
50  
51      private String label;
52  
53      private String i18nBasename;
54  
55      private boolean i18n = false;
56  
57      private String description; // not relevant for controlType=static
58  
59      private String type; // JCR Property type name see javax.jcr.PropertyType
60  
61      private boolean required = false; // Not relevant for checkbox
62  
63      private String requiredErrorMessage = "validation.message.required";
64  
65      private boolean readOnly = false; // Specify if the property has to be saved
66  
67      private String defaultValue; // Specify the default value
68  
69      private String styleName;
70  
71      private List<FieldValidatorDefinition> validators = new ArrayList<FieldValidatorDefinition>();
72  
73      private Class<? extends Transformer<?>> transformerClass;
74  
75      private Class<? extends Converter<?,?>> converterClass;
76  
77      @Override
78      public String getName() {
79          return name;
80      }
81  
82      @Override
83      public String getLabel() {
84          return label;
85      }
86  
87      /**
88       * @deprecated since 5.1. Use {@link info.magnolia.i18nsystem.I18nizer} mechanism instead.
89       */
90      @Override
91      @Deprecated
92      public String getI18nBasename() {
93          return i18nBasename;
94      }
95  
96      @Override
97      public String getDescription() {
98          return description;
99      }
100 
101     @Override
102     public String getType() {
103         return type;
104     }
105 
106     @Override
107     public boolean isRequired() {
108         return required;
109     }
110 
111     @Override
112     public String getRequiredErrorMessage() {
113         return requiredErrorMessage;
114     }
115 
116     @Override
117     public List<FieldValidatorDefinition> getValidators() {
118         return validators;
119     }
120 
121     @Override
122     public String getDefaultValue() {
123         return this.defaultValue;
124     }
125 
126     @Override
127     public boolean isReadOnly() {
128         return this.readOnly;
129     }
130 
131     @Override
132     public boolean isI18n() {
133         return i18n;
134     }
135 
136     @Override
137     public String getStyleName() {
138         return styleName;
139     }
140 
141     public void setStyleName(String styleName) {
142         this.styleName = styleName;
143     }
144 
145     public void setI18n(boolean i18n) {
146         this.i18n = i18n;
147     }
148 
149     public void setRequiredErrorMessage(String requiredErrorMessage) {
150         this.requiredErrorMessage = requiredErrorMessage;
151     }
152 
153     public void setReadOnly(boolean readOnly) {
154         this.readOnly = readOnly;
155     }
156 
157     public void setName(String name) {
158         this.name = name;
159     }
160 
161     public void setLabel(String label) {
162         this.label = label;
163     }
164 
165     /**
166      * @deprecated since 5.1. Use {@link info.magnolia.i18nsystem.I18nizer} mechanism instead.
167      */
168     @Deprecated
169     public void setI18nBasename(String i18nBasename) {
170         this.i18nBasename = i18nBasename;
171     }
172 
173     public void setDescription(String description) {
174         this.description = description;
175     }
176 
177     public void setType(String type) {
178         this.type = type;
179     }
180 
181     public void setRequired(boolean required) {
182         this.required = required;
183     }
184 
185     public void setValidators(List<FieldValidatorDefinition> validators) {
186         this.validators = validators;
187     }
188 
189     public void addValidator(FieldValidatorDefinition validator) {
190         validators.add(validator);
191     }
192 
193     public void setDefaultValue(String defaultValue) {
194         this.defaultValue = defaultValue;
195     }
196 
197     @Override
198     public Class<? extends Transformer<?>> getTransformerClass() {
199         return transformerClass;
200     }
201 
202     public void setTransformerClass(Class<? extends Transformer<?>> transformerClass) {
203         this.transformerClass = transformerClass;
204     }
205 
206     @Override
207     public Class<? extends Converter<?, ?>> getConverterClass() {
208         return converterClass;
209     }
210 
211     public void setConverterClass(Class<? extends Converter<?, ?>> converterClass) {
212         this.converterClass = converterClass;
213     }
214 
215 }