1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.field;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.util.ConcreteKeyValue;
20 import org.kuali.rice.core.api.util.KeyValue;
21 import org.kuali.rice.krad.datadictionary.AttributeDefinition;
22 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
23 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
24 import org.kuali.rice.krad.uif.component.Component;
25 import org.kuali.rice.krad.uif.control.CheckboxControl;
26 import org.kuali.rice.krad.uif.control.Control;
27 import org.kuali.rice.krad.uif.control.FilterableLookupCriteriaControl;
28 import org.kuali.rice.krad.uif.control.MultiValueControl;
29 import org.kuali.rice.krad.uif.control.RadioGroupControl;
30 import org.kuali.rice.krad.uif.control.TextAreaControl;
31 import org.kuali.rice.krad.uif.util.ComponentFactory;
32 import org.kuali.rice.krad.uif.util.ComponentUtils;
33 import org.kuali.rice.krad.uif.view.View;
34 import org.kuali.rice.krad.util.KRADConstants;
35 import org.kuali.rice.krad.util.KRADPropertyConstants;
36
37 import java.util.ArrayList;
38 import java.util.List;
39 import java.util.Map;
40
41
42
43
44
45
46 @BeanTag(name = "lookupCriteriaInputField-bean", parent = "Uif-LookupCriteriaInputField")
47 public class LookupInputField extends InputField {
48 private static final long serialVersionUID = -8294275596836322699L;
49
50 private boolean disableWildcardsAndOperators;
51 private boolean addControlSelectAllOption;
52 private boolean triggerOnChange;
53 private boolean ranged;
54
55 private RadioGroupControl radioGroupControl;
56
57 public LookupInputField() {
58 super();
59
60 disableWildcardsAndOperators = false;
61 addControlSelectAllOption = false;
62 }
63
64
65
66
67
68
69
70 @Override
71 public void performApplyModel(View view, Object model, Component parent) {
72 super.performApplyModel(view, model, parent);
73
74 if (getControl() != null && getControl() instanceof CheckboxControl) {
75 setControl(getRadioGroupControl());
76 }
77 }
78
79
80
81
82
83
84
85
86
87
88
89 @Override
90 public void performFinalize(View view, Object model, Component parent) {
91 super.performFinalize(view, model, parent);
92
93
94 if (addControlSelectAllOption && (getControl() != null) && getControl() instanceof MultiValueControl) {
95 MultiValueControl multiValueControl = (MultiValueControl) getControl();
96 if (multiValueControl.getOptions() != null) {
97 List<KeyValue> fieldOptions = multiValueControl.getOptions();
98 fieldOptions.add(0, new ConcreteKeyValue("", "All"));
99
100 multiValueControl.setOptions(fieldOptions);
101 }
102 }
103 }
104
105
106
107
108
109
110 @Override
111 public List<Component> getComponentPrototypes() {
112 List<Component> components = super.getComponentPrototypes();
113 if (getControl() != null && getControl() instanceof CheckboxControl) {
114 components.add(radioGroupControl);
115 }
116 return components;
117 }
118
119
120
121
122
123
124
125
126
127 @Override
128 public void copyFromAttributeDefinition(View view, AttributeDefinition attributeDefinition) {
129
130 if (StringUtils.isEmpty(getLabel())) {
131 setLabel(attributeDefinition.getLabel());
132 }
133
134
135 if (StringUtils.isEmpty(getShortLabel())) {
136 setShortLabel(attributeDefinition.getShortLabel());
137 }
138
139
140 if (getDataFieldSecurity().getAttributeSecurity() == null) {
141 getDataFieldSecurity().setAttributeSecurity(attributeDefinition.getAttributeSecurity());
142 }
143
144
145 if (getOptionsFinder() == null) {
146 setOptionsFinder(attributeDefinition.getOptionsFinder());
147 }
148
149
150
151
152 if (getControl() == null) {
153 Control control = convertControlToLookupControl(attributeDefinition);
154 view.assignComponentIds(control);
155
156 setControl(control);
157 }
158
159
160 setMaxLength(100);
161
162
163 if (StringUtils.isEmpty(getDefaultValue())) {
164 if ((StringUtils.equals(getPropertyName(), KRADPropertyConstants.ACTIVE))) {
165 setDefaultValue(KRADConstants.YES_INDICATOR_VALUE);
166 }
167 }
168
169
170
171
172
173
174 }
175
176
177
178
179
180
181
182
183 protected static Control convertControlToLookupControl(AttributeDefinition attributeDefinition) {
184 if (attributeDefinition.getControlField() == null) {
185 return null;
186 }
187
188 Control newControl = null;
189
190
191 if (CheckboxControl.class.isAssignableFrom(attributeDefinition.getControlField().getClass())) {
192 newControl = ComponentFactory.getRadioGroupControlHorizontal();
193 List<KeyValue> options = new ArrayList<KeyValue>();
194 options.add(new ConcreteKeyValue("Y", "Yes"));
195 options.add(new ConcreteKeyValue("N", "No"));
196 options.add(new ConcreteKeyValue("", "Both"));
197
198 ((RadioGroupControl) newControl).setOptions(options);
199 }
200
201 else if (TextAreaControl.class.isAssignableFrom(attributeDefinition.getControlField().getClass())) {
202 newControl = ComponentFactory.getTextControl();
203 } else {
204 newControl = ComponentUtils.copy(attributeDefinition.getControlField(), "");
205 }
206
207 return newControl;
208 }
209
210
211
212
213 @BeanTagAttribute(name="disableWildcardsAndOperators")
214 public boolean isDisableWildcardsAndOperators() {
215 return this.disableWildcardsAndOperators;
216 }
217
218
219
220
221 public void setDisableWildcardsAndOperators(boolean disableWildcardsAndOperators) {
222 this.disableWildcardsAndOperators = disableWildcardsAndOperators;
223 }
224
225
226
227
228
229
230
231 @BeanTagAttribute(name="addControlSelectAllOption")
232 public boolean isAddControlSelectAllOption() {
233 return addControlSelectAllOption;
234 }
235
236
237
238
239
240
241 public void setAddControlSelectAllOption(boolean addControlSelectAllOption) {
242 this.addControlSelectAllOption = addControlSelectAllOption;
243 }
244
245
246
247
248
249
250 public RadioGroupControl getRadioGroupControl() {
251 return radioGroupControl;
252 }
253
254
255
256
257
258
259 public void setRadioGroupControl(RadioGroupControl radioGroupControl) {
260 this.radioGroupControl = radioGroupControl;
261 }
262
263
264
265
266
267
268 public boolean isRanged() {
269 return ranged;
270 }
271
272
273
274
275
276
277 public void setRanged(boolean ranged) {
278 this.ranged = ranged;
279 }
280
281
282
283
284
285
286
287 public Map<String, String> filterSearchCriteria( Map<String, String> searchCriteria) {
288 if (getControl() instanceof FilterableLookupCriteriaControl) {
289 return ((FilterableLookupCriteriaControl) getControl()).filterSearchCriteria(getPropertyName(), searchCriteria);
290 } else {
291 return searchCriteria;
292 }
293 }
294 }