BrightSide Workbench Full Report + Source Code
ContractDefinitionGrid.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.List;
21 import org.turro.elephant.util.BooleanFormats;
22 import org.turro.financials.db.FinancialsPU;
23 import org.turro.financials.entity.ContractDefinition;
24 import org.turro.financials.menu.FinancialsMenu;
25 import org.turro.i18n.I_;
26 import org.turro.zkoss.grid.PagingGrid;
27 import org.zkoss.zk.ui.event.Event;
28 import org.zkoss.zk.ui.event.EventListener;
29 import org.zkoss.zk.ui.event.Events;
30 import org.zkoss.zk.ui.ext.AfterCompose;
31 import org.zkoss.zul.Column;
32 import org.zkoss.zul.Columns;
33 import org.zkoss.zul.Label;
34 import org.zkoss.zul.Row;
35 import org.zkoss.zul.Rows;
36 
41 public class ContractDefinitionGrid extends PagingGrid implements AfterCompose {
42 
43  @Override
44  public void afterCompose() {
45  addColumns();
46  addRows();
47  }
48 
49  private void addRows() {
50  List<ContractDefinition> list = new FinancialsPU().getResultList(
51  "select ctcdef from ContractDefinition as ctcdef order by ctcdef.name"
52  );
53  Rows rows = new Rows();
54  appendChild(rows);
55 
56  for(final ContractDefinition cd : list) {
57  Row row = new Row();
58  rows.appendChild(row);
59  row.appendChild(new Label(cd.getId() + ""));
60  Label l = new Label(cd.getName());
61  l.setStyle("cursor:pointer");
62  l.addEventListener(Events.ON_CLICK, new EventListener() {
63  @Override
64  public void onEvent(Event event) throws Exception {
66  }
67  });
68  row.appendChild(l);
69  row.appendChild(new Label(BooleanFormats.format(cd.isStock())));
70  row.appendChild(new Label(BooleanFormats.format(cd.isCash())));
71  }
72 
73  setRowCount(list.size());
74  }
75 
76  private void addColumns() {
77  Columns cols = new Columns();
78  appendChild(cols);
79 
80  Column col = new Column("#", null, "80px");
81  cols.appendChild(col);
82 
83  col = new Column(I_.get("Name"));
84  cols.appendChild(col);
85 
86  col = new Column(I_.get("Store"), null, "100px");
87  cols.appendChild(col);
88 
89  col = new Column(I_.get("Cash"), null, "100px");
90  cols.appendChild(col);
91  }
92 
93 }