BrightSide Workbench Full Report + Source Code
ContractGrid.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.contract;
19 
20 import java.util.Collection;
21 import org.turro.command.CommandUtil;
22 import org.turro.elephant.util.BooleanFormats;
23 import org.turro.financials.contract.filter.ContractFilterGrid;
24 import org.turro.financials.entity.Contract;
25 import org.turro.i18n.I_;
26 import org.turro.zkoss.grid.PagingGrid;
27 import org.zkoss.zk.ui.ext.AfterCompose;
28 import org.zkoss.zul.*;
29 
34 public class ContractGrid extends PagingGrid implements AfterCompose {
35 
36  private ContractFilter filter = new ContractFilter();
37  private ContractFilterGrid filterGrid;
38 
40  return filter;
41  }
42 
43  public void setFilterGrid(ContractFilterGrid 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()) return;
61 
62  Collection<Contract> list = filter.getContracts(filterGrid.getValues());
63 
64  Rows rows = new Rows();
65  appendChild(rows);
66 
67  boolean openGroup = list.size() < 40;
68 
69  for(final Contract cd : list) {
70  filter.checkGroup(this, cd, openGroup);
71  Row row = new Row();
72  rows.appendChild(row);
73  if(!cd.isActive()) {
74  row.setSclass("draft");
75  }
76  row.appendChild(new Label(cd.getId() + ""));
77  row.appendChild(CommandUtil.getLink(cd));
78 
79  row.appendChild(new Label(BooleanFormats.format(cd.isStock())));
80 // row.appendChild(new Label(BooleanFormats.format(cd.isCash())));
81  }
82 
83  setRowCount(list.size());
84  }
85 
86  private void addColumns() {
87  Columns cols = new Columns();
88  appendChild(cols);
89 
90  Column col = new Column("#", null, "50px");
91  cols.appendChild(col);
92 
93  col = new Column(I_.get("Name"));
94  cols.appendChild(col);
95 
96  col = new Column(I_.get("Store"), null, "100px");
97  cols.appendChild(col);
98 
99 // col = new Column(Labels.getLink("Cash"), null, "100px");
100 // cols.appendChild(col);
101  }
102 
103 }
Collection< Contract > getContracts(List< IFilterValue > values)
void checkGroup(Grid grid, Contract contract, boolean open)
void setFilterGrid(ContractFilterGrid filterGrid)
List< IFilterValue > getValues()
Rows getRows(boolean create)