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