View Javadoc
1   /**
2    * This file Copyright (c) 2010-2015 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.shared.ui.combobox.FilteringMode;
43  
44  /**
45   * Field definition for a select field.
46   */
47  public class SelectFieldDefinition extends ConfiguredFieldDefinition {
48  
49      public static final String OPTION_VALUE_PROPERTY_NAME = "value";
50      public static final String OPTION_NAME_PROPERTY_NAME = "name";
51      public static final String OPTION_SELECTED_PROPERTY_NAME = "selected";
52      public static final String OPTION_ICONSRC_PROPERTY_NAME = "iconSrc";
53      public static final String OPTION_LABEL_PROPERTY_NAME = "label";
54  
55      public static final String DEFAULT_REPOSITORY_NAME = RepositoryConstants.CONFIG;
56  
57      private String path;
58  
59      private String repository = DEFAULT_REPOSITORY_NAME;
60  
61      private String valueProperty = OPTION_VALUE_PROPERTY_NAME;
62  
63      private String labelProperty = OPTION_LABEL_PROPERTY_NAME;
64  
65      private int filteringMode = 0;
66  
67      private boolean sortOptions = true;
68  
69      private Class<? extends Comparator<SelectFieldOptionDefinition>> comparatorClass;
70  
71      private List<SelectFieldOptionDefinition> options = new ArrayList<SelectFieldOptionDefinition>();
72  
73      public List<SelectFieldOptionDefinition> getOptions() {
74          return options;
75      }
76  
77      public void setOptions(List<SelectFieldOptionDefinition> options) {
78          this.options = options;
79      }
80  
81      public void addOption(SelectFieldOptionDefinition option) {
82          options.add(option);
83      }
84  
85      public String getPath() {
86          return path;
87      }
88  
89      public void setPath(String path) {
90          this.path = path;
91      }
92  
93      public String getRepository() {
94          return repository;
95      }
96  
97      public void setRepository(String repository) {
98          this.repository = repository;
99      }
100 
101     public String getValueProperty() {
102         return valueProperty;
103     }
104 
105     public void setValueProperty(String valueProperty) {
106         this.valueProperty = valueProperty;
107     }
108 
109     public String getLabelProperty() {
110         return labelProperty;
111     }
112 
113     public void setLabelProperty(String labelProperty) {
114         this.labelProperty = labelProperty;
115     }
116 
117     public FilteringMode getFilteringMode() {
118         switch (filteringMode) {
119         case 1:
120             return FilteringMode.CONTAINS;
121         case 2:
122             return FilteringMode.STARTSWITH;
123         default:
124             return FilteringMode.OFF;
125         }
126     }
127 
128     public void setFilteringMode(int filteringMode) {
129         this.filteringMode = filteringMode;
130     }
131 
132     /**
133      * 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.
134      */
135     public void setSortOptions(boolean sortOptions) {
136         this.sortOptions = sortOptions;
137     }
138 
139     public boolean isSortOptions() {
140         return sortOptions;
141     }
142 
143     public Class<? extends Comparator<SelectFieldOptionDefinition>> getComparatorClass() {
144         return comparatorClass;
145     }
146 
147     public void setComparatorClass(Class<? extends Comparator<SelectFieldOptionDefinition>> comparatorClass) {
148         this.comparatorClass = comparatorClass;
149     }
150 }