1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.layout;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
20 import org.kuali.rice.krad.uif.UifConstants;
21 import org.kuali.rice.krad.uif.UifPropertyPaths;
22 import org.kuali.rice.krad.uif.component.DataBinding;
23 import org.kuali.rice.krad.uif.container.CollectionGroup;
24 import org.kuali.rice.krad.uif.control.Control;
25 import org.kuali.rice.krad.uif.control.ValueConfiguredControl;
26 import org.kuali.rice.krad.uif.field.InputField;
27 import org.kuali.rice.krad.uif.field.Field;
28 import org.kuali.rice.krad.util.KRADUtils;
29
30
31
32
33
34
35 public class CollectionLayoutUtils {
36
37 public static void prepareSelectFieldForLine(Field selectField, CollectionGroup collectionGroup, String lineBindingPath,
38 Object line) {
39
40 String selectPropertyName = collectionGroup.getSelectPropertyName();
41 if (StringUtils.isNotBlank(selectPropertyName)) {
42
43 if (selectPropertyName.startsWith(UifConstants.NO_BIND_ADJUST_PREFIX)) {
44 selectPropertyName = StringUtils.removeStart(selectPropertyName, UifConstants.NO_BIND_ADJUST_PREFIX);
45 ((DataBinding) selectField).getBindingInfo().setBindingName(selectPropertyName);
46 ((DataBinding) selectField).getBindingInfo().setBindToForm(true);
47
48 setControlValueToLineIdentifier(selectField, line);
49 } else {
50 ((DataBinding) selectField).getBindingInfo().setBindingName(selectPropertyName);
51 ((DataBinding) selectField).getBindingInfo().setBindByNamePrefix(lineBindingPath);
52 }
53 } else {
54
55 String collectionLineKey = KRADUtils.translateToMapSafeKey(
56 collectionGroup.getBindingInfo().getBindingPath());
57 String selectBindingPath = UifPropertyPaths.SELECTED_COLLECTION_LINES + "['" + collectionLineKey + "']";
58
59 ((DataBinding) selectField).getBindingInfo().setBindingName(selectBindingPath);
60 ((DataBinding) selectField).getBindingInfo().setBindToForm(true);
61
62 setControlValueToLineIdentifier(selectField, line);
63 }
64 }
65
66 protected static void setControlValueToLineIdentifier(Field selectField, Object line) {
67 if (selectField instanceof InputField) {
68 Control selectControl = ((InputField) selectField).getControl();
69
70 selectControl.addStyleClass("kr-select-line");
71
72 if ((selectControl != null) && (selectControl instanceof ValueConfiguredControl)) {
73 String lineIdentifier =
74 KRADServiceLocatorWeb.getDataObjectMetaDataService().getDataObjectIdentifierString(line);
75 ((ValueConfiguredControl) selectControl).setValue(lineIdentifier);
76 }
77 }
78 }
79 }