View Javadoc
1   /*
2    * Copyright 2008 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.ole.sys.document.service.impl;
17  
18  import java.util.HashSet;
19  import java.util.List;
20  import java.util.Set;
21  
22  import org.kuali.ole.sys.document.service.AccountingLineTableTransformation;
23  import org.kuali.ole.sys.document.web.AccountingLineTableCell;
24  import org.kuali.ole.sys.document.web.AccountingLineTableRow;
25  
26  /**
27   * Rendering transformation which removes any empty cells and rows from a table
28   */
29  public class RemoveEmptyCellsAndRowsRenderingTransformationImpl implements AccountingLineTableTransformation {
30  
31      /**
32       * Removes any empty cells and rows from this table
33       * @param rows the table rows to render
34       */
35      public void transformRows(List<AccountingLineTableRow> rows) {
36          Set<AccountingLineTableRow> rowsToRemove = new HashSet<AccountingLineTableRow>();
37          for (AccountingLineTableRow row : rows) {
38              removeEmptyCells(row);
39              if (row.isEmpty()) {
40                  rowsToRemove.add(row);
41              }
42          }
43          rows.removeAll(rowsToRemove);
44      }
45      
46      /**
47       * Removes all empty cells from a given row
48       * @param row the row to remove empty cells from
49       */
50      public void removeEmptyCells(AccountingLineTableRow row) {
51          Set<AccountingLineTableCell> cellsToRemove = new HashSet<AccountingLineTableCell>();
52          for (AccountingLineTableCell cell : row.getCells()) {
53              if (cell.isEmpty()) {
54                  cellsToRemove.add(cell);
55              }
56          }
57          row.getCells().removeAll(cellsToRemove);
58      }
59  }