001package org.kuali.rice.krad.uif.layout.extension; 002 003import java.util.List; 004 005import org.kuali.rice.krad.uif.component.Component; 006import org.kuali.rice.krad.uif.container.CollectionGroup; 007import org.kuali.rice.krad.uif.container.collections.LineBuilderContext; 008import org.kuali.rice.krad.uif.field.Field; 009import org.kuali.rice.krad.uif.field.FieldGroup; 010import org.kuali.rice.krad.uif.layout.TableLayoutManagerBase; 011import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle; 012import org.kuali.rice.krad.uif.view.View; 013import org.kuali.student.ap.coursesearch.dataobject.ActivityOfferingItem; 014import org.kuali.student.r2.common.util.constants.LuiServiceConstants; 015import org.slf4j.Logger; 016import org.slf4j.LoggerFactory; 017 018/** 019 * Layout manager for controlling and optimizing section details presentation. 020 */ 021public class CourseSectionDetailsLayoutManager extends TableLayoutManagerBase { 022 023 private static final long serialVersionUID = 3056313875988089648L; 024 025 private static final Logger LOG = LoggerFactory.getLogger(CourseSectionDetailsLayoutManager.class); 026 027 @Override 028 public void buildLine(LineBuilderContext lineBuilderContext) { 029 int lineIndex = lineBuilderContext.getLineIndex(); 030 Object currentLine = lineBuilderContext.getCurrentLine(); 031 032 super.buildLine(lineBuilderContext); 033 034 // This logic replaces onDocumentReadyScript entries previously in 035 // CourseDetailsUI.xml by assigning the correct CSS class to table rows 036 // at rendering time, rather than relying on the browser to query for 037 // and assign classes on document ready. 038 if (lineIndex != -1 && (currentLine instanceof ActivityOfferingItem)) { 039 ActivityOfferingItem aoi = (ActivityOfferingItem) currentLine; 040 List<String> rowCss = getRowCssClasses(); 041 rowCss.remove(rowCss.size() - 1); // super adds a row, remove it 042 StringBuilder r1css = new StringBuilder(); 043 r1css.append("row"); 044 r1css.append(aoi.isPrimary() ? " primary" : " secondary"); 045 boolean offered = LuiServiceConstants.LUI_AO_STATE_OFFERED_KEY 046 .equals(aoi.getStateKey()); 047 StringBuilder r2css = offered ? new StringBuilder() : null; 048 if (offered && !aoi.isPrimary()) 049 r2css.append("collapsible"); 050 if (aoi.getPlanItemId() != null) { 051 r1css.append(r1css.length() == 0 ? " " : "").append( 052 "ksap-section-planned"); 053 if (offered) 054 r2css.append(r2css.length() == 0 ? " " : "").append( 055 "ksap-section-planned"); 056 } 057 rowCss.add(r1css.toString()); 058 if (offered) { 059 rowCss.add(r2css.toString()); 060 rowCss.add(r2css.toString()); 061 } 062 if (LOG.isDebugEnabled()) { 063 LOG.debug("AO luiId {} lineIndex = {} css(1) {} css(2,3) {}", 064 aoi.getLuiId(), lineIndex, r1css, r2css); 065 } 066 } 067 } 068 069 /** 070 * This method is written to override the default colSpan calculation done 071 * in TableLayoutManager. If this LayoutManager is used, it will rely on the 072 * row span and col spans set in the XML and not try to calculate the last 073 * column col span on its own 074 * 075 * Temporary fix for KULRICE-9215 076 * 077 * @Author kmuthu Date: 3/28/13 078 */ 079 @Override 080 protected int calculateNumberOfRows(List<? extends Field> items) { 081 int rowCount = 0; 082 083 // check flag that indicates only one row should be created 084 if (isSuppressLineWrapping()) { 085 return 1; 086 } 087 088 if (items.size() % getNumberOfDataColumns() > 0) { 089 rowCount = ((items.size() / getNumberOfDataColumns()) + 1); 090 } else { 091 rowCount = items.size() / getNumberOfDataColumns(); 092 } 093 return rowCount; 094 } 095}