BrightSide Workbench Full Report + Source Code
product/ProductGrid.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.product;
19 
20 import java.util.Collection;
21 import org.turro.command.CommandUtil;
22 import org.turro.elephant.util.DecimalFormats;
23 import org.turro.financials.entity.Product;
24 import org.turro.i18n.I_;
25 import org.turro.zkoss.filter.FilterGrid;
26 import org.turro.zkoss.grid.PagingGrid;
27 import org.zkoss.zk.ui.ext.AfterCompose;
28 import org.zkoss.zul.*;
29 
34 public class ProductGrid extends PagingGrid implements AfterCompose {
35 
36  private ProductFilter filter = new ProductFilter();
37  private FilterGrid filterGrid;
38 
40  return filter;
41  }
42 
43  public void setFilterGrid(FilterGrid filterGrid) {
44  this.filterGrid = filterGrid;
45  }
46 
47  public void reload() {
48  if(getRows() != null) {
49  getRows().detach();
50  }
51  addRows();
52  }
53 
54  @Override
55  public void afterCompose() {
56  addColumns();
57  }
58 
59  private void addRows() {
60  if(!filterGrid.hasValues()) {
61  return;
62  }
63  Collection<Product> list = filter.getProducts(filterGrid.getValues());
64 
65  Rows rows = new Rows();
66  appendChild(rows);
67 
68  for(final Product prod : list) {
69  //filter.checkGroup(prod);
70  Row row = new Row();
71  rows.appendChild(row);
72  row.appendChild(new Label(prod.getProductCodeStr()));
73  row.appendChild(CommandUtil.getAdapter(prod).setLabel(prod.getDescription(true)));
74  row.appendChild(new Label(DecimalFormats.format(prod.getTax())));
75  row.appendChild(new Label(DecimalFormats.format(prod.getProductPrice())));
76  }
77 
78  setRowCount(list.size());
79  }
80 
81  private void addColumns() {
82  Columns cols = new Columns();
83  appendChild(cols);
84 
85  Column col = new Column(I_.get("Identifier"), null, "180px");
86  cols.appendChild(col);
87 
88  col = new Column(I_.get("Description"));
89  cols.appendChild(col);
90 
91  col = new Column(I_.get("Tax"), null, "90px");
92  col.setAlign("right");
93  cols.appendChild(col);
94 
95  col = new Column(I_.get("Price"), null, "120px");
96  col.setAlign("right");
97  cols.appendChild(col);
98  }
99 
100 }
Collection< Product > getProducts(List< IFilterValue > values)
List< IFilterValue > getValues()
Rows getRows(boolean create)