1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.control;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21 import org.kuali.rice.krad.datadictionary.validator.ErrorReport;
22 import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
23 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
24 import org.kuali.rice.krad.uif.component.Component;
25 import org.kuali.rice.krad.uif.element.ContentElementBase;
26 import org.kuali.rice.krad.uif.service.ExpressionEvaluatorService;
27 import org.kuali.rice.krad.uif.util.ExpressionUtils;
28 import org.kuali.rice.krad.uif.view.View;
29
30 import java.util.ArrayList;
31 import java.util.List;
32
33
34
35
36
37
38
39 @BeanTag(name = "controlBase-bean", parent = "Uif-ControlBase")
40 public abstract class ControlBase extends ContentElementBase implements Control {
41 private static final long serialVersionUID = -7898244978136312663L;
42
43 private int tabIndex;
44
45 private boolean disabled;
46 private String disabledExpression;
47 private String disabledReason;
48 private boolean evaluateDisabledOnKeyUp;
49
50 private String disabledConditionJs;
51 private List<String> disabledConditionControlNames;
52
53 private List<String> disabledWhenChangedPropertyNames;
54 private List<String> enabledWhenChangedPropertyNames;
55
56 public ControlBase() {
57 super();
58
59 disabled = false;
60 disabledWhenChangedPropertyNames = new ArrayList<String>();
61 enabledWhenChangedPropertyNames = new ArrayList<String>();
62 }
63
64
65
66
67
68
69
70
71 public void performApplyModel(View view, Object model, Component parent) {
72 super.performApplyModel(view, model, parent);
73
74 disabledExpression = this.getPropertyExpression("disabled");
75 if(disabledExpression != null){
76 ExpressionEvaluatorService expressionEvaluatorService =
77 KRADServiceLocatorWeb.getExpressionEvaluatorService();
78 disabledExpression = expressionEvaluatorService.replaceBindingPrefixes(view, this,
79 disabledExpression);
80 disabled = (Boolean) expressionEvaluatorService.evaluateExpression(model, this.getContext(),
81 disabledExpression);
82 }
83 }
84
85
86
87
88
89
90
91
92
93 public void performFinalize(View view, Object model, Component parent) {
94 super.performApplyModel(view, model, parent);
95
96 if (StringUtils.isNotEmpty(disabledExpression) && !disabledExpression.equalsIgnoreCase("true")
97 && !disabledExpression.equalsIgnoreCase("false")) {
98 disabledConditionControlNames = new ArrayList<String>();
99 disabledConditionJs = ExpressionUtils.parseExpression(disabledExpression,
100 disabledConditionControlNames);
101 }
102
103 List<String> adjustedDisablePropertyNames = new ArrayList<String>();
104 for (String propertyName : disabledWhenChangedPropertyNames) {
105 adjustedDisablePropertyNames.add(
106 KRADServiceLocatorWeb.getExpressionEvaluatorService().replaceBindingPrefixes(view, this,
107 propertyName));
108 }
109 disabledWhenChangedPropertyNames = adjustedDisablePropertyNames;
110
111 List<String> adjustedEnablePropertyNames = new ArrayList<String>();
112 for (String propertyName : enabledWhenChangedPropertyNames) {
113 adjustedEnablePropertyNames.add(
114 KRADServiceLocatorWeb.getExpressionEvaluatorService().replaceBindingPrefixes(view, this,
115 propertyName));
116 }
117 enabledWhenChangedPropertyNames = adjustedEnablePropertyNames;
118 }
119
120
121
122
123 @Override
124 public final String getComponentTypeName() {
125 return "control";
126 }
127
128
129
130
131 @BeanTagAttribute(name="tabIndex")
132 public int getTabIndex() {
133 return this.tabIndex;
134 }
135
136
137
138
139 public void setTabIndex(int tabIndex) {
140 this.tabIndex = tabIndex;
141 }
142
143
144
145
146 @BeanTagAttribute(name="disabled")
147 public boolean isDisabled() {
148 return disabled;
149 }
150
151
152
153
154 public void setDisabled(boolean disabled) {
155 this.disabled = disabled;
156 }
157
158
159
160
161 @BeanTagAttribute(name="disabledReason")
162 public String getDisabledReason() {
163 return disabledReason;
164 }
165
166
167
168
169 public void setDisabledReason(String disabledReason) {
170 this.disabledReason = disabledReason;
171 }
172
173
174
175
176
177
178
179
180
181
182
183
184 @Override
185 public String getComplexDataAttributesJs() {
186
187
188
189
190
191
192
193
194
195 return super.getAllDataAttributesJs();
196 }
197
198
199
200
201 @Override
202 public void completeValidation(ValidationTrace tracer){
203 tracer.addBean(this);
204
205 super.completeValidation(tracer.getCopy());
206 }
207
208
209
210
211
212
213
214 @BeanTagAttribute(name="evaluateDisabledOnKeyUp")
215 public boolean isEvaluateDisabledOnKeyUp() {
216 return evaluateDisabledOnKeyUp;
217 }
218
219
220
221
222
223
224 public void setEvaluateDisabledOnKeyUp(boolean evaluateDisabledOnKeyUp) {
225 this.evaluateDisabledOnKeyUp = evaluateDisabledOnKeyUp;
226 }
227
228
229
230
231
232
233 public String getDisabledConditionJs() {
234 return disabledConditionJs;
235 }
236
237
238
239
240
241
242 public List<String> getDisabledConditionControlNames() {
243 return disabledConditionControlNames;
244 }
245
246
247
248
249
250
251 @BeanTagAttribute(name="disabledWhenChangedPropertyNames",type= BeanTagAttribute.AttributeType.LISTVALUE)
252 public List<String> getDisabledWhenChangedPropertyNames() {
253 return disabledWhenChangedPropertyNames;
254 }
255
256
257
258
259
260
261 public void setDisabledWhenChangedPropertyNames(List<String> disabledWhenChangedPropertyNames) {
262 this.disabledWhenChangedPropertyNames = disabledWhenChangedPropertyNames;
263 }
264
265
266
267
268
269
270 @BeanTagAttribute(name="ensabledConditionControlNames",type= BeanTagAttribute.AttributeType.LISTVALUE)
271 public List<String> getEnabledWhenChangedPropertyNames() {
272 return enabledWhenChangedPropertyNames;
273 }
274
275
276
277
278
279
280 public void setEnabledWhenChangedPropertyNames(List<String> enabledWhenChangedPropertyNames) {
281 this.enabledWhenChangedPropertyNames = enabledWhenChangedPropertyNames;
282 }
283 }