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 java.util.ArrayList;
19 import java.util.List;
20
21 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
22 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
23 import org.kuali.rice.krad.uif.component.Component;
24 import org.kuali.rice.krad.uif.container.Container;
25 import org.kuali.rice.krad.uif.util.LifecycleElement;
26 import org.kuali.rice.krad.util.KRADUtils;
27
28
29
30
31
32
33
34
35
36
37
38
39
40 @BeanTag(name = "cssGridLayout-bean", parent = "Uif-CssGridLayout")
41 public class CssGridLayoutManager extends CssGridLayoutManagerBase {
42 private static final long serialVersionUID = 1830635073147703757L;
43
44 private int defaultItemColSpan;
45
46
47
48
49
50
51
52 @Override
53 public void performFinalize(Object model, LifecycleElement component) {
54 super.performFinalize(model, component);
55
56 Container container = (Container) component;
57 processNormalLayout(container);
58
59 }
60
61
62
63
64
65
66
67 private void processNormalLayout(Container container) {
68 int rowSpaceLeft = NUMBER_OF_COLUMNS;
69 int rowIndex = 0;
70 boolean isOdd = true;
71 List<Component> currentRow = new ArrayList<Component>();
72 for (Component item : container.getItems()) {
73 if (item == null) {
74 continue;
75 }
76 isOdd = rowIndex % 2 == 0;
77
78
79 int colSpan = this.defaultItemColSpan;
80
81
82 if (item.getColSpan() > 1 && item.getColSpan() <= NUMBER_OF_COLUMNS) {
83 colSpan = item.getColSpan();
84 }
85
86
87 List<String> cellCssClasses = item.getWrapperCssClasses();
88 if (cellCssClasses == null) {
89 item.setWrapperCssClasses(new ArrayList<String>());
90 cellCssClasses = item.getWrapperCssClasses();
91 }
92 cellCssClasses.add(0, BOOTSTRAP_SPAN_PREFIX + colSpan);
93 cellCssClassAttributes.add(getCellStyleClassesAsString(cellCssClasses));
94
95
96 rowSpaceLeft = rowSpaceLeft - colSpan;
97
98 if (rowSpaceLeft > 0) {
99
100 currentRow.add(item);
101 } else if (rowSpaceLeft < 0) {
102
103 rows.add(new ArrayList<Component>(currentRow));
104 currentRow = new ArrayList<Component>();
105 currentRow.add(item);
106
107
108 String rowCss = rowLayoutCssClass + " " + KRADUtils.generateRowCssClassString(conditionalRowCssClasses,
109 rowIndex, isOdd, null, null);
110 rowCssClassAttributes.add(rowCss);
111
112 rowIndex++;
113 rowSpaceLeft = NUMBER_OF_COLUMNS - colSpan;
114 } else if (rowSpaceLeft == 0) {
115
116 currentRow.add(item);
117 rows.add(new ArrayList<Component>(currentRow));
118 currentRow = new ArrayList<Component>();
119
120
121 String rowCss = rowLayoutCssClass + " " + KRADUtils.generateRowCssClassString(conditionalRowCssClasses,
122 rowIndex, isOdd, null, null);
123 rowCssClassAttributes.add(rowCss);
124
125 rowIndex++;
126 rowSpaceLeft = NUMBER_OF_COLUMNS;
127 }
128 }
129
130 isOdd = rowIndex % 2 == 0;
131
132 if (!currentRow.isEmpty()) {
133
134 String rowCss = rowLayoutCssClass + " " + KRADUtils.generateRowCssClassString(conditionalRowCssClasses,
135 rowIndex, isOdd, null, null);
136 rowCssClassAttributes.add(rowCss);
137
138 rows.add(currentRow);
139 }
140 }
141
142
143
144
145
146
147 @BeanTagAttribute(name = "defaultItemColSpan")
148 public int getDefaultItemColSpan() {
149 return defaultItemColSpan;
150 }
151
152
153
154
155
156
157 public void setDefaultItemColSpan(int defaultItemColSpan) {
158 this.defaultItemColSpan = defaultItemColSpan;
159 }
160
161 }