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