1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.core.krms;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.uif.UifConstants;
20 import org.kuali.rice.krad.uif.component.Component;
21 import org.kuali.rice.krad.uif.component.DataBinding;
22 import org.kuali.rice.krad.uif.container.CollectionGroup;
23 import org.kuali.rice.krad.uif.container.Container;
24 import org.kuali.rice.krad.uif.container.Group;
25 import org.kuali.rice.krad.uif.element.Action;
26 import org.kuali.rice.krad.uif.field.Field;
27 import org.kuali.rice.krad.uif.field.FieldGroup;
28 import org.kuali.rice.krad.uif.layout.StackedLayoutManager;
29 import org.kuali.rice.krad.uif.util.ComponentUtils;
30 import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
31 import org.kuali.rice.krad.uif.view.View;
32 import org.kuali.rice.krad.web.form.UifFormBase;
33
34 import java.util.ArrayList;
35 import java.util.List;
36 import java.util.Map;
37
38
39
40
41 public class HorizontalActionsStackedLayoutManager extends StackedLayoutManager {
42
43 @Override
44 public void buildLine(View view, Object model, CollectionGroup collectionGroup, List<Field> lineFields,
45 List<FieldGroup> subCollectionFields, String bindingPath, List<Action> actions, String idSuffix,
46 Object currentLine, int lineIndex) {
47
48 boolean isAddLine = lineIndex == -1;
49
50
51 Group lineGroup = null;
52 if (isAddLine) {
53 setStackedGroups(new ArrayList<Group>());
54
55 if (this.getAddLineGroup() == null) {
56 lineGroup = ComponentUtils.copy(this.getLineGroupPrototype(), idSuffix);
57 } else {
58 lineGroup = ComponentUtils.copy(getAddLineGroup(), idSuffix);
59 lineGroup.addStyleClass(collectionGroup.getAddItemCssClass());
60 }
61
62 if (collectionGroup.isAddViaLightBox()) {
63 String actionScript = "showLightboxComponent('" + lineGroup.getId() + "');";
64 if (StringUtils.isNotBlank(collectionGroup.getAddViaLightBoxAction().getActionScript())) {
65 actionScript = collectionGroup.getAddViaLightBoxAction().getActionScript() + actionScript;
66 }
67 collectionGroup.getAddViaLightBoxAction().setActionScript(actionScript);
68 lineGroup.setStyle("display: none");
69 }
70 } else {
71 lineGroup = ComponentUtils.copy(this.getLineGroupPrototype(), idSuffix);
72 }
73
74 if (((UifFormBase) model).isAddedCollectionItem(currentLine)) {
75 lineGroup.addStyleClass(collectionGroup.getNewItemsCssClass());
76 }
77
78 ComponentUtils.updateContextForLine(lineGroup, currentLine, lineIndex, idSuffix);
79
80
81 String headerText = "";
82 if (isAddLine) {
83 headerText = collectionGroup.getAddLabel();
84 } else {
85
86 List<Object> modelCollection = ObjectPropertyUtils.getPropertyValue(model,
87 ((DataBinding) collectionGroup).getBindingInfo().getBindingPath());
88
89 headerText = buildLineHeaderText(view, modelCollection.get(lineIndex), lineGroup);
90 }
91
92
93 if (StringUtils.isNotBlank(headerText) && lineGroup.getHeader() != null) {
94 lineGroup.getHeader().setHeaderText(headerText);
95 }
96
97
98 List<Component> groupFields = new ArrayList<Component>();
99 groupFields.addAll(lineFields);
100
101
102 if (collectionGroup.isRenderLineActions() && !collectionGroup.isReadOnly() && (lineGroup.getFooter() != null)) {
103
104
105 if (isActionsInLineGroup()) {
106 groupFields.addAll(actions);
107 groupFields.addAll(subCollectionFields);
108 lineGroup.setRenderFooter(false);
109 }else{
110 List<Component> footerFields = new ArrayList<Component>();
111 footerFields.addAll(actions);
112 footerFields.addAll(subCollectionFields);
113 lineGroup.getFooter().setItems(footerFields);
114 }
115 }
116
117 lineGroup.setItems(groupFields);
118 this.getStackedGroups().add(lineGroup);
119
120 if (lineIndex == -1) {
121 String nodePath = this.getNodePath(this.getContext());
122 if (nodePath != null) {
123 for (Group group : this.getStackedGroups()) {
124
125 ComponentUtils.pushObjectToContext(group, UifConstants.ContextVariableNames.NODE_PATH, nodePath);
126 }
127 }
128 }
129
130 }
131
132 private String getNodePath(Map<String, Object> context) {
133 if (context.containsKey(UifConstants.ContextVariableNames.NODE_PATH)) {
134 return (String) context.get(UifConstants.ContextVariableNames.NODE_PATH);
135
136 } else if (context.containsKey(UifConstants.ContextVariableNames.PARENT)) {
137 Component parent = (Component) context.get(UifConstants.ContextVariableNames.PARENT);
138 return this.getNodePath(parent.getContext());
139 }
140 return null;
141 }
142
143 }