BrightSide Workbench Full Report + Source Code
DocumentDefinitionGrid.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.document;
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.DocumentDefinition;
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 DocumentDefinitionGrid extends PagingGrid implements AfterCompose {
42 
43  @Override
44  public void afterCompose() {
45  addColumns();
46  addRows();
47  }
48 
49  private void addRows() {
50  List<DocumentDefinition> list = new FinancialsPU().getResultList(
51  "select docdef from DocumentDefinition as docdef order by docdef.name"
52  );
53  Rows rows = new Rows();
54  appendChild(rows);
55 
56  for(final DocumentDefinition dd : list) {
57  Row row = new Row();
58  rows.appendChild(row);
59  row.appendChild(new Label(dd.getId() + ""));
60  Label l = new Label(dd.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(dd.isAutoNumbered())));
70  }
71 
72  setRowCount(list.size());
73  }
74 
75  private void addColumns() {
76  Columns cols = new Columns();
77  appendChild(cols);
78 
79  Column col = new Column("#", null, "25px");
80  cols.appendChild(col);
81 
82  col = new Column(I_.get("Name"));
83  cols.appendChild(col);
84 
85  col = new Column(I_.get("Autonumbered"), null, "100px");
86  cols.appendChild(col);
87  }
88 
89 }