1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.layout;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20 import org.kuali.rice.krad.uif.CssConstants;
21 import org.kuali.rice.krad.uif.component.Component;
22 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycleRestriction;
23
24 import java.util.ArrayList;
25 import java.util.List;
26
27
28
29
30
31
32
33 @BeanTag(name = "cssGridLayoutBase", parent = "Uif-CssGridLayoutBase")
34 public abstract class CssGridLayoutManagerBase extends LayoutManagerBase {
35 private static final long serialVersionUID = 1830635073147703757L;
36
37 protected static final int NUMBER_OF_COLUMNS = 12;
38 protected static final String BOOTSTRAP_SPAN_PREFIX = "col-md-";
39
40
41 protected List<Component> cellItems;
42 protected List<String> cellCssClassAttributes;
43
44
45 protected int xsTotalSize = 0;
46 protected int smTotalSize = 0;
47 protected int mdTotalSize = 0;
48 protected int lgTotalSize = 0;
49
50 public CssGridLayoutManagerBase() {
51 cellCssClassAttributes = new ArrayList<String>();
52 cellItems = new ArrayList<Component>();
53 }
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 protected void calculateCssClassAndSize(Component item, List<String> cellCssClasses, CssGridSizes defaultSizes,
71 int basicSize) {
72
73 if (StringUtils.isNotBlank(item.getCssGridSizes().getCssClassString())) {
74 cellCssClasses.add(0, item.getCssGridSizes().getCssClassString());
75
76 xsTotalSize += item.getCssGridSizes().getXsSize();
77 smTotalSize += item.getCssGridSizes().getTotalSmSize();
78 mdTotalSize += item.getCssGridSizes().getTotalMdSize();
79 lgTotalSize += item.getCssGridSizes().getTotalLgSize();
80 } else if (StringUtils.isNotBlank(defaultSizes.getCssClassString())) {
81 cellCssClasses.add(0, defaultSizes.getCssClassString());
82
83 xsTotalSize += defaultSizes.getXsSize();
84 smTotalSize += defaultSizes.getTotalSmSize();
85 mdTotalSize += defaultSizes.getTotalMdSize();
86 lgTotalSize += defaultSizes.getTotalLgSize();
87 } else {
88 cellCssClasses.add(0, BOOTSTRAP_SPAN_PREFIX + basicSize);
89
90 mdTotalSize += basicSize;
91 }
92 }
93
94
95
96
97
98
99
100 protected void addLeftClearCssClass(List<String> cellCssClasses) {
101 String classString = getCellStyleClassesAsString(cellCssClasses);
102
103
104
105
106 if (lgTotalSize > 12) {
107 if (classString.contains(CssConstants.CssGrid.LG_COL_PREFIX)) {
108 cellCssClasses.add(0, CssConstants.CssGrid.LG_CLEAR_LEFT);
109 }
110 lgTotalSize = lgTotalSize - 12;
111 }
112
113 if (mdTotalSize > 12) {
114 if (classString.contains(CssConstants.CssGrid.MD_COL_PREFIX)) {
115 cellCssClasses.add(0, CssConstants.CssGrid.MD_CLEAR_LEFT);
116 }
117 mdTotalSize = mdTotalSize - 12;
118 }
119
120 if (smTotalSize > 12) {
121 if (classString.contains(CssConstants.CssGrid.SM_COL_PREFIX)) {
122 cellCssClasses.add(0, CssConstants.CssGrid.SM_CLEAR_LEFT);
123 }
124 smTotalSize = smTotalSize - 12;
125 }
126
127 if (xsTotalSize > 12) {
128 cellCssClasses.add(0, CssConstants.CssGrid.XS_CLEAR_LEFT);
129 xsTotalSize = xsTotalSize - 12;
130 }
131 }
132
133
134
135
136
137
138
139
140 protected String getCellStyleClassesAsString(List<String> cellCssClasses) {
141 if (cellCssClasses != null) {
142 return StringUtils.join(cellCssClasses, " ").trim();
143 }
144
145 return "";
146 }
147
148
149
150
151
152
153
154 @ViewLifecycleRestriction
155 public List<Component> getCellItems() {
156 return cellItems;
157 }
158
159
160
161
162
163
164 public List<String> getCellCssClassAttributes() {
165 return cellCssClassAttributes;
166 }
167
168 }