1 /**
2 * Copyright 2005-2012 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.uif.container.Container;
19 import org.kuali.rice.krad.uif.container.Group;
20 import org.kuali.rice.krad.uif.view.View;
21
22 /**
23 * Layout manager that organizes its components in a table based grid
24 *
25 * <p>
26 * Items are laid out from left to right (with each item taking up one column)
27 * until the configured number of columns is reached. If the item count is
28 * greater than the number of columns, a new row will be created to render the
29 * remaining items (and so on until all items are placed). Labels for the fields
30 * can be pulled out (default) and rendered as a separate column. The manager
31 * also supports the column span and row span options for the field items. If
32 * not specified the default is 1.
33 * </p>
34 *
35 * @author Kuali Rice Team (rice.collab@kuali.org)
36 */
37 public class GridLayoutManager extends LayoutManagerBase {
38 private static final long serialVersionUID = 1890011900375071128L;
39
40 private int numberOfColumns;
41
42 private boolean suppressLineWrapping;
43 private boolean applyAlternatingRowStyles;
44 private boolean applyDefaultCellWidths;
45 private boolean renderAlternatingHeaderColumns;
46 private String firstLineStyle = "";
47
48 public GridLayoutManager() {
49 super();
50 }
51
52 /**
53 * The following finalization is performed:
54 *
55 * <ul>
56 * <li>If suppressLineWrapping is true, sets the number of columns to the
57 * container's items list size</li>
58 * </ul>
59 *
60 * @see org.kuali.rice.krad.uif.layout.LayoutManagerBase#performFinalize(org.kuali.rice.krad.uif.view.View,
61 * java.lang.Object, org.kuali.rice.krad.uif.container.Container)
62 */
63 @Override
64 public void performFinalize(View view, Object model, Container container) {
65 super.performFinalize(view, model, container);
66
67 if (suppressLineWrapping) {
68 numberOfColumns = container.getItems().size();
69 }
70 }
71
72 /**
73 * @see org.kuali.rice.krad.uif.layout.ContainerAware#getSupportedContainer()
74 */
75 @Override
76 public Class<? extends Container> getSupportedContainer() {
77 return Group.class;
78 }
79
80 /**
81 * Indicates the number of columns that should make up one row of data
82 *
83 * <p>
84 * If the item count is greater than the number of columns, a new row will
85 * be created to render the remaining items (and so on until all items are
86 * placed).
87 * </p>
88 *
89 * <p>
90 * Note this does not include any generated columns by the layout manager,
91 * so the final column count could be greater (if label fields are
92 * separate).
93 * </p>
94 *
95 * @return
96 */
97 public int getNumberOfColumns() {
98 return this.numberOfColumns;
99 }
100
101 /**
102 * Setter for the number of columns (each row)
103 *
104 * @param numberOfColumns
105 */
106 public void setNumberOfColumns(int numberOfColumns) {
107 this.numberOfColumns = numberOfColumns;
108 }
109
110 /**
111 * Indicates whether the number of columns for the table data should match
112 * the number of fields given in the container's items list (so that each
113 * field takes up one column without wrapping), this overrides the configured
114 * numberOfColumns
115 *
116 * <p>
117 * If set to true during the initialize phase the number of columns will be
118 * set to the size of the container's field list, if false the configured
119 * number of columns is used
120 * </p>
121 *
122 * @return boolean true if the column count should match the container's
123 * field count, false to use the configured number of columns
124 */
125 public boolean isSuppressLineWrapping() {
126 return this.suppressLineWrapping;
127 }
128
129 /**
130 * Setter for the suppressLineWrapping indicator
131 *
132 * @param suppressLineWrapping
133 */
134 public void setSuppressLineWrapping(boolean suppressLineWrapping) {
135 this.suppressLineWrapping = suppressLineWrapping;
136 }
137
138 /**
139 * Indicates whether alternating row styles should be applied
140 *
141 * <p>
142 * Indicator to layout manager templates to apply alternating row styles.
143 * See the configured template for the actual style classes used
144 * </p>
145 *
146 * @return boolean true if alternating styles should be applied, false if
147 * all rows should have the same style
148 */
149 public boolean isApplyAlternatingRowStyles() {
150 return this.applyAlternatingRowStyles;
151 }
152
153 /**
154 * Setter for the alternating row styles indicator
155 *
156 * @param applyAlternatingRowStyles
157 */
158 public void setApplyAlternatingRowStyles(boolean applyAlternatingRowStyles) {
159 this.applyAlternatingRowStyles = applyAlternatingRowStyles;
160 }
161
162 /**
163 * Indicates whether the manager should default the cell widths
164 *
165 * <p>
166 * If true, the manager will set the cell width by equally dividing by the
167 * number of columns
168 * </p>
169 *
170 * @return boolean true if default cell widths should be applied, false if
171 * no defaults should be applied
172 */
173 public boolean isApplyDefaultCellWidths() {
174 return this.applyDefaultCellWidths;
175 }
176
177 /**
178 * Setter for the default cell width indicator
179 *
180 * @param applyDefaultCellWidths
181 */
182 public void setApplyDefaultCellWidths(boolean applyDefaultCellWidths) {
183 this.applyDefaultCellWidths = applyDefaultCellWidths;
184 }
185
186 /**
187 * Indicates whether header columns (th for tables) should be rendered for
188 * every other item (alternating)
189 *
190 * <p>
191 * If true the first cell of each row will be rendered as an header, with
192 * every other cell in the row as a header
193 * </p>
194 *
195 * @return boolean true if alternating headers should be rendered, false if
196 * not
197 */
198 public boolean isRenderAlternatingHeaderColumns() {
199 return this.renderAlternatingHeaderColumns;
200 }
201
202 /**
203 * Setter for the render alternating header columns indicator
204 *
205 * @param renderAlternatingHeaderColumns
206 */
207 public void setRenderAlternatingHeaderColumns(boolean renderAlternatingHeaderColumns) {
208 this.renderAlternatingHeaderColumns = renderAlternatingHeaderColumns;
209 }
210
211
212 public String getFirstLineStyle() {
213 return firstLineStyle;
214 }
215
216 /**
217 * Style class given to the first line in the collection
218 * @param firstLineStyle
219 */
220 public void setFirstLineStyle(String firstLineStyle) {
221 this.firstLineStyle = firstLineStyle;
222 }
223 }