BrightSide Workbench Full Report + Source Code
BatchOfsGrid.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.financials.batchof;
19 
20 import java.util.Collection;
21 import org.turro.command.CommandUtil;
22 import org.turro.elephant.util.DateFormats;
23 import org.turro.elephant.util.DecimalFormats;
24 import org.turro.financials.batchof.filter.BatchOfFilterGrid;
25 import org.turro.financials.entity.BatchOf;
26 import org.turro.i18n.I_;
27 import org.turro.zkoss.grid.PagingGrid;
28 import org.zkoss.zk.ui.ext.AfterCompose;
29 import org.zkoss.zul.*;
30 
35 public class BatchOfsGrid extends PagingGrid implements AfterCompose {
36 
37  private BatchOfFilter filter = new BatchOfFilter();
38  private BatchOfFilterGrid filterGrid;
39 
41  return filter;
42  }
43 
44  public void setFilterGrid(BatchOfFilterGrid filterGrid) {
45  this.filterGrid = filterGrid;
46  }
47 
48  public void reload() {
49  if(getRows() != null) {
50  getRows().detach();
51  }
52  addRows();
53  }
54 
55  @Override
56  public void afterCompose() {
57  addColumns();
58  }
59 
60  private void addRows() {
61  if(!filterGrid.hasValues()) return;
62 
63  Collection<BatchOf> list = filter.getBatchOfs(filterGrid.getValues());
64 
65  Rows rows = new Rows();
66  appendChild(rows);
67 
68  for(final BatchOf batchOf : list) {
69  Row row = new Row();
70  rows.appendChild(row);
71  if(batchOf.getBatch().isDraft()) {
72  row.setSclass("draft");
73  }
74  row.appendChild(new Label(batchOf.getId() + ""));
75  row.appendChild(new Label(DateFormats.format(batchOf.getBatch().getReceiptDate(), true)));
76  row.appendChild(new Label(DateFormats.format(batchOf.getBatch().getDocumentDate(), true)));
77  row.appendChild(new Label(batchOf.getBatch().getDocumentNumber()));
78  row.appendChild(CommandUtil.getLinkOrSpace(batchOf));
79  row.appendChild(new Label(DecimalFormats.format(batchOf.getBatch().getTotalAmount(),
80  DecimalFormats.getStringFormat(batchOf.getBatch().getCurrency().getDefaultFractionDigits()))));
81  }
82 
83  setRowCount(list.size());
84  }
85 
86  private void addColumns() {
87  Columns cols = getColumns(true);
88  appendChild(cols);
89 
90  Column col = new Column("#", null, "40px");
91  cols.appendChild(col);
92 
93  col = new Column(I_.get("Receipt/Issue"), null, "120px");
94  cols.appendChild(col);
95 
96  col = new Column(I_.get("Date"), null, "90px");
97  cols.appendChild(col);
98 
99  col = new Column(I_.get("Number"), null, "180px");
100  cols.appendChild(col);
101 
102  col = new Column(I_.get("Batch of"));
103  cols.appendChild(col);
104 
105  col = new Column(I_.get("Amount"), null, "120px");
106  col.setAlign("right");
107  cols.appendChild(col);
108  }
109 
110 }
Collection< BatchOf > getBatchOfs(List< IFilterValue > values)
void setFilterGrid(BatchOfFilterGrid filterGrid)
List< IFilterValue > getValues()
Columns getColumns(boolean create)
Rows getRows(boolean create)