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