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 java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.List;
21 import java.util.Map;
22 import java.util.Set;
23 import java.util.TreeMap;
24
25 import com.google.common.collect.Lists;
26 import org.apache.commons.lang.StringUtils;
27 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
28 import org.kuali.rice.krad.uif.CssConstants;
29 import org.kuali.rice.krad.uif.UifConstants;
30 import org.kuali.rice.krad.uif.UifPropertyPaths;
31 import org.kuali.rice.krad.uif.component.Component;
32 import org.kuali.rice.krad.uif.component.DataBinding;
33 import org.kuali.rice.krad.uif.container.CollectionGroup;
34 import org.kuali.rice.krad.uif.container.Container;
35 import org.kuali.rice.krad.uif.container.Group;
36 import org.kuali.rice.krad.uif.element.Action;
37 import org.kuali.rice.krad.uif.element.Label;
38 import org.kuali.rice.krad.uif.element.Message;
39 import org.kuali.rice.krad.uif.field.DataField;
40 import org.kuali.rice.krad.uif.field.Field;
41 import org.kuali.rice.krad.uif.field.FieldGroup;
42 import org.kuali.rice.krad.uif.field.InputField;
43 import org.kuali.rice.krad.uif.field.MessageField;
44 import org.kuali.rice.krad.uif.layout.CollectionLayoutManager;
45 import org.kuali.rice.krad.uif.layout.CollectionLayoutUtils;
46 import org.kuali.rice.krad.uif.layout.GridLayoutManager;
47 import org.kuali.rice.krad.uif.layout.TableLayoutManager;
48 import org.kuali.rice.krad.uif.util.ColumnCalculationInfo;
49 import org.kuali.rice.krad.uif.util.ComponentFactory;
50 import org.kuali.rice.krad.uif.util.ComponentUtils;
51 import org.kuali.rice.krad.uif.view.ExpressionEvaluator;
52 import org.kuali.rice.krad.uif.view.View;
53 import org.kuali.rice.krad.uif.widget.RichTable;
54 import org.kuali.rice.krad.util.KRADUtils;
55 import org.kuali.rice.krad.web.form.UifFormBase;
56
57
58
59
60
61
62 public class SimpleTableLayoutManager extends TableLayoutManager {
63
64
65
66
67
68
69
70
71
72 @Override
73 protected void setupColumnCalculations(View view, Object model, Container container, int totalColumns) {
74 if(this.getColumnCalculations().size()>0){
75 super.setupColumnCalculations(view, model, container, totalColumns);
76 }
77 }
78
79
80
81
82
83
84
85
86
87
88
89
90
91 public void buildLine(View view, Object model, CollectionGroup collectionGroup, List<Field> lineFields,
92 List<FieldGroup> subCollectionFields, String bindingPath, List<Action> actions, String idSuffix,
93 Object currentLine, int lineIndex) {
94
95
96
97 ExpressionEvaluator expressionEvaluator = view.getViewHelperService().getExpressionEvaluator();
98 for (Field lineField : lineFields) {
99 lineField.pushObjectToContext(UifConstants.ContextVariableNames.PARENT, collectionGroup);
100 lineField.pushAllToContext(view.getViewHelperService().getCommonContext(view, lineField));
101
102 expressionEvaluator.evaluatePropertyExpression(view, lineField.getContext(), lineField,
103 UifPropertyPaths.ROW_SPAN, true);
104 expressionEvaluator.evaluatePropertyExpression(view, lineField.getContext(), lineField,
105 UifPropertyPaths.COL_SPAN, true);
106 expressionEvaluator.evaluatePropertyExpression(view, lineField.getContext(), lineField,
107 UifPropertyPaths.REQUIRED, true);
108 expressionEvaluator.evaluatePropertyExpression(view, lineField.getContext(), lineField,
109 UifPropertyPaths.READ_ONLY, true);
110 }
111
112
113 if (this.getAllRowFields().isEmpty()) {
114 if (isSuppressLineWrapping()) {
115 setNumberOfDataColumns(lineFields.size());
116 } else {
117 setNumberOfDataColumns(getNumberOfColumns());
118 }
119 }
120
121 boolean isAddLine = false;
122
123 boolean renderActions = collectionGroup.isRenderLineActions() && !collectionGroup.isReadOnly();
124 int extraColumns = 0;
125 String rowCss = "";
126 boolean addLineInTable =
127 collectionGroup.isRenderAddLine() && !collectionGroup.isReadOnly() && !isSeparateAddLine();
128
129 if (collectionGroup.isHighlightNewItems() && ((UifFormBase) model).isAddedCollectionItem(currentLine)) {
130 rowCss = collectionGroup.getNewItemsCssClass();
131 } else if (isAddLine && addLineInTable) {
132 rowCss = collectionGroup.getAddItemCssClass();
133 this.addStyleClass(CssConstants.Classes.HAS_ADD_LINE);
134 }
135
136
137 if (rowCss == null) {
138 rowCss = "";
139 }
140
141 rowCss = StringUtils.removeStart(rowCss, " ");
142 this.getRowCssClasses().add(rowCss);
143
144
145 for (Field field : lineFields) {
146 field.setLabelRendered(true);
147 field.setFieldLabel(null);
148
149 setCellAttributes(field);
150 }
151
152 int rowCount = calculateNumberOfRows(lineFields);
153 int rowSpan = rowCount + subCollectionFields.size();
154
155
156 if (collectionGroup.isIncludeLineSelectionField()) {
157 Field selectField = ComponentUtils.copy(getSelectFieldPrototype(), idSuffix);
158 CollectionLayoutUtils.prepareSelectFieldForLine(selectField, collectionGroup, bindingPath, currentLine);
159
160 ComponentUtils.updateContextForLine(selectField, currentLine, lineIndex, idSuffix);
161 setCellAttributes(selectField);
162
163 this.getAllRowFields().add(selectField);
164
165 extraColumns++;
166 }
167
168
169 int cellPosition = 0;
170 int columnNumber = 0;
171
172 boolean insertActionField = false;
173
174 for (Field lineField : lineFields) {
175
176 cellPosition += lineField.getColSpan();
177 columnNumber++;
178
179 this.getAllRowFields().add(lineField);
180
181
182 if (lineField instanceof FieldGroup && ((FieldGroup) lineField).getItems() != null) {
183 for (Component component : ((FieldGroup) lineField).getItems()) {
184 if (component != null && component instanceof Action && component.getDataAttributes().get("role")
185 != null && component.getDataAttributes().get("role").equals("detailsLink") &&
186 StringUtils.isBlank(((Action) component).getActionScript())) {
187 ((Action) component).setActionScript("rowDetailsActionHandler(this,'" + this.getId() + "');");
188 }
189 }
190 }
191 }
192
193
194 this.getAllRowFields().addAll(subCollectionFields);
195 }
196 }