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.MultiValueControl;
28 import org.kuali.rice.krad.uif.control.RadioGroupControl;
29 import org.kuali.rice.krad.uif.control.TextAreaControl;
30 import org.kuali.rice.krad.uif.util.ComponentFactory;
31 import org.kuali.rice.krad.uif.util.ComponentUtils;
32 import org.kuali.rice.krad.uif.view.View;
33 import org.kuali.rice.krad.util.KRADConstants;
34 import org.kuali.rice.krad.util.KRADPropertyConstants;
35
36 import java.util.ArrayList;
37 import java.util.List;
38
39
40
41
42
43
44 @BeanTag(name="lookupInputField")
45 public class LookupInputField extends InputField {
46 private static final long serialVersionUID = -8294275596836322699L;
47
48 private boolean disableWildcardsAndOperators;
49 private boolean addControlSelectAllOption;
50
51 public LookupInputField() {
52 super();
53
54 disableWildcardsAndOperators = false;
55 addControlSelectAllOption = false;
56 }
57
58
59
60
61
62
63
64
65
66
67
68 @Override
69 public void performFinalize(View view, Object model, Component parent) {
70 super.performFinalize(view, model, parent);
71
72
73 if (addControlSelectAllOption && (getControl() != null) && getControl() instanceof MultiValueControl) {
74 MultiValueControl multiValueControl = (MultiValueControl) getControl();
75 if (multiValueControl.getOptions() != null) {
76 List<KeyValue> fieldOptions = multiValueControl.getOptions();
77 fieldOptions.add(0, new ConcreteKeyValue("", "All"));
78
79 multiValueControl.setOptions(fieldOptions);
80 }
81 }
82 }
83
84
85
86
87
88
89
90
91
92 @Override
93 public void copyFromAttributeDefinition(View view, AttributeDefinition attributeDefinition) {
94
95 if (StringUtils.isEmpty(getLabel())) {
96 setLabel(attributeDefinition.getLabel());
97 }
98
99
100 if (StringUtils.isEmpty(getShortLabel())) {
101 setShortLabel(attributeDefinition.getShortLabel());
102 }
103
104
105 if (getDataFieldSecurity().getAttributeSecurity() == null) {
106 getDataFieldSecurity().setAttributeSecurity(attributeDefinition.getAttributeSecurity());
107 }
108
109
110 if (getOptionsFinder() == null) {
111 setOptionsFinder(attributeDefinition.getOptionsFinder());
112 }
113
114
115
116
117 if (getControl() == null) {
118 Control control = convertControlToLookupControl(attributeDefinition);
119 view.assignComponentIds(control);
120
121 setControl(control);
122 }
123
124
125 setMaxLength(100);
126
127
128 if (StringUtils.isEmpty(getDefaultValue())) {
129 if ((StringUtils.equals(getPropertyName(), KRADPropertyConstants.ACTIVE))) {
130 setDefaultValue(KRADConstants.YES_INDICATOR_VALUE);
131 }
132 }
133
134
135
136
137
138
139 }
140
141
142
143
144
145
146
147
148 protected static Control convertControlToLookupControl(AttributeDefinition attributeDefinition) {
149 if (attributeDefinition.getControlField() == null) {
150 return null;
151 }
152
153 Control newControl = null;
154
155
156 if (CheckboxControl.class.isAssignableFrom(attributeDefinition.getControlField().getClass())) {
157 newControl = ComponentFactory.getRadioGroupControlHorizontal();
158 List<KeyValue> options = new ArrayList<KeyValue>();
159 options.add(new ConcreteKeyValue("Y", "Yes"));
160 options.add(new ConcreteKeyValue("N", "No"));
161 options.add(new ConcreteKeyValue("", "Both"));
162
163 ((RadioGroupControl) newControl).setOptions(options);
164 }
165
166 else if (TextAreaControl.class.isAssignableFrom(attributeDefinition.getControlField().getClass())) {
167 newControl = ComponentFactory.getTextControl();
168 } else {
169 newControl = ComponentUtils.copy(attributeDefinition.getControlField(), "");
170 }
171
172 return newControl;
173 }
174
175
176
177
178 @BeanTagAttribute(name="disableWildcardsAndOperators")
179 public boolean isDisableWildcardsAndOperators() {
180 return this.disableWildcardsAndOperators;
181 }
182
183
184
185
186 public void setDisableWildcardsAndOperators(boolean disableWildcardsAndOperators) {
187 this.disableWildcardsAndOperators = disableWildcardsAndOperators;
188 }
189
190
191
192
193
194
195
196 @BeanTagAttribute(name="addControlSelectAllOption")
197 public boolean isAddControlSelectAllOption() {
198 return addControlSelectAllOption;
199 }
200
201
202
203
204
205
206 public void setAddControlSelectAllOption(boolean addControlSelectAllOption) {
207 this.addControlSelectAllOption = addControlSelectAllOption;
208 }
209 }