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 com.google.common.collect.Lists;
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
21 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
22 import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
23 import org.kuali.rice.krad.uif.UifConstants;
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.view.ExpressionEvaluator;
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
72 public void performApplyModel(View view, Object model, Component parent) {
73 super.performApplyModel(view, model, parent);
74
75 disabledExpression = this.getPropertyExpression("disabled");
76 if(disabledExpression != null){
77 ExpressionEvaluator expressionEvaluator =
78 view.getViewHelperService().getExpressionEvaluator();
79
80 disabledExpression = expressionEvaluator.replaceBindingPrefixes(view, this,
81 disabledExpression);
82 disabled = (Boolean) expressionEvaluator.evaluateExpression(this.getContext(), disabledExpression);
83 }
84 }
85
86
87
88
89
90
91
92
93
94 public void performFinalize(View view, Object model, Component parent) {
95 super.performApplyModel(view, model, parent);
96
97 ExpressionEvaluator expressionEvaluator =
98 view.getViewHelperService().getExpressionEvaluator();
99
100 if (StringUtils.isNotEmpty(disabledExpression) && !disabledExpression.equalsIgnoreCase("true")
101 && !disabledExpression.equalsIgnoreCase("false")) {
102 disabledConditionControlNames = new ArrayList<String>();
103 disabledConditionJs = ExpressionUtils.parseExpression(disabledExpression,
104 disabledConditionControlNames);
105 }
106
107 List<String> adjustedDisablePropertyNames = new ArrayList<String>();
108 for (String propertyName : disabledWhenChangedPropertyNames) {
109 adjustedDisablePropertyNames.add(expressionEvaluator.replaceBindingPrefixes(view, this,
110 propertyName));
111 }
112 disabledWhenChangedPropertyNames = adjustedDisablePropertyNames;
113
114 List<String> adjustedEnablePropertyNames = new ArrayList<String>();
115 for (String propertyName : enabledWhenChangedPropertyNames) {
116 adjustedEnablePropertyNames.add(expressionEvaluator.replaceBindingPrefixes(view, this,
117 propertyName));
118 }
119 enabledWhenChangedPropertyNames = adjustedEnablePropertyNames;
120
121
122 this.addDataAttribute(UifConstants.DataAttributes.ROLE, UifConstants.RoleTypes.CONTROL);
123 }
124
125
126
127
128 @Override
129 public final String getComponentTypeName() {
130 return "control";
131 }
132
133
134
135
136 @BeanTagAttribute(name="tabIndex")
137 public int getTabIndex() {
138 return this.tabIndex;
139 }
140
141
142
143
144 public void setTabIndex(int tabIndex) {
145 this.tabIndex = tabIndex;
146 }
147
148
149
150
151 @BeanTagAttribute(name="disabled")
152 public boolean isDisabled() {
153 return disabled;
154 }
155
156
157
158
159 public void setDisabled(boolean disabled) {
160 this.disabled = disabled;
161 }
162
163
164
165
166 @BeanTagAttribute(name="disabledReason")
167 public String getDisabledReason() {
168 return disabledReason;
169 }
170
171
172
173
174 public void setDisabledReason(String disabledReason) {
175 this.disabledReason = disabledReason;
176 }
177
178
179
180
181 @Override
182 public void completeValidation(ValidationTrace tracer){
183 tracer.addBean(this);
184
185 super.completeValidation(tracer.getCopy());
186 }
187
188
189
190
191
192
193
194 @BeanTagAttribute(name="evaluateDisabledOnKeyUp")
195 public boolean isEvaluateDisabledOnKeyUp() {
196 return evaluateDisabledOnKeyUp;
197 }
198
199
200
201
202
203
204 public void setEvaluateDisabledOnKeyUp(boolean evaluateDisabledOnKeyUp) {
205 this.evaluateDisabledOnKeyUp = evaluateDisabledOnKeyUp;
206 }
207
208
209
210
211
212
213 public String getDisabledConditionJs() {
214 return disabledConditionJs;
215 }
216
217
218
219
220
221
222 public List<String> getDisabledConditionControlNames() {
223 return disabledConditionControlNames;
224 }
225
226
227
228
229
230
231 @BeanTagAttribute(name="disabledWhenChangedPropertyNames",type= BeanTagAttribute.AttributeType.LISTVALUE)
232 public List<String> getDisabledWhenChangedPropertyNames() {
233 return disabledWhenChangedPropertyNames;
234 }
235
236
237
238
239
240
241 public void setDisabledWhenChangedPropertyNames(List<String> disabledWhenChangedPropertyNames) {
242 this.disabledWhenChangedPropertyNames = disabledWhenChangedPropertyNames;
243 }
244
245
246
247
248
249
250 @BeanTagAttribute(name="ensabledConditionControlNames",type= BeanTagAttribute.AttributeType.LISTVALUE)
251 public List<String> getEnabledWhenChangedPropertyNames() {
252 return enabledWhenChangedPropertyNames;
253 }
254
255
256
257
258
259
260 public void setEnabledWhenChangedPropertyNames(List<String> enabledWhenChangedPropertyNames) {
261 this.enabledWhenChangedPropertyNames = enabledWhenChangedPropertyNames;
262 }
263
264 public void setDisabledExpression(String disabledExpression) {
265 this.disabledExpression = disabledExpression;
266 }
267
268 public String getDisabledExpression() {
269 return disabledExpression;
270 }
271
272 public void setDisabledConditionJs(String disabledConditionJs) {
273 this.disabledConditionJs = disabledConditionJs;
274 }
275
276 public void setDisabledConditionControlNames(List<String> disabledConditionControlNames) {
277 this.disabledConditionControlNames = disabledConditionControlNames;
278 }
279
280
281
282
283 @Override
284 protected <T> void copyProperties(T component) {
285 super.copyProperties(component);
286 ControlBase controlBaseCopy = (ControlBase) component;
287 controlBaseCopy.setTabIndex(this.getTabIndex());
288 controlBaseCopy.setDisabled(this.isDisabled());
289 controlBaseCopy.setDisabledExpression(this.getDisabledExpression());
290 controlBaseCopy.setDisabledReason(this.getDisabledReason());
291 controlBaseCopy.setEvaluateDisabledOnKeyUp(this.isEvaluateDisabledOnKeyUp());
292 controlBaseCopy.setDisabledConditionJs(this.getDisabledConditionJs());
293
294 if (disabledConditionControlNames != null) {
295 List<String> disabledConditionControlNamesCopy = Lists.newArrayListWithExpectedSize(
296 disabledConditionControlNames.size());
297
298 for(String disabledConditionControlName : disabledConditionControlNames) {
299 disabledConditionControlNamesCopy.add(disabledConditionControlName);
300 }
301
302 controlBaseCopy.setDisabledConditionControlNames(disabledConditionControlNamesCopy);
303 }
304
305 if (disabledWhenChangedPropertyNames != null) {
306 List<String> disabledWhenChangedPropertyNamesCopy = Lists.newArrayListWithExpectedSize(disabledWhenChangedPropertyNames.size());
307
308 for(String disabledWhenChangedPropertyName : disabledWhenChangedPropertyNames) {
309 disabledWhenChangedPropertyNamesCopy.add(disabledWhenChangedPropertyName);
310 }
311
312 controlBaseCopy.setDisabledWhenChangedPropertyNames(disabledWhenChangedPropertyNamesCopy);
313 }
314
315 if (enabledWhenChangedPropertyNames != null) {
316 List<String> enabledWhenChangedPropertyNamesCopy = Lists.newArrayListWithExpectedSize(enabledWhenChangedPropertyNames.size());
317
318 for(String enabledWhenChangedPropertyName : enabledWhenChangedPropertyNames) {
319 enabledWhenChangedPropertyNamesCopy.add(enabledWhenChangedPropertyName);
320 }
321
322 controlBaseCopy.setEnabledWhenChangedPropertyNames(enabledWhenChangedPropertyNamesCopy);
323 }
324 }
325 }