View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * This ia an override of the TableLayoutManager to not show the header and footer of the table.
59   *
60   * @author Kuali Student Team
61   */
62  public class SimpleTableLayoutManager extends TableLayoutManager {
63  
64      /**
65       * Setup the column calculations functionality and components
66       *
67       * @param view the view
68       * @param model the model
69       * @param container the parent container
70       * @param totalColumns total number of columns in the table
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       * Assembles the field instances for the collection line. The given sequence
81       * field prototype is copied for the line sequence field. Likewise a copy of
82       * the actionFieldPrototype is made and the given actions are set as the
83       * items for the action field. Finally the generated items are assembled
84       * together into the allRowFields list with the given lineFields.
85       *
86       * @see org.kuali.rice.krad.uif.layout.CollectionLayoutManager#buildLine(org.kuali.rice.krad.uif.view.View,
87       *      java.lang.Object, org.kuali.rice.krad.uif.container.CollectionGroup,
88       *      java.util.List, java.util.List, java.lang.String, java.util.List,
89       *      java.lang.String, java.lang.Object, int)
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          // since expressions are not evaluated on child components yet, we need to evaluate any properties
96          // we are going to read for building the table
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         // if first line for table set number of data columns
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         // do not allow null rowCss
137         if (rowCss == null) {
138             rowCss = "";
139         }
140 
141         rowCss = StringUtils.removeStart(rowCss, " ");
142         this.getRowCssClasses().add(rowCss);
143 
144         // set label field rendered to true on line fields and adjust cell properties
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         // select field will come after sequence field (if enabled) or be first column
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         // now add the fields in the correct position
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             //details action
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         // add sub-collection fields to end of data fields
194         this.getAllRowFields().addAll(subCollectionFields);
195     }
196 }