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