Coverage Report - org.kuali.rice.kns.uif.layout.GridLayoutManager
 
Classes in this File Line Coverage Branch Coverage Complexity
GridLayoutManager
0%
0/33
0%
0/6
1.176
 
 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.kns.uif.layout;
 17  
 
 18  
 import org.kuali.rice.kns.uif.container.Container;
 19  
 import org.kuali.rice.kns.uif.container.Group;
 20  
 import org.kuali.rice.kns.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 matchColumnsToFieldCount;
 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 initialization is performed:
 54  
      * 
 55  
      * <ul>
 56  
      * <li>If match field count is true, sets the number of columns to the
 57  
      * container's items list size</li>
 58  
      * </ul>
 59  
      * 
 60  
      * @see org.kuali.rice.kns.uif.layout.LayoutManagerBase#performInitialization(org.kuali.rice.kns.uif.container.View,
 61  
      *      org.kuali.rice.kns.uif.container.Container)
 62  
      */
 63  
     @Override
 64  
     public void performInitialization(View view, Container container) {
 65  0
         super.performInitialization(view, container);
 66  
 
 67  0
         if (matchColumnsToFieldCount) {
 68  0
             numberOfColumns = container.getItems().size();
 69  
         }
 70  0
     }
 71  
 
 72  
     /**
 73  
      * The following finalization is performed:
 74  
      * 
 75  
      * <ul>
 76  
      * <li>Build the list of fields for the grid</li>
 77  
      * </ul>
 78  
      * 
 79  
      * @see org.kuali.rice.kns.uif.layout.LayoutManagerBase#performFinalize(org.kuali.rice.kns.uif.container.View,
 80  
      *      java.lang.Object, org.kuali.rice.kns.uif.container.Container)
 81  
      */
 82  
     @Override
 83  
     public void performFinalize(View view, Object model, Container container) {
 84  0
         super.performFinalize(view, model, container);
 85  
 
 86  
         // TODO: lookup into why we need this in each of the phases
 87  0
         if (matchColumnsToFieldCount) {
 88  0
             numberOfColumns = container.getItems().size();
 89  
         }
 90  0
     }
 91  
 
 92  
     /**
 93  
      * @see org.kuali.rice.kns.uif.layout.LayoutManagerBase#performApplyModel(org.kuali.rice.kns.uif.container.View,
 94  
      *      java.lang.Object, org.kuali.rice.kns.uif.container.Container)
 95  
      */
 96  
     @Override
 97  
     public void performApplyModel(View view, Object model, Container container) {
 98  0
         super.performApplyModel(view, model, container);
 99  
 
 100  0
         if (matchColumnsToFieldCount) {
 101  0
             numberOfColumns = container.getItems().size();
 102  
         }
 103  0
     }
 104  
 
 105  
     /**
 106  
      * @see org.kuali.rice.kns.uif.layout.ContainerAware#getSupportedContainer()
 107  
      */
 108  
     @Override
 109  
     public Class<? extends Container> getSupportedContainer() {
 110  0
         return Group.class;
 111  
     }
 112  
 
 113  
     /**
 114  
      * Indicates the number of columns that should make up one row of data
 115  
      * 
 116  
      * <p>
 117  
      * If the item count is greater than the number of columns, a new row will
 118  
      * be created to render the remaining items (and so on until all items are
 119  
      * placed).
 120  
      * </p>
 121  
      * 
 122  
      * <p>
 123  
      * Note this does not include any generated columns by the layout manager,
 124  
      * so the final column count could be greater (if label fields are
 125  
      * separate).
 126  
      * </p>
 127  
      * 
 128  
      * @return
 129  
      */
 130  
     public int getNumberOfColumns() {
 131  0
         return this.numberOfColumns;
 132  
     }
 133  
 
 134  
     /**
 135  
      * Setter for the number of columns (each row)
 136  
      * 
 137  
      * @param numberOfColumns
 138  
      */
 139  
     public void setNumberOfColumns(int numberOfColumns) {
 140  0
         this.numberOfColumns = numberOfColumns;
 141  0
     }
 142  
 
 143  
     /**
 144  
      * Conditional string expression for setting the number of columns field
 145  
      * 
 146  
      * @return String expression that should evaluate to an int
 147  
      */
 148  
     public String getConditionalNumberOfColumns() {
 149  0
         return this.conditionalNumberOfColumns;
 150  
     }
 151  
 
 152  
     /**
 153  
      * Setter for the conditional number of columns string
 154  
      * 
 155  
      * @param conditionalNumberOfColumns
 156  
      */
 157  
     public void setConditionalNumberOfColumns(String conditionalNumberOfColumns) {
 158  0
         this.conditionalNumberOfColumns = conditionalNumberOfColumns;
 159  0
     }
 160  
 
 161  
     /**
 162  
      * Indicates whether the number of columns for the table data should match
 163  
      * the number of fields given in the container's items list (so that each
 164  
      * field takes up one column without wrapping)
 165  
      * 
 166  
      * <p>
 167  
      * If set to true during the initialize phase the number of columns will be
 168  
      * set to the size of the container's field list, if false the configured
 169  
      * number of columns is used
 170  
      * </p>
 171  
      * 
 172  
      * @return boolean true if the column count should match the container's
 173  
      *         field count, false to use the configured number of columns
 174  
      */
 175  
     public boolean isMatchColumnsToFieldCount() {
 176  0
         return this.matchColumnsToFieldCount;
 177  
     }
 178  
 
 179  
     /**
 180  
      * Setter for the match column count to field count indicator
 181  
      * 
 182  
      * @param matchColumnsToFieldCount
 183  
      */
 184  
     public void setMatchColumnsToFieldCount(boolean matchColumnsToFieldCount) {
 185  0
         this.matchColumnsToFieldCount = matchColumnsToFieldCount;
 186  0
     }
 187  
 
 188  
     /**
 189  
      * Indicates whether alternating row styles should be applied
 190  
      * 
 191  
      * <p>
 192  
      * Indicator to layout manager templates to apply alternating row styles.
 193  
      * See the configured template for the actual style classes used
 194  
      * </p>
 195  
      * 
 196  
      * @return boolean true if alternating styles should be applied, false if
 197  
      *         all rows should have the same style
 198  
      */
 199  
     public boolean isApplyAlternatingRowStyles() {
 200  0
         return this.applyAlternatingRowStyles;
 201  
     }
 202  
 
 203  
     /**
 204  
      * Setter for the alternating row styles indicator
 205  
      * 
 206  
      * @param applyAlternatingRowStyles
 207  
      */
 208  
     public void setApplyAlternatingRowStyles(boolean applyAlternatingRowStyles) {
 209  0
         this.applyAlternatingRowStyles = applyAlternatingRowStyles;
 210  0
     }
 211  
 
 212  
     /**
 213  
      * Indicates whether the manager should default the cell widths
 214  
      * 
 215  
      * <p>
 216  
      * If true, the manager will set the cell width by equally dividing by the
 217  
      * number of columns
 218  
      * </p>
 219  
      * 
 220  
      * @return boolean true if default cell widths should be applied, false if
 221  
      *         no defaults should be applied
 222  
      */
 223  
     public boolean isApplyDefaultCellWidths() {
 224  0
         return this.applyDefaultCellWidths;
 225  
     }
 226  
 
 227  
     /**
 228  
      * Setter for the default cell width indicator
 229  
      * 
 230  
      * @param applyDefaultCellWidths
 231  
      */
 232  
     public void setApplyDefaultCellWidths(boolean applyDefaultCellWidths) {
 233  0
         this.applyDefaultCellWidths = applyDefaultCellWidths;
 234  0
     }
 235  
 
 236  
     /**
 237  
      * Indicates whether header columns (th for tables) should be rendered for
 238  
      * every other item (alternating)
 239  
      * 
 240  
      * <p>
 241  
      * If true the first cell of each row will be rendered as an header, with
 242  
      * every other cell in the row as a header
 243  
      * </p>
 244  
      * 
 245  
      * @return boolean true if alternating headers should be rendered, false if
 246  
      *         not
 247  
      */
 248  
     public boolean isRenderAlternatingHeaderColumns() {
 249  0
         return this.renderAlternatingHeaderColumns;
 250  
     }
 251  
 
 252  
     /**
 253  
      * Setter for the render alternating header columns indicator
 254  
      * 
 255  
      * @param renderAlternatingHeaderColumns
 256  
      */
 257  
     public void setRenderAlternatingHeaderColumns(boolean renderAlternatingHeaderColumns) {
 258  0
         this.renderAlternatingHeaderColumns = renderAlternatingHeaderColumns;
 259  0
     }
 260  
 
 261  
 }