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