| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| GridLayoutManager |
|
| 1.0666666666666667;1.067 |
| 1 | /* | |
| 2 | * Copyright 2007 The Kuali Foundation | |
| 3 | * | |
| 4 | * Licensed under the Educational Community License, Version 1.0 (the | |
| 5 | * "License"); 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/ecl1.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, WITHOUT | |
| 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |
| 13 | * License for the specific language governing permissions and limitations under | |
| 14 | * 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.container.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 | private String conditionalNumberOfColumns; | |
| 42 | ||
| 43 | private boolean suppressLineWrapping; | |
| 44 | private boolean applyAlternatingRowStyles; | |
| 45 | private boolean applyDefaultCellWidths; | |
| 46 | private boolean renderAlternatingHeaderColumns; | |
| 47 | ||
| 48 | public GridLayoutManager() { | |
| 49 | 0 | super(); |
| 50 | 0 | } |
| 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.container.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 | 0 | super.performFinalize(view, model, container); |
| 66 | ||
| 67 | 0 | if (suppressLineWrapping) { |
| 68 | 0 | numberOfColumns = container.getItems().size(); |
| 69 | } | |
| 70 | 0 | } |
| 71 | ||
| 72 | /** | |
| 73 | * @see org.kuali.rice.krad.uif.layout.ContainerAware#getSupportedContainer() | |
| 74 | */ | |
| 75 | @Override | |
| 76 | public Class<? extends Container> getSupportedContainer() { | |
| 77 | 0 | 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 | 0 | 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 | 0 | this.numberOfColumns = numberOfColumns; |
| 108 | 0 | } |
| 109 | ||
| 110 | /** | |
| 111 | * Conditional string expression for setting the number of columns field | |
| 112 | * | |
| 113 | * @return String expression that should evaluate to an int | |
| 114 | */ | |
| 115 | public String getConditionalNumberOfColumns() { | |
| 116 | 0 | return this.conditionalNumberOfColumns; |
| 117 | } | |
| 118 | ||
| 119 | /** | |
| 120 | * Setter for the conditional number of columns string | |
| 121 | * | |
| 122 | * @param conditionalNumberOfColumns | |
| 123 | */ | |
| 124 | public void setConditionalNumberOfColumns(String conditionalNumberOfColumns) { | |
| 125 | 0 | this.conditionalNumberOfColumns = conditionalNumberOfColumns; |
| 126 | 0 | } |
| 127 | ||
| 128 | /** | |
| 129 | * Indicates whether the number of columns for the table data should match | |
| 130 | * the number of fields given in the container's items list (so that each | |
| 131 | * field takes up one column without wrapping), this overrides the configured | |
| 132 | * numberOfColumns | |
| 133 | * | |
| 134 | * <p> | |
| 135 | * If set to true during the initialize phase the number of columns will be | |
| 136 | * set to the size of the container's field list, if false the configured | |
| 137 | * number of columns is used | |
| 138 | * </p> | |
| 139 | * | |
| 140 | * @return boolean true if the column count should match the container's | |
| 141 | * field count, false to use the configured number of columns | |
| 142 | */ | |
| 143 | public boolean isSuppressLineWrapping() { | |
| 144 | 0 | return this.suppressLineWrapping; |
| 145 | } | |
| 146 | ||
| 147 | /** | |
| 148 | * Setter for the suppressLineWrapping indicator | |
| 149 | * | |
| 150 | * @param suppressLineWrapping | |
| 151 | */ | |
| 152 | public void setSuppressLineWrapping(boolean suppressLineWrapping) { | |
| 153 | 0 | this.suppressLineWrapping = suppressLineWrapping; |
| 154 | 0 | } |
| 155 | ||
| 156 | /** | |
| 157 | * Indicates whether alternating row styles should be applied | |
| 158 | * | |
| 159 | * <p> | |
| 160 | * Indicator to layout manager templates to apply alternating row styles. | |
| 161 | * See the configured template for the actual style classes used | |
| 162 | * </p> | |
| 163 | * | |
| 164 | * @return boolean true if alternating styles should be applied, false if | |
| 165 | * all rows should have the same style | |
| 166 | */ | |
| 167 | public boolean isApplyAlternatingRowStyles() { | |
| 168 | 0 | return this.applyAlternatingRowStyles; |
| 169 | } | |
| 170 | ||
| 171 | /** | |
| 172 | * Setter for the alternating row styles indicator | |
| 173 | * | |
| 174 | * @param applyAlternatingRowStyles | |
| 175 | */ | |
| 176 | public void setApplyAlternatingRowStyles(boolean applyAlternatingRowStyles) { | |
| 177 | 0 | this.applyAlternatingRowStyles = applyAlternatingRowStyles; |
| 178 | 0 | } |
| 179 | ||
| 180 | /** | |
| 181 | * Indicates whether the manager should default the cell widths | |
| 182 | * | |
| 183 | * <p> | |
| 184 | * If true, the manager will set the cell width by equally dividing by the | |
| 185 | * number of columns | |
| 186 | * </p> | |
| 187 | * | |
| 188 | * @return boolean true if default cell widths should be applied, false if | |
| 189 | * no defaults should be applied | |
| 190 | */ | |
| 191 | public boolean isApplyDefaultCellWidths() { | |
| 192 | 0 | return this.applyDefaultCellWidths; |
| 193 | } | |
| 194 | ||
| 195 | /** | |
| 196 | * Setter for the default cell width indicator | |
| 197 | * | |
| 198 | * @param applyDefaultCellWidths | |
| 199 | */ | |
| 200 | public void setApplyDefaultCellWidths(boolean applyDefaultCellWidths) { | |
| 201 | 0 | this.applyDefaultCellWidths = applyDefaultCellWidths; |
| 202 | 0 | } |
| 203 | ||
| 204 | /** | |
| 205 | * Indicates whether header columns (th for tables) should be rendered for | |
| 206 | * every other item (alternating) | |
| 207 | * | |
| 208 | * <p> | |
| 209 | * If true the first cell of each row will be rendered as an header, with | |
| 210 | * every other cell in the row as a header | |
| 211 | * </p> | |
| 212 | * | |
| 213 | * @return boolean true if alternating headers should be rendered, false if | |
| 214 | * not | |
| 215 | */ | |
| 216 | public boolean isRenderAlternatingHeaderColumns() { | |
| 217 | 0 | return this.renderAlternatingHeaderColumns; |
| 218 | } | |
| 219 | ||
| 220 | /** | |
| 221 | * Setter for the render alternating header columns indicator | |
| 222 | * | |
| 223 | * @param renderAlternatingHeaderColumns | |
| 224 | */ | |
| 225 | public void setRenderAlternatingHeaderColumns(boolean renderAlternatingHeaderColumns) { | |
| 226 | 0 | this.renderAlternatingHeaderColumns = renderAlternatingHeaderColumns; |
| 227 | 0 | } |
| 228 | ||
| 229 | } |