View Javadoc
1   package org.kuali.rice.krad.uif.layout.extension;
2   
3   import java.util.List;
4   
5   import org.kuali.rice.krad.uif.component.Component;
6   import org.kuali.rice.krad.uif.container.CollectionGroup;
7   import org.kuali.rice.krad.uif.container.collections.LineBuilderContext;
8   import org.kuali.rice.krad.uif.field.Field;
9   import org.kuali.rice.krad.uif.field.FieldGroup;
10  import org.kuali.rice.krad.uif.layout.TableLayoutManagerBase;
11  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
12  import org.kuali.rice.krad.uif.view.View;
13  import org.kuali.student.ap.coursesearch.dataobject.ActivityOfferingItem;
14  import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
15  import org.slf4j.Logger;
16  import org.slf4j.LoggerFactory;
17  
18  /**
19   * Layout manager for controlling and optimizing section details presentation.
20   */
21  public class CourseSectionDetailsLayoutManager extends TableLayoutManagerBase {
22  
23  	private static final long serialVersionUID = 3056313875988089648L;
24  
25  	private static final Logger LOG = LoggerFactory.getLogger(CourseSectionDetailsLayoutManager.class);
26  
27  	@Override
28  	public void buildLine(LineBuilderContext lineBuilderContext) {
29          int lineIndex = lineBuilderContext.getLineIndex();
30          Object currentLine = lineBuilderContext.getCurrentLine();
31  
32  		super.buildLine(lineBuilderContext);
33  
34  		// This logic replaces onDocumentReadyScript entries previously in
35  		// CourseDetailsUI.xml by assigning the correct CSS class to table rows
36  		// at rendering time, rather than relying on the browser to query for
37  		// and assign classes on document ready.
38  		if (lineIndex != -1 && (currentLine instanceof ActivityOfferingItem)) {
39  			ActivityOfferingItem aoi = (ActivityOfferingItem) currentLine;
40  			List<String> rowCss = getRowCssClasses();
41  			rowCss.remove(rowCss.size() - 1); // super adds a row, remove it
42  			StringBuilder r1css = new StringBuilder();
43  			r1css.append("row");
44  			r1css.append(aoi.isPrimary() ? " primary" : " secondary");
45  			boolean offered = LuiServiceConstants.LUI_AO_STATE_OFFERED_KEY
46  					.equals(aoi.getStateKey());
47  			StringBuilder r2css = offered ? new StringBuilder() : null;
48  			if (offered && !aoi.isPrimary())
49  				r2css.append("collapsible");
50  			if (aoi.getPlanItemId() != null) {
51  				r1css.append(r1css.length() == 0 ? " " : "").append(
52  						"ksap-section-planned");
53  				if (offered)
54  					r2css.append(r2css.length() == 0 ? " " : "").append(
55  							"ksap-section-planned");
56  			}
57  			rowCss.add(r1css.toString());
58  			if (offered) {
59  				rowCss.add(r2css.toString());
60  				rowCss.add(r2css.toString());
61  			}
62  			if (LOG.isDebugEnabled()) {
63  				LOG.debug("AO luiId {} lineIndex = {} css(1) {} css(2,3) {}",
64                          aoi.getLuiId(), lineIndex, r1css, r2css);
65              }
66  		}
67  	}
68  
69  	/**
70  	 * This method is written to override the default colSpan calculation done
71  	 * in TableLayoutManager. If this LayoutManager is used, it will rely on the
72  	 * row span and col spans set in the XML and not try to calculate the last
73  	 * column col span on its own
74  	 * 
75  	 * Temporary fix for KULRICE-9215
76  	 * 
77  	 * @Author kmuthu Date: 3/28/13
78  	 */
79  	@Override
80  	protected int calculateNumberOfRows(List<? extends Field> items) {
81  		int rowCount = 0;
82  
83  		// check flag that indicates only one row should be created
84  		if (isSuppressLineWrapping()) {
85  			return 1;
86  		}
87  
88  		if (items.size() % getNumberOfDataColumns() > 0) {
89  			rowCount = ((items.size() / getNumberOfDataColumns()) + 1);
90  		} else {
91  			rowCount = items.size() / getNumberOfDataColumns();
92  		}
93  		return rowCount;
94  	}
95  }