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