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.control.CheckboxControl;
23 import org.kuali.rice.krad.uif.control.Control;
24 import org.kuali.rice.krad.uif.control.RadioGroupControl;
25 import org.kuali.rice.krad.uif.control.TextAreaControl;
26 import org.kuali.rice.krad.uif.util.ComponentFactory;
27 import org.kuali.rice.krad.uif.util.ComponentUtils;
28 import org.kuali.rice.krad.uif.view.View;
29 import org.kuali.rice.krad.util.KRADConstants;
30 import org.kuali.rice.krad.util.KRADPropertyConstants;
31
32 import java.util.ArrayList;
33 import java.util.List;
34
35
36
37
38
39
40 public class LookupInputField extends InputField {
41 private static final long serialVersionUID = -8294275596836322699L;
42
43 protected boolean treatWildcardsAndOperatorsAsLiteral = false;
44
45 public LookupInputField() {
46 super();
47 }
48
49
50
51
52 public boolean isTreatWildcardsAndOperatorsAsLiteral() {
53 return this.treatWildcardsAndOperatorsAsLiteral;
54 }
55
56
57
58
59 public void setTreatWildcardsAndOperatorsAsLiteral(boolean treatWildcardsAndOperatorsAsLiteral) {
60 this.treatWildcardsAndOperatorsAsLiteral = treatWildcardsAndOperatorsAsLiteral;
61 }
62
63
64
65
66
67
68
69
70 @Override
71 public void copyFromAttributeDefinition(View view, AttributeDefinition attributeDefinition) {
72
73 if (StringUtils.isEmpty(getLabel())) {
74 setLabel(attributeDefinition.getLabel());
75 }
76
77
78 if (StringUtils.isEmpty(getShortLabel())) {
79 setShortLabel(attributeDefinition.getShortLabel());
80 }
81
82
83 if (getAttributeSecurity() == null) {
84 setAttributeSecurity(attributeDefinition.getAttributeSecurity());
85 }
86
87
88 if (getOptionsFinder() == null) {
89 setOptionsFinder(attributeDefinition.getOptionsFinder());
90 }
91
92
93
94
95 if (getControl() == null) {
96 Control control = convertControlToLookupControl(attributeDefinition);
97 view.assignComponentIds(control);
98
99 setControl(control);
100 }
101
102
103 setMaxLength(100);
104
105
106 if (StringUtils.isEmpty(getDefaultValue())) {
107 if ((StringUtils.equals(getPropertyName(), KRADPropertyConstants.ACTIVE))) {
108 setDefaultValue(KRADConstants.YES_INDICATOR_VALUE);
109 }
110 }
111
112
113
114
115
116
117 }
118
119
120
121
122
123
124
125
126 protected static Control convertControlToLookupControl(AttributeDefinition attributeDefinition) {
127 if (attributeDefinition.getControlField() == null) {
128 return null;
129 }
130
131 Control newControl = null;
132
133
134 if (CheckboxControl.class.isAssignableFrom(attributeDefinition.getControlField().getClass())) {
135 newControl = ComponentFactory.getRadioGroupControlHorizontal();
136 List<KeyValue> options = new ArrayList<KeyValue>();
137 options.add(new ConcreteKeyValue("Y", "Yes"));
138 options.add(new ConcreteKeyValue("N", "No"));
139 options.add(new ConcreteKeyValue("", "Both"));
140
141 ((RadioGroupControl) newControl).setOptions(options);
142 }
143
144 else if (TextAreaControl.class.isAssignableFrom(attributeDefinition.getControlField().getClass())) {
145 newControl = ComponentFactory.getTextControl();
146 } else {
147 newControl = ComponentUtils.copy(attributeDefinition.getControlField(), "");
148 }
149
150 return newControl;
151 }
152 }