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 | 0 | public class CollectionLayoutUtils { |
36 | |
|
37 | |
public static void prepareSelectFieldForLine(Field selectField, CollectionGroup collectionGroup, String lineBindingPath, |
38 | |
Object line) { |
39 | |
|
40 | 0 | String selectPropertyName = collectionGroup.getSelectPropertyName(); |
41 | 0 | if (StringUtils.isNotBlank(selectPropertyName)) { |
42 | |
|
43 | 0 | if (selectPropertyName.startsWith(UifConstants.NO_BIND_ADJUST_PREFIX)) { |
44 | 0 | selectPropertyName = StringUtils.removeStart(selectPropertyName, UifConstants.NO_BIND_ADJUST_PREFIX); |
45 | 0 | ((DataBinding) selectField).getBindingInfo().setBindingName(selectPropertyName); |
46 | 0 | ((DataBinding) selectField).getBindingInfo().setBindToForm(true); |
47 | |
|
48 | 0 | setControlValueToLineIdentifier(selectField, line); |
49 | |
} else { |
50 | 0 | ((DataBinding) selectField).getBindingInfo().setBindingName(selectPropertyName); |
51 | 0 | ((DataBinding) selectField).getBindingInfo().setBindByNamePrefix(lineBindingPath); |
52 | |
} |
53 | |
} else { |
54 | |
|
55 | 0 | String collectionLineKey = KRADUtils.translateToMapSafeKey( |
56 | |
collectionGroup.getBindingInfo().getBindingPath()); |
57 | 0 | String selectBindingPath = UifPropertyPaths.SELECTED_COLLECTION_LINES + "['" + collectionLineKey + "']"; |
58 | |
|
59 | 0 | ((DataBinding) selectField).getBindingInfo().setBindingName(selectBindingPath); |
60 | 0 | ((DataBinding) selectField).getBindingInfo().setBindToForm(true); |
61 | |
|
62 | 0 | setControlValueToLineIdentifier(selectField, line); |
63 | |
} |
64 | 0 | } |
65 | |
|
66 | |
protected static void setControlValueToLineIdentifier(Field selectField, Object line) { |
67 | 0 | if (selectField instanceof InputField) { |
68 | 0 | Control selectControl = ((InputField) selectField).getControl(); |
69 | |
|
70 | 0 | selectControl.addStyleClass("kr-select-line"); |
71 | |
|
72 | 0 | if ((selectControl != null) && (selectControl instanceof ValueConfiguredControl)) { |
73 | 0 | String lineIdentifier = |
74 | |
KRADServiceLocatorWeb.getDataObjectMetaDataService().getDataObjectIdentifierString(line); |
75 | 0 | ((ValueConfiguredControl) selectControl).setValue(lineIdentifier); |
76 | |
} |
77 | |
} |
78 | 0 | } |
79 | |
} |