1 /** 2 * Copyright 2005-2015 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.rice.krad.uif.layout; 17 18 import org.kuali.rice.krad.datadictionary.parse.BeanTag; 19 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute; 20 import org.kuali.rice.krad.uif.component.Component; 21 import org.kuali.rice.krad.uif.container.Container; 22 import org.kuali.rice.krad.uif.util.LifecycleElement; 23 24 import java.util.ArrayList; 25 import java.util.List; 26 27 /** 28 * Css Grid Layout manager is a layout manager which creates div "rows" and "cells" to replicate a 29 * table look by using div elements for its items. 30 * 31 * <p> 32 * Items are added into rows based on their colSpan 33 * setting, while each row has a max size of 12 columns. By default, if colSpan is not set on an 34 * item, that item will take a full row. 35 * </p> 36 * 37 * @author Kuali Rice Team (rice.collab@kuali.org) 38 */ 39 @BeanTag(name = "cssGridLayout", parent = "Uif-CssGridLayout") 40 public class CssGridLayoutManager extends CssGridLayoutManagerBase { 41 private static final long serialVersionUID = 1830635073147703757L; 42 43 private int defaultItemSize; 44 45 private CssGridSizes defaultItemSizes; 46 47 public CssGridLayoutManager() { 48 super(); 49 50 defaultItemSizes = new CssGridSizes(); 51 } 52 53 /** 54 * CssGridLayoutManager's performFinalize method calculates and separates the items into rows 55 * based on their colSpan settings and the defaultItemSize setting 56 * 57 * {@inheritDoc} 58 */ 59 @Override 60 public void performFinalize(Object model, LifecycleElement component) { 61 super.performFinalize(model, component); 62 63 Container container = (Container) component; 64 cellItems = new ArrayList<Component>(); 65 processNormalLayout(container); 66 67 } 68 69 /** 70 * Separates the container's items into the appropriate number of rows and div "cells" based on 71 * the defaultColSpan property settings and colSpan settings of the items 72 * 73 * @param container the container using this layout manager 74 */ 75 private void processNormalLayout(Container container) { 76 for (Component item : container.getItems()) { 77 if (item == null) { 78 continue; 79 } 80 81 // set colSpan to default setting (12 is the default) 82 int colSpan = this.defaultItemSize; 83 84 // if the item's mdSize is set, use that as the col span for calculations below 85 if (item.getColSpan() > 1 && item.getColSpan() <= NUMBER_OF_COLUMNS) { 86 colSpan = item.getColSpan(); 87 } 88 89 List<String> cellCssClasses = item.getWrapperCssClasses(); 90 if (cellCssClasses == null) { 91 item.setWrapperCssClasses(new ArrayList<String>()); 92 cellCssClasses = item.getWrapperCssClasses(); 93 } 94 95 // Determine "cell" div css 96 calculateCssClassAndSize(item, cellCssClasses, defaultItemSizes, colSpan); 97 98 // Add dynamic left clear classes for potential wrapping content at each screen size 99 addLeftClearCssClass(cellCssClasses); 100 101 cellCssClassAttributes.add(getCellStyleClassesAsString(cellCssClasses)); 102 cellItems.add(item); 103 } 104 } 105 106 /** 107 * The default "cell" size to use for this layout - this converts to medium size 108 * (max setting, and the default, is 12) 109 * 110 * <p> 111 * This is a quick and easy setter for default mdSize for this layout, as a common use case is to have 112 * a different layout for medium devices and up, while small and extra small will consume the full screen. 113 * For customizations at every screen size, use defaultItemSizes. 114 * </p> 115 * 116 * @return int representing the default colSpan for cells in this layout 117 */ 118 @BeanTagAttribute 119 public int getDefaultItemSize() { 120 return defaultItemSize; 121 } 122 123 /** 124 * Set the default colSpan for this layout's items 125 * 126 * @param defaultItemSize 127 */ 128 public void setDefaultItemSize(int defaultItemSize) { 129 this.defaultItemSize = defaultItemSize; 130 } 131 132 /** 133 * Default sizes for each item in this css grid layout, these settings will override the setting in 134 * defaultItemSize, 135 * but will not override item specific cssGridSizes. 136 * 137 * @return cssGridSizes containing the sizes of items in this group to use as default 138 */ 139 public CssGridSizes getDefaultItemSizes() { 140 return defaultItemSizes; 141 } 142 143 /** 144 * @see org.kuali.rice.krad.uif.layout.CssGridLayoutManager#getDefaultItemSizes() 145 */ 146 public void setDefaultItemSizes(CssGridSizes defaultItemSizes) { 147 this.defaultItemSizes = defaultItemSizes; 148 } 149 }