View Javadoc
1   /**
2    * This file Copyright (c) 2013-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.config;
35  
36  import info.magnolia.ui.form.field.component.ContentPreviewComponent;
37  import info.magnolia.ui.form.field.converter.IdentifierToPathConverter;
38  import info.magnolia.ui.form.field.definition.ContentPreviewDefinition;
39  import info.magnolia.ui.form.field.definition.LinkFieldDefinition;
40  import info.magnolia.ui.form.field.transformer.Transformer;
41  import info.magnolia.ui.form.validator.definition.ConfiguredFieldValidatorDefinition;
42  
43  /**
44   * Builder for building a link field definition.
45   */
46  public class LinkFieldBuilder extends AbstractFieldBuilder {
47  
48      private final LinkFieldDefinition definition = new LinkFieldDefinition();
49  
50      public LinkFieldBuilder(String name) {
51          this.definition().setName(name);
52      }
53  
54      @Override
55      public LinkFieldDefinition definition() {
56          return definition;
57      }
58  
59      public LinkFieldBuilder targetPropertyToPopulate(String targetPropertyToPopulate) {
60          definition().setTargetPropertyToPopulate(targetPropertyToPopulate);
61          return this;
62      }
63  
64      public LinkFieldBuilder targetWorkspace(String targetWorkspace) {
65          definition().setTargetWorkspace(targetWorkspace);
66          return this;
67      }
68  
69      public LinkFieldBuilder targetTreeRootPath(String targetTreeRootPath) {
70          definition().setTargetTreeRootPath(targetTreeRootPath);
71          return this;
72      }
73  
74      public LinkFieldBuilder appName(String appName) {
75          definition().setAppName(appName);
76          return this;
77      }
78  
79      public LinkFieldBuilder buttonSelectNewLabel(String buttonSelectNewLabel) {
80          definition().setButtonSelectNewLabel(buttonSelectNewLabel);
81          return this;
82      }
83  
84      public LinkFieldBuilder buttonSelectOtherLabel(String buttonSelectOtherLabel) {
85          definition().setButtonSelectOtherLabel(buttonSelectOtherLabel);
86          return this;
87      }
88  
89      public LinkFieldBuilder identifierToPathConverter(IdentifierToPathConverter identifierToPathConverter) {
90          definition().setIdentifierToPathConverter(identifierToPathConverter);
91          return this;
92      }
93  
94      public LinkFieldBuilder contentPreviewClass(Class<? extends ContentPreviewComponent<?>> contentPreviewClass) {
95          ContentPreviewDefinition contentPreviewDefinition = definition().getContentPreviewDefinition();
96          if (contentPreviewDefinition == null) {
97              contentPreviewDefinition = new ContentPreviewDefinition();
98              definition().setContentPreviewDefinition(contentPreviewDefinition);
99          }
100         contentPreviewDefinition.setContentPreviewClass(contentPreviewClass);
101         return this;
102     }
103 
104     public LinkFieldBuilder fieldEditable() {
105         definition().setFieldEditable(true);
106         return this;
107     }
108 
109     public LinkFieldBuilder fieldEditable(boolean fieldEditable) {
110         definition().setFieldEditable(fieldEditable);
111         return this;
112     }
113 
114     // Overrides for methods in parent class changing return type to allow method chaining
115 
116     @Override
117     public LinkFieldBuilder label(String label) {
118         return (LinkFieldBuilder) super.label(label);
119     }
120 
121     @Override
122     public LinkFieldBuilder i18nBasename(String i18nBasename) {
123         return (LinkFieldBuilder) super.i18nBasename(i18nBasename);
124     }
125 
126     @Override
127     public LinkFieldBuilder i18n(boolean i18n) {
128         return (LinkFieldBuilder) super.i18n(i18n);
129     }
130 
131     @Override
132     public LinkFieldBuilder i18n() {
133         return (LinkFieldBuilder) super.i18n();
134     }
135 
136     @Override
137     public LinkFieldBuilder description(String description) {
138         return (LinkFieldBuilder) super.description(description);
139     }
140 
141     @Override
142     public LinkFieldBuilder type(String type) {
143         return (LinkFieldBuilder) super.type(type);
144     }
145 
146     @Override
147     public LinkFieldBuilder required(boolean required) {
148         return (LinkFieldBuilder) super.required(required);
149     }
150 
151     @Override
152     public LinkFieldBuilder required() {
153         return (LinkFieldBuilder) super.required();
154     }
155 
156     @Override
157     public LinkFieldBuilder requiredErrorMessage(String requiredErrorMessage) {
158         return (LinkFieldBuilder) super.requiredErrorMessage(requiredErrorMessage);
159     }
160 
161     @Override
162     public LinkFieldBuilder readOnly(boolean readOnly) {
163         return (LinkFieldBuilder) super.readOnly(readOnly);
164     }
165 
166     @Override
167     public LinkFieldBuilder readOnly() {
168         return (LinkFieldBuilder) super.readOnly();
169     }
170 
171     @Override
172     public LinkFieldBuilder defaultValue(String defaultValue) {
173         return (LinkFieldBuilder) super.defaultValue(defaultValue);
174     }
175 
176     @Override
177     public LinkFieldBuilder styleName(String styleName) {
178         return (LinkFieldBuilder) super.styleName(styleName);
179     }
180 
181     @Override
182     public LinkFieldBuilder validator(ConfiguredFieldValidatorDefinition validatorDefinition) {
183         return (LinkFieldBuilder) super.validator(validatorDefinition);
184     }
185 
186     @Override
187     public LinkFieldBuilder validator(GenericValidatorBuilder validatorBuilder) {
188         return (LinkFieldBuilder) super.validator(validatorBuilder);
189     }
190 
191     @Override
192     public LinkFieldBuilder transformerClass(Class<? extends Transformer<?>> transformerClass) {
193         return (LinkFieldBuilder) super.transformerClass(transformerClass);
194     }
195 }