BrightSide Workbench Full Report + Source Code
VendorGrid.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2012 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 
19 package org.turro.crm.zul.vendor;
20 
21 import java.util.Collection;
22 import org.turro.command.CommandUtil;
23 import org.turro.crm.entity.Vendor;
24 import org.turro.i18n.I_;
25 import org.turro.zkoss.grid.PagingGrid;
26 import org.zkoss.zk.ui.ext.AfterCompose;
27 import org.zkoss.zul.Column;
28 import org.zkoss.zul.Columns;
29 import org.zkoss.zul.Row;
30 import org.zkoss.zul.Rows;
31 
32 
37 public class VendorGrid extends PagingGrid implements AfterCompose {
38 
39  private VendorFilter filter = new VendorFilter();
40  private VendorFilterGrid filterGrid;
41 
43  return filter;
44  }
45 
46  public void setFilterGrid(VendorFilterGrid filterGrid) {
47  this.filterGrid = filterGrid;
48  }
49 
50  public void reload() {
51  if(getRows() != null) {
52  getRows().detach();
53  }
54  addRows();
55  }
56 
57  @Override
58  public void afterCompose() {
59  addColumns();
60  }
61 
62  private void addRows() {
63  if(!filterGrid.hasValues()) return;
64 
65  Collection<Vendor> list = filter.getVendors(filterGrid.getValues());
66 
67  Rows rows = new Rows();
68  appendChild(rows);
69 
70  for(final Vendor cd : list) {
71  Row row = new Row();
72  rows.appendChild(row);
73  row.appendChild(CommandUtil.getLinkOrSpace(cd));
74  }
75 
76  setRowCount(list.size());
77  }
78 
79  private void addColumns() {
80  Columns cols = new Columns();
81  appendChild(cols);
82 
83  Column col = new Column(I_.get("Vendor"));
84  cols.appendChild(col);
85  }
86 
87 }
static HtmlBasedComponent getLinkOrSpace(Object entity)
Collection< Vendor > getVendors(List< IFilterValue > values)
void setFilterGrid(VendorFilterGrid filterGrid)
Definition: VendorGrid.java:46
List< IFilterValue > getValues()
Rows getRows(boolean create)