1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
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  import org.kuali.ole.sys.document.web.RenderableElement;
26  
27  
28  
29  
30  
31  public class HiddenFieldRearrangementAccountingLineRenderingTransformationImpl implements AccountingLineTableTransformation {
32  
33      public void transformRows(List<AccountingLineTableRow> rows) {
34          
35          AccountingLineTableCell cell = findFirstNonHiddenCell(rows);
36          
37          for (AccountingLineTableRow row : rows) {
38              moveHiddenFields(row, cell);
39          }
40      }
41      
42      
43  
44  
45  
46  
47      protected AccountingLineTableCell findFirstNonHiddenCell(List<AccountingLineTableRow> rows) {
48          for (AccountingLineTableRow row : rows) {
49              for (AccountingLineTableCell cell : row.getCells()) {
50                  if (!cell.isHidden()) {
51                      return cell;
52                  }
53              }
54          }
55          throw new IllegalArgumentException("The renderable element tree specified does not seem to have any elements that will display as non-hidden specified");
56      }
57      
58      
59  
60  
61  
62  
63      protected void moveHiddenFields(AccountingLineTableRow sourceRow, AccountingLineTableCell targetCell) {
64          for (AccountingLineTableCell cell : sourceRow.getCells()) {
65              moveHiddenFields(cell, targetCell);
66          }
67      }
68      
69      
70  
71  
72  
73  
74      protected void moveHiddenFields(AccountingLineTableCell sourceCell, AccountingLineTableCell targetCell) {
75          Set<RenderableElement> renderableElementsToRemove = new HashSet<RenderableElement>();
76          for (RenderableElement element : sourceCell.getRenderableElement()) {
77              if (element.isHidden()) {
78                  renderableElementsToRemove.add(element);
79              }
80          }
81          sourceCell.getRenderableElement().removeAll(renderableElementsToRemove);
82          targetCell.getRenderableElement().addAll(renderableElementsToRemove);
83      }
84  }