001 /**
002 * Copyright 2005-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.krad.uif.layout;
017
018 import org.apache.commons.lang.StringUtils;
019 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
020 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
021 import org.kuali.rice.krad.uif.component.Component;
022
023 import java.util.ArrayList;
024 import java.util.HashMap;
025 import java.util.List;
026 import java.util.Map;
027
028 /**
029 * Css Grid Layout managers are a layout managers which creates div "rows" and "cells" to replicate a
030 * table look by using div elements for its items.
031 *
032 * @author Kuali Rice Team (rice.collab@kuali.org)
033 */
034 @BeanTag(name = "cssGridLayoutBase-bean", parent = "Uif-CssGridLayoutBase")
035 public abstract class CssGridLayoutManagerBase extends LayoutManagerBase {
036 private static final long serialVersionUID = 1830635073147703757L;
037
038 protected static final int NUMBER_OF_COLUMNS = 12;
039 protected static final String BOOTSTRAP_SPAN_PREFIX = "col-md-";
040
041 protected Map<String, String> conditionalRowCssClasses;
042 protected String rowLayoutCssClass;
043
044 // non-settable
045 protected List<List<Component>> rows;
046 protected List<String> rowCssClassAttributes;
047 protected List<String> cellCssClassAttributes;
048
049 public CssGridLayoutManagerBase() {
050 rows = new ArrayList<List<Component>>();
051 conditionalRowCssClasses = new HashMap<String, String>();
052 cellCssClassAttributes = new ArrayList<String>();
053 rowCssClassAttributes = new ArrayList<String>();
054 }
055
056 /**
057 * Builds the HTML class attribute string by combining the cellStyleClasses list with a space
058 * delimiter
059 * @param cellCssClasses list of cell CSS classes
060 *
061 * @return class attribute string
062 */
063 protected String getCellStyleClassesAsString(List<String> cellCssClasses) {
064 if (cellCssClasses != null) {
065 return StringUtils.join(cellCssClasses, " ").trim();
066 }
067
068 return "";
069 }
070
071 /**
072 * Get the rows (which are a list of components each)
073 *
074 * @return the List of Lists of Components which represents rows for this layout
075 */
076 public List<List<Component>> getRows() {
077 return rows;
078 }
079
080 /**
081 * List of css class HTML attribute values ordered by index of row
082 *
083 * @return the list of css class HTML attributes for rows
084 */
085 public List<String> getRowCssClassAttributes() {
086 return rowCssClassAttributes;
087 }
088
089 /**
090 * List of css class HTML attribute values ordered by the order in which the cell appears
091 *
092 * @return the list of css class HTML attributes for cells
093 */
094 public List<String> getCellCssClassAttributes() {
095 return cellCssClassAttributes;
096 }
097
098 /**
099 * The row css classes for the rows of this layout
100 *
101 * <p>
102 * To set a css class on all rows, use "all" as a key. To set a class for even rows, use "even"
103 * as a key, for odd rows, use "odd". Use a one-based index to target a specific row by index.
104 * </p>
105 *
106 * @return a map which represents the css classes of the rows of this layout
107 */
108 @BeanTagAttribute(name = "conditionalRowCssClasses", type = BeanTagAttribute.AttributeType.MAPVALUE)
109 public Map<String, String> getConditionalRowCssClasses() {
110 return conditionalRowCssClasses;
111 }
112
113 /**
114 * Set conditionalRowCssClasses
115 *
116 * @param conditionalRowCssClasses
117 */
118 public void setConditionalRowCssClasses(Map<String, String> conditionalRowCssClasses) {
119 this.conditionalRowCssClasses = conditionalRowCssClasses;
120 }
121
122 /**
123 * The layout css class used by the framework to represent the row as a row visually (currently
124 * using a bootstrap class), which should not be manually reset in most situations
125 *
126 * @return the css structure class for the rows of this layout
127 */
128 @BeanTagAttribute(name = "rowLayoutCssClass")
129 public String getRowLayoutCssClass() {
130 return rowLayoutCssClass;
131 }
132
133 /**
134 * Set the rowLayoutCssClass
135 *
136 * @param rowLayoutCssClass
137 */
138 public void setRowLayoutCssClass(String rowLayoutCssClass) {
139 this.rowLayoutCssClass = rowLayoutCssClass;
140 }
141
142 }