View Javadoc
1   /*
2    * Copyright (c) 2011-2024 PrimeFaces Extensions
3    *
4    *  Permission is hereby granted, free of charge, to any person obtaining a copy
5    *  of this software and associated documentation files (the "Software"), to deal
6    *  in the Software without restriction, including without limitation the rights
7    *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    *  copies of the Software, and to permit persons to whom the Software is
9    *  furnished to do so, subject to the following conditions:
10   *
11   *  The above copyright notice and this permission notice shall be included in
12   *  all copies or substantial portions of the Software.
13   *
14   *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20   *  THE SOFTWARE.
21   */
22  package org.primefaces.extensions.component.fuzzysearch;
23  
24  import javax.faces.component.UISelectOne;
25  import javax.faces.component.behavior.ClientBehaviorHolder;
26  
27  import org.primefaces.component.api.PrimeClientBehaviorHolder;
28  import org.primefaces.component.api.Widget;
29  
30  /**
31   * <code>FuzzySearch</code> component.
32   *
33   * @author https://github.com/aripddev
34   * @since 8.0.1
35   */
36  public abstract class FuzzySearchBase extends UISelectOne implements Widget, ClientBehaviorHolder, PrimeClientBehaviorHolder {
37  
38      public static final String COMPONENT_FAMILY = "org.primefaces.extensions.component";
39  
40      public static final String DEFAULT_RENDERER = "org.primefaces.extensions.component.FuzzySearchRenderer";
41  
42      @SuppressWarnings("java:S115")
43      protected enum PropertyKeys {
44          // @formatter:off
45          widgetVar,
46          disabled,
47          label,
48          onchange,
49          style,
50          styleClass,
51          tabindex,
52          unselectable,
53          resultStyle,
54          resultStyleClass,
55          placeholder,
56          highlight,
57          listItemsAtTheBeginning
58          // @formatter:on
59      }
60  
61      public FuzzySearchBase() {
62          super.setRendererType(DEFAULT_RENDERER);
63      }
64  
65      @Override
66      public String getFamily() {
67          return COMPONENT_FAMILY;
68      }
69  
70      public String getWidgetVar() {
71          return (String) getStateHelper().eval(PropertyKeys.widgetVar, null);
72      }
73  
74      public void setWidgetVar(final String widgetVar) {
75          getStateHelper().put(PropertyKeys.widgetVar, widgetVar);
76      }
77  
78      public boolean isDisabled() {
79          return (Boolean) getStateHelper().eval(PropertyKeys.disabled, false);
80      }
81  
82      public void setDisabled(final boolean disabled) {
83          getStateHelper().put(PropertyKeys.disabled, disabled);
84      }
85  
86      public String getLabel() {
87          return (String) getStateHelper().eval(PropertyKeys.label, null);
88      }
89  
90      public void setLabel(final String label) {
91          getStateHelper().put(PropertyKeys.label, label);
92      }
93  
94      public String getOnchange() {
95          return (String) getStateHelper().eval(PropertyKeys.onchange, null);
96      }
97  
98      public void setOnchange(final String onchange) {
99          getStateHelper().put(PropertyKeys.onchange, onchange);
100     }
101 
102     public String getStyle() {
103         return (String) getStateHelper().eval(PropertyKeys.style, null);
104     }
105 
106     public void setStyle(final String style) {
107         getStateHelper().put(PropertyKeys.style, style);
108     }
109 
110     public String getStyleClass() {
111         return (String) getStateHelper().eval(PropertyKeys.styleClass, null);
112     }
113 
114     public void setStyleClass(final String styleClass) {
115         getStateHelper().put(PropertyKeys.styleClass, styleClass);
116     }
117 
118     public String getTabindex() {
119         return (String) getStateHelper().eval(PropertyKeys.tabindex, null);
120     }
121 
122     public void setTabindex(final String tabindex) {
123         getStateHelper().put(PropertyKeys.tabindex, tabindex);
124     }
125 
126     public boolean isUnselectable() {
127         return (Boolean) getStateHelper().eval(PropertyKeys.unselectable, true);
128     }
129 
130     public void setUnselectable(final boolean unselectable) {
131         getStateHelper().put(PropertyKeys.unselectable, unselectable);
132     }
133 
134     public boolean isHighlight() {
135         return (Boolean) getStateHelper().eval(PropertyKeys.highlight, true);
136     }
137 
138     public void setHighlight(final boolean highlight) {
139         getStateHelper().put(PropertyKeys.highlight, highlight);
140     }
141 
142     public String getResultStyle() {
143         return (String) getStateHelper().eval(PropertyKeys.resultStyle, null);
144     }
145 
146     public void setResultStyle(final String resultStyle) {
147         getStateHelper().put(PropertyKeys.resultStyle, resultStyle);
148     }
149 
150     public String getResultStyleClass() {
151         return (String) getStateHelper().eval(PropertyKeys.resultStyleClass, null);
152     }
153 
154     public void setResultStyleClass(final String resultStyleClass) {
155         getStateHelper().put(PropertyKeys.resultStyleClass, resultStyleClass);
156     }
157 
158     public String getPlaceholder() {
159         return (String) getStateHelper().eval(PropertyKeys.placeholder, null);
160     }
161 
162     public void setPlaceholder(final String placeholder) {
163         getStateHelper().put(PropertyKeys.placeholder, placeholder);
164     }
165 
166     public boolean isListItemsAtTheBeginning() {
167         return (Boolean) getStateHelper().eval(PropertyKeys.listItemsAtTheBeginning, false);
168     }
169 
170     public void setListItemsAtTheBeginning(final boolean listItemsAtTheBeginning) {
171         getStateHelper().put(PropertyKeys.listItemsAtTheBeginning, listItemsAtTheBeginning);
172     }
173 
174 }