View Javadoc
1   /**
2    * This file Copyright (c) 2010-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.annotation.deprecation.MgnlDeprecated;
37  
38  import info.magnolia.repository.RepositoryConstants;
39  
40  import java.util.ArrayList;
41  import java.util.Comparator;
42  import java.util.List;
43  
44  import com.vaadin.v7.shared.ui.combobox.FilteringMode;
45  
46  /**
47   * Basic definition class for various types of select fields.
48   * <p>
49   * Offers two distinct ways of populating selection options:
50   * <ul>
51   * <li>an explicit set of {@link SelectFieldOptionDefinition option definitions} can be provided via {@link #setOptions(List)}</li>
52   * <li><strong>if no explicit options are specified</strong> - option set can be resolved from a remote path in JCR repository by means of 
53   * {@link #setPath(String)}, {@link #setLabelProperty(String)} and {@link #setValueProperty(String)} methods</li>
54   * </ul>
55   *
56   * @deprecated since 6.2 - use {@link info.magnolia.ui.field.AbstractSelectFieldDefinition} instead.
57   *
58   * @see <a href="https://documentation.magnolia-cms.com/display/DOCS62/Upgrading+to+Magnolia+6.2.x">Upgrading to Magnolia 6.2.x</a>
59   */
60  @Deprecated
61  @MgnlDeprecated(since = "6.2", description = "Use new framework and info.magnolia.ui.field.AbstractSelectFieldDefinition instead.")
62  public class SelectFieldDefinition extends ConfiguredFieldDefinition {
63  
64      public static final String OPTION_VALUE_PROPERTY_NAME = "value";
65      public static final String OPTION_NAME_PROPERTY_NAME = "name";
66      public static final String OPTION_SELECTED_PROPERTY_NAME = "selected";
67      public static final String OPTION_ICONSRC_PROPERTY_NAME = "iconSrc";
68      public static final String OPTION_LABEL_PROPERTY_NAME = "label";
69  
70      public static final String DEFAULT_REPOSITORY_NAME = RepositoryConstants.CONFIG;
71  
72      private String path;
73  
74      private String repository = DEFAULT_REPOSITORY_NAME;
75  
76      private String valueProperty = OPTION_VALUE_PROPERTY_NAME;
77  
78      private String labelProperty = OPTION_LABEL_PROPERTY_NAME;
79  
80      private FilteringMode filteringMode = FilteringMode.OFF;
81  
82      private boolean sortOptions = true;
83  
84      private Class<? extends Comparator<SelectFieldOptionDefinition>> comparatorClass;
85  
86      private List<SelectFieldOptionDefinition> options = new ArrayList<SelectFieldOptionDefinition>();
87  
88      private boolean textInputAllowed = false;
89  
90      private int pageLength = 0;
91  
92      public List<SelectFieldOptionDefinition> getOptions() {
93          return options;
94      }
95  
96      public void setOptions(List<SelectFieldOptionDefinition> options) {
97          this.options = options;
98      }
99  
100     public void addOption(SelectFieldOptionDefinition option) {
101         options.add(option);
102     }
103 
104     public String getPath() {
105         return path;
106     }
107 
108     public void setPath(String path) {
109         this.path = path;
110     }
111 
112     public String getRepository() {
113         return repository;
114     }
115 
116     public void setRepository(String repository) {
117         this.repository = repository;
118     }
119 
120     public String getValueProperty() {
121         return valueProperty;
122     }
123 
124     public void setValueProperty(String valueProperty) {
125         this.valueProperty = valueProperty;
126     }
127 
128     public String getLabelProperty() {
129         return labelProperty;
130     }
131 
132     public void setLabelProperty(String labelProperty) {
133         this.labelProperty = labelProperty;
134     }
135 
136     /**
137      * Defines the filtering mode (off, startswith, contains) of this select field. Additionally, mind that filtering
138      * mode is only enabled with paging, i.e. when the pageLength property is greater than 0.
139      *
140      * @return a member of the FilteringMode enum. Defaults to <code>off</code>.
141      * @see com.vaadin.shared.ui.combobox.FilteringMode
142      */
143     public FilteringMode getFilteringMode() {
144         return filteringMode;
145     }
146 
147     public void setFilteringMode(FilteringMode filteringMode) {
148         this.filteringMode = filteringMode;
149     }
150 
151     /**
152      * @deprecated since 5.3.15, use {@link #setFilteringMode(FilteringMode)} instead.
153      */
154     @Deprecated
155     public void setFilteringMode(int filteringMode) {
156         switch (filteringMode) {
157         case 1:
158             this.filteringMode = FilteringMode.CONTAINS;
159         case 2:
160             this.filteringMode = FilteringMode.STARTSWITH;
161         default:
162             this.filteringMode = FilteringMode.OFF;
163         }
164     }
165 
166     /**
167      * By default, options labels are sorted alphabetically (in ascending order) unless <code>false</code> is specified. In that case, the JCR "natural order" should be kept.
168      */
169     public void setSortOptions(boolean sortOptions) {
170         this.sortOptions = sortOptions;
171     }
172 
173     public boolean isSortOptions() {
174         return sortOptions;
175     }
176 
177     public Class<? extends Comparator<SelectFieldOptionDefinition>> getComparatorClass() {
178         return comparatorClass;
179     }
180 
181     public void setComparatorClass(Class<? extends Comparator<SelectFieldOptionDefinition>> comparatorClass) {
182         this.comparatorClass = comparatorClass;
183     }
184 
185     public boolean isTextInputAllowed() {
186         return textInputAllowed;
187     }
188 
189     public void setTextInputAllowed(boolean textInputAllowed) {
190         this.textInputAllowed = textInputAllowed;
191     }
192 
193     public int getPageLength() {
194         return pageLength;
195     }
196 
197     public void setPageLength(int pageLength) {
198         this.pageLength = pageLength;
199     }
200 }