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.ArrayList;
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.AccountingLineViewColumnsDefinition;
25  import org.kuali.ole.sys.document.service.AccountingLineFieldRenderingTransformation;
26  
27  
28  
29  
30  public class AccountingLineViewColumns implements AccountingLineViewLineFillingElement {
31      private List<AccountingLineViewField> fields;
32      private AccountingLineViewColumnsDefinition definition;
33      
34      
35  
36  
37  
38  
39      public AccountingLineViewColumns(AccountingLineViewColumnsDefinition definition, List<AccountingLineViewField> fields) {
40          this.definition = definition;
41          this.fields = fields;
42      }
43  
44      
45  
46  
47  
48      public String getName() {
49          return definition.getName();
50      }
51  
52      
53  
54  
55  
56      public int getRequestedRowCount() {
57          return 1;
58      }
59  
60      
61  
62  
63  
64      public boolean shouldStretchToFillLine() {
65          return true;
66      }
67  
68      
69  
70  
71  
72      public void joinRow(AccountingLineTableRow headerLabelRow, AccountingLineTableRow row) {
73          AccountingLineTableCell cell = new AccountingLineTableCell();
74  
75          AccountingLineTable columnsTable = new AccountingLineTable();
76  
77          List<AccountingLineTableRow> rows = createRowsForFields();
78          
79          columnsTable.setRows(rows);
80          cell.addRenderableElement(columnsTable);
81          headerLabelRow.addCell(cell);
82      }
83      
84      
85  
86  
87  
88      protected List<AccountingLineTableRow> createRowsForFields() {
89          List<AccountingLineTableRow> rows = new ArrayList<AccountingLineTableRow>();
90          
91          int countForThisRow = 0;
92          AccountingLineTableRow row = new AccountingLineTableRow();
93          for (AccountingLineViewField field : fields) {
94              row.addCell(createHeaderCellForField(field));
95              row.addCell(createCellForField(field));
96              countForThisRow += 1;
97              
98              if (countForThisRow == definition.getColumnCount()) {
99                  rows.add(row);
100                 countForThisRow = 0;
101                 row = new AccountingLineTableRow();
102             }
103         }
104         if (countForThisRow > 0) { 
105             while (countForThisRow < definition.getColumnCount()) {
106                 row.addCell(createPaddingCell());
107                 countForThisRow += 1;
108             }
109             rows.add(row);
110         }
111         
112         return rows;
113     }
114     
115     
116 
117 
118 
119 
120     protected AccountingLineTableCell createHeaderCellForField(AccountingLineViewField field) {
121         AccountingLineTableCell headerCell = new AccountingLineTableCell();
122         headerCell.setRendersAsHeader(true);
123         headerCell.addRenderableElement(field.createHeaderLabel());
124         return headerCell;
125     }
126     
127     
128 
129 
130 
131 
132     protected AccountingLineTableCell createCellForField(AccountingLineViewField field) {
133         AccountingLineTableCell cell = new AccountingLineTableCell();
134         cell.addRenderableElement(field);
135         return cell;
136     }
137     
138     
139 
140 
141 
142     protected AccountingLineTableCell createPaddingCell() {
143         AccountingLineTableCell cell = new AccountingLineTableCell();
144         cell.setColSpan(2);
145         cell.setNeverEmpty(true);
146         return cell;
147     }
148 
149     
150 
151 
152 
153     public void joinTable(List<AccountingLineTableRow> rows) {
154         throw new IllegalStateException("Line elements may not join a table directly; the specified rendering is incorrect");
155     }
156 
157     
158 
159 
160 
161     public void performFieldTransformations(List<AccountingLineFieldRenderingTransformation> fieldTransformations, AccountingLine accountingLine, Map unconvertedValues) {
162         int count = 0;
163         for (AccountingLineViewField field : fields) {
164             for (AccountingLineFieldRenderingTransformation transformation : fieldTransformations) {
165                 transformation.transformField(accountingLine, field.getField(), field.getDefinition(), unconvertedValues);
166             }
167         }
168     }
169 
170     
171 
172 
173 
174     public void removeAllActionBlocks() {
175         List<AccountingLineViewField> fieldsToRemove = new ArrayList<AccountingLineViewField>();
176         for (AccountingLineViewField field : fields) {
177             if (field.isActionBlock()) {
178                 fieldsToRemove.add(field);
179             } else {
180                 field.removeAllActionBlocks();
181             }
182         }
183         fields.removeAll(fieldsToRemove);
184     }
185 
186     
187 
188 
189 
190     public void removeUnviewableBlocks(Set<String> unviewableBlocks) {
191         List<AccountingLineViewField> unviewableFields = new ArrayList<AccountingLineViewField>();
192         for (AccountingLineViewField field : fields) {
193             if (unviewableBlocks.contains(field.getName())) {
194                 unviewableFields.add(field);
195             } else {
196                 field.removeUnviewableBlocks(unviewableBlocks);
197             }
198         }
199         fields.removeAll(unviewableFields);
200     }
201 
202     
203 
204 
205 
206     public void readOnlyizeReadOnlyBlocks(Set<String> readOnlyBlocks) {
207         for (AccountingLineViewField field : fields) {
208             field.readOnlyizeReadOnlyBlocks(readOnlyBlocks);
209         }
210     }
211 
212     
213 
214 
215 
216     public List<AccountingLineViewField> getFields() {
217         return fields;
218     }
219 
220     
221 
222 
223 
224     public void setFields(List<AccountingLineViewField> fields) {
225         this.fields = fields;
226     }
227 
228     
229 
230 
231     public boolean isReadOnly() {
232         for (AccountingLineViewField field : fields) {
233             if (!field.isReadOnly()) return false;
234         }
235         return true;
236     }
237 
238     
239 
240 
241     public void readOnlyize() {
242         for (AccountingLineViewField field : fields) {
243             field.readOnlyize();
244         }
245     }
246 
247     
248 
249 
250 
251     public int getDisplayingFieldWidth() {
252         return 1;
253     }
254 
255     
256 
257 
258     public void setEditableBlocks(Set<String> editableBlocks) {
259         for (AccountingLineViewField field : fields) {
260             field.setEditableBlocks(editableBlocks);
261         }
262     }
263 
264     
265 
266 
267     public void setEditable() {
268         for (AccountingLineViewField field : fields) {
269             field.setEditable();
270         }
271     }
272 
273 }