1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.ole.sys.document.web;
17  
18  import java.util.HashSet;
19  import java.util.List;
20  import java.util.Map;
21  import java.util.Set;
22  
23  import org.kuali.ole.sys.businessobject.AccountingLine;
24  import org.kuali.ole.sys.document.datadictionary.AccountingLineViewLinesDefinition;
25  import org.kuali.ole.sys.document.service.AccountingLineFieldRenderingTransformation;
26  
27  
28  
29  
30  public class AccountingLineViewLines implements TableJoining, ReadOnlyable {
31      private List<AccountingLineViewLineFillingElement> elements;
32      private AccountingLineViewLinesDefinition definition;
33      
34      
35  
36  
37  
38      public AccountingLineViewLinesDefinition getDefinition() {
39          return definition;
40      }
41      
42  
43  
44  
45      public void setDefinition(AccountingLineViewLinesDefinition definition) {
46          this.definition = definition;
47      }
48      
49      
50  
51  
52      public String getName() {
53          return definition.getElementName();
54      }
55      
56  
57  
58  
59      public List<AccountingLineViewLineFillingElement> getElements() {
60          return elements;
61      }
62      
63  
64  
65  
66      public void setElements(List<AccountingLineViewLineFillingElement> lines) {
67          this.elements = lines;
68      }
69      
70      
71  
72  
73  
74  
75      public int getRequestedRowCount() {
76          int sum = 0;
77          for (AccountingLineViewLineFillingElement line : elements) {
78              sum += line.getRequestedRowCount();
79          }
80          return sum;
81      }
82      
83      
84  
85  
86  
87      public void joinRow(AccountingLineTableRow headerRow, AccountingLineTableRow row) {
88          throw new IllegalStateException("Error in line rendering algorithm - lines cannot join a single row.");
89      }
90      
91      
92  
93  
94  
95      public void joinTable(List<AccountingLineTableRow> rows) {
96          final int maxExpectedLineWidth = getMaxExpectedLineWidth();
97          
98          int count = 0;
99          for (AccountingLineViewLineFillingElement line : elements) {
100             AccountingLineTableRow headerRow = rows.get(count);
101             
102             if (line.getRequestedRowCount() > 1) {
103                 line.joinRow(headerRow, rows.get(count+1));
104                 padOutOrStretchCells(line, maxExpectedLineWidth, headerRow, rows.get(count+1));
105                 
106                 count += 2;
107             } else {
108                 line.joinRow(headerRow, null);
109                 padOutOrStretchCells(line, maxExpectedLineWidth, headerRow, null);
110                 
111                 count += 1;
112             }
113         }
114     }
115     
116     
117 
118 
119 
120 
121 
122 
123     protected void padOutOrStretchCells(AccountingLineViewLineFillingElement line, int maxExpectedLineWidth, AccountingLineTableRow headerRow, AccountingLineTableRow row) {
124         final int shorterThanMax = maxExpectedLineWidth - line.getDisplayingFieldWidth();
125         if (shorterThanMax > 0) {
126             if (line.shouldStretchToFillLine() && headerRow.getChildCellCount() == 1) {
127                 headerRow.getCells().get(0).setColSpan(maxExpectedLineWidth);
128                 if (row != null) {
129                     row.getCells().get(0).setColSpan(maxExpectedLineWidth);
130                 }
131             } else {
132                 PlaceHoldingLayoutElement placeHolder = new PlaceHoldingLayoutElement(shorterThanMax);
133                 placeHolder.joinRow(headerRow, row);
134             }
135         }
136     }
137     
138     
139 
140 
141     public void readOnlyize() {
142         for (AccountingLineViewLineFillingElement line : elements) {
143             line.readOnlyize();
144         }
145     }
146     
147     
148 
149 
150     public boolean isReadOnly() {
151         for (AccountingLineViewLineFillingElement line : elements) {
152             if (!line.isReadOnly()) {
153                 return false;
154             }
155         }
156         return true;
157     }
158     
159     
160 
161 
162     public void removeAllActionBlocks() {
163         for (AccountingLineViewLineFillingElement line : elements) {
164             line.removeAllActionBlocks();
165         }
166     }
167     
168     
169 
170 
171     public void removeUnviewableBlocks(Set<String> unviewableBlocks) {
172         Set<AccountingLineViewLineFillingElement> linesToRemove = new HashSet<AccountingLineViewLineFillingElement>();
173         for (AccountingLineViewLineFillingElement line : elements) {
174             if (unviewableBlocks.contains(line.getName())) {
175                 linesToRemove.add(line);
176             } else {
177                 line.removeUnviewableBlocks(unviewableBlocks);
178             }
179         }
180         elements.removeAll(linesToRemove);
181     }
182     
183     
184 
185 
186     public void performFieldTransformations(List<AccountingLineFieldRenderingTransformation> fieldTransformations, AccountingLine accountingLine, Map unconvertedValues) {
187         for (AccountingLineViewLineFillingElement line : elements) {
188             line.performFieldTransformations(fieldTransformations, accountingLine, unconvertedValues);
189         }
190     }
191     
192     
193 
194 
195     public int getMaxExpectedLineWidth() {
196         int maxWidth = 0;
197         for (AccountingLineViewLineFillingElement line: elements) {
198             int width = line.getDisplayingFieldWidth();
199             if (width > maxWidth) {
200                 maxWidth = width;
201             }
202         }
203         return maxWidth;
204     }
205     
206     
207 
208 
209 
210     public void readOnlyizeReadOnlyBlocks(Set<String> readOnlyBlocks) {
211         for (AccountingLineViewLineFillingElement line : elements) {
212             line.readOnlyizeReadOnlyBlocks(readOnlyBlocks);
213         }
214     }
215     
216     
217 
218 
219     public void setEditableBlocks(Set<String> editableBlocks) {
220         for (AccountingLineViewLineFillingElement line : elements) {
221             line.setEditableBlocks(editableBlocks);
222         }
223     }
224     
225     
226 
227 
228     public void setEditable() {
229         for (AccountingLineViewLineFillingElement line : elements) {
230             line.setEditable();
231         }       
232     }
233 }