001/**
002 * Copyright 2005-2016 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 */
016package org.kuali.rice.krad.uif.layout;
017
018import org.kuali.rice.krad.uif.container.Container;
019import org.kuali.rice.krad.uif.container.Group;
020import org.kuali.rice.krad.uif.view.View;
021
022/**
023 * Layout manager that organizes its components in a table based grid
024 * 
025 * <p>
026 * Items are laid out from left to right (with each item taking up one column)
027 * until the configured number of columns is reached. If the item count is
028 * greater than the number of columns, a new row will be created to render the
029 * remaining items (and so on until all items are placed). Labels for the fields
030 * can be pulled out (default) and rendered as a separate column. The manager
031 * also supports the column span and row span options for the field items. If
032 * not specified the default is 1.
033 * </p>
034 * 
035 * @author Kuali Rice Team (rice.collab@kuali.org)
036 */
037public class GridLayoutManager extends LayoutManagerBase {
038    private static final long serialVersionUID = 1890011900375071128L;
039
040    private int numberOfColumns;
041
042    private boolean suppressLineWrapping;
043    private boolean applyAlternatingRowStyles;
044    private boolean applyDefaultCellWidths;
045    private boolean renderAlternatingHeaderColumns;
046    private String firstLineStyle = "";
047
048    public GridLayoutManager() {
049        super();
050    }
051
052    /**
053     * The following finalization is performed:
054     * 
055     * <ul>
056     * <li>If suppressLineWrapping is true, sets the number of columns to the
057     * container's items list size</li>
058     * </ul>
059     * 
060     * @see org.kuali.rice.krad.uif.layout.LayoutManagerBase#performFinalize(org.kuali.rice.krad.uif.view.View,
061     *      java.lang.Object, org.kuali.rice.krad.uif.container.Container)
062     */
063    @Override
064    public void performFinalize(View view, Object model, Container container) {
065        super.performFinalize(view, model, container);
066
067        if (suppressLineWrapping) {
068            numberOfColumns = container.getItems().size();
069        }
070    }
071
072    /**
073     * @see org.kuali.rice.krad.uif.layout.ContainerAware#getSupportedContainer()
074     */
075    @Override
076    public Class<? extends Container> getSupportedContainer() {
077        return Group.class;
078    }
079
080    /**
081     * Indicates the number of columns that should make up one row of data
082     * 
083     * <p>
084     * If the item count is greater than the number of columns, a new row will
085     * be created to render the remaining items (and so on until all items are
086     * placed).
087     * </p>
088     * 
089     * <p>
090     * Note this does not include any generated columns by the layout manager,
091     * so the final column count could be greater (if label fields are
092     * separate).
093     * </p>
094     * 
095     * @return
096     */
097    public int getNumberOfColumns() {
098        return this.numberOfColumns;
099    }
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}