1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.lookup;
17
18 import java.util.Map;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.kuali.rice.core.api.util.ConcreteKeyValue;
22 import org.kuali.rice.krad.datadictionary.AttributeDefinition;
23 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
24 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
25 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
26 import org.kuali.rice.krad.uif.UifConstants;
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.FilterableLookupCriteriaControl;
30 import org.kuali.rice.krad.uif.control.MultiValueControl;
31 import org.kuali.rice.krad.uif.control.RadioGroupControl;
32 import org.kuali.rice.krad.uif.control.TextAreaControl;
33 import org.kuali.rice.krad.uif.element.Message;
34 import org.kuali.rice.krad.uif.field.InputField;
35 import org.kuali.rice.krad.uif.field.InputFieldBase;
36 import org.kuali.rice.krad.uif.util.ComponentFactory;
37 import org.kuali.rice.krad.uif.util.ComponentUtils;
38 import org.kuali.rice.krad.uif.util.KeyMessage;
39 import org.kuali.rice.krad.uif.util.LifecycleElement;
40 import org.kuali.rice.krad.util.KRADConstants;
41 import org.kuali.rice.krad.util.KRADPropertyConstants;
42
43
44
45
46
47
48 @BeanTag(name = "lookupCriteriaInputField-bean", parent = "Uif-LookupCriteriaInputField")
49 public class LookupInputField extends InputFieldBase {
50 private static final long serialVersionUID = -8294275596836322699L;
51
52 private boolean disableWildcardsAndOperators;
53 private boolean addControlSelectAllOption;
54 private boolean ranged;
55
56 public LookupInputField() {
57 super();
58 }
59
60
61
62
63
64
65
66
67
68
69 @Override
70 public void performFinalize(Object model, LifecycleElement parent) {
71 super.performFinalize(model, parent);
72
73
74 if (addControlSelectAllOption && (getControl() != null) && getControl() instanceof MultiValueControl) {
75 String allOptionText = KRADServiceLocatorWeb.getMessageService().getMessageText(
76 UifConstants.MessageKeys.OPTION_ALL);
77
78 MultiValueControl multiValueControl = (MultiValueControl) getControl();
79 if (multiValueControl.getOptions() != null) {
80 multiValueControl.getOptions().add(0, new ConcreteKeyValue("", allOptionText));
81 }
82
83 if (multiValueControl.getRichOptions() != null) {
84 Message message = ComponentFactory.getMessage();
85 message.setMessageText(allOptionText);
86 message.setRenderWrapperTag(false);
87
88 multiValueControl.getRichOptions().add(0, new KeyMessage("", allOptionText, message));
89 }
90 }
91 }
92
93
94
95
96
97
98
99
100
101
102 @Override
103 public void copyFromAttributeDefinition(AttributeDefinition attributeDefinition) {
104
105 if (StringUtils.isEmpty(getLabel())) {
106 setLabel(attributeDefinition.getLabel());
107 }
108
109
110 if (StringUtils.isEmpty(getShortLabel())) {
111 setShortLabel(attributeDefinition.getShortLabel());
112 }
113
114
115 if ((attributeDefinition.getAttributeSecurity() != null) && ((getDataFieldSecurity() == null) || (
116 getDataFieldSecurity().getAttributeSecurity() == null))) {
117 initializeComponentSecurity();
118
119 getDataFieldSecurity().setAttributeSecurity(attributeDefinition.getAttributeSecurity());
120 }
121
122
123 if (getOptionsFinder() == null) {
124 setOptionsFinder(attributeDefinition.getOptionsFinder());
125 }
126
127
128 if (getControl() == null) {
129 Control control = convertControlToLookupControl(attributeDefinition);
130 setControl(control);
131 }
132
133
134 setMaxLength(100);
135 if ( attributeDefinition.getMaxLength()!=null && (attributeDefinition.getMaxLength() > 100)) {
136 setMaxLength(attributeDefinition.getMaxLength());
137 }
138
139
140 if (getDefaultValue() == null || (getDefaultValue() instanceof String && StringUtils.isEmpty((String)getDefaultValue()))) {
141 if ((StringUtils.equals(getPropertyName(), KRADPropertyConstants.ACTIVE))) {
142 setDefaultValue(KRADConstants.YES_INDICATOR_VALUE);
143 }
144 }
145 }
146
147
148
149
150
151
152
153
154 protected static Control convertControlToLookupControl(AttributeDefinition attributeDefinition) {
155 if (attributeDefinition.getControlField() == null) {
156 return null;
157 }
158
159 Control newControl = null;
160
161
162 if (CheckboxControl.class.isAssignableFrom(attributeDefinition.getControlField().getClass())) {
163 newControl = (RadioGroupControl) ComponentFactory.getNewComponentInstance(
164 ComponentFactory.CHECKBOX_CONVERTED_RADIO_CONTROL);
165 }
166
167 else if (TextAreaControl.class.isAssignableFrom(attributeDefinition.getControlField().getClass())) {
168 newControl = ComponentFactory.getTextControl();
169 } else {
170 newControl = ComponentUtils.copy(attributeDefinition.getControlField(), "");
171 }
172
173 return newControl;
174 }
175
176
177
178
179
180
181
182 public Map<String, String> filterSearchCriteria(Map<String, String> searchCriteria) {
183 return searchCriteria;
184 }
185
186
187
188
189
190
191
192 @BeanTagAttribute(name = "disableWildcardsAndOperators")
193 public boolean isDisableWildcardsAndOperators() {
194 return this.disableWildcardsAndOperators;
195 }
196
197
198
199
200 public void setDisableWildcardsAndOperators(boolean disableWildcardsAndOperators) {
201 this.disableWildcardsAndOperators = disableWildcardsAndOperators;
202 }
203
204
205
206
207
208
209
210 @BeanTagAttribute(name = "addControlSelectAllOption")
211 public boolean isAddControlSelectAllOption() {
212 return addControlSelectAllOption;
213 }
214
215
216
217
218 public void setAddControlSelectAllOption(boolean addControlSelectAllOption) {
219 this.addControlSelectAllOption = addControlSelectAllOption;
220 }
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236 public boolean isRanged() {
237 return ranged;
238 }
239
240
241
242
243 public void setRanged(boolean ranged) {
244 this.ranged = ranged;
245 }
246 }