BrightSide Workbench Full Report + Source Code
RegisterEntriesGrid.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.assets;
19 
20 import java.util.Collection;
21 import org.turro.elephant.util.DateFormats;
22 import org.turro.elephant.util.DecimalFormats;
23 import org.turro.financials.entity.FixedAsset;
24 import org.turro.financials.entity.RegisterEntry;
25 import org.turro.financials.menu.FinancialsMenu;
26 import org.turro.i18n.I_;
27 import org.turro.math.Zero;
28 import org.turro.zkoss.grid.PagingGrid;
29 import org.turro.zkoss.label.LabelTypes;
30 import org.zkoss.zk.ui.event.Event;
31 import org.zkoss.zk.ui.event.EventListener;
32 import org.zkoss.zk.ui.event.Events;
33 import org.zkoss.zk.ui.ext.AfterCompose;
34 import org.zkoss.zul.A;
35 import org.zkoss.zul.Column;
36 import org.zkoss.zul.Columns;
37 import org.zkoss.zul.Label;
38 import org.zkoss.zul.Row;
39 import org.zkoss.zul.Rows;
40 import org.zkoss.zul.Vlayout;
41 
46 public class RegisterEntriesGrid extends PagingGrid implements AfterCompose {
47 
48  private FixedAsset fixedAsset;
49 
51  return fixedAsset;
52  }
53 
54  public void setFixedAsset(FixedAsset fixedAsset) {
55  this.fixedAsset = fixedAsset;
56  }
57 
58  public void reload() {
59  getRows().detach();
60  addRows();
61  }
62 
63  @Override
64  public void afterCompose() {
65  addColumns();
66  addRows();
67  }
68 
69  private void addRows() {
70  Collection<RegisterEntry> list = new FixedAssetWrapper(fixedAsset).getEntries();
71 
72  Rows rows = new Rows();
73  appendChild(rows);
74 
75  for(final RegisterEntry re : list) {
76  if(!Zero.near(re.getDebit(), 2)) {
77  Row row = new Row();
78  rows.appendChild(row);
79 
80  row.appendChild(new Label(re.getRegister().getId() + ""));
81  row.appendChild(new Label(DateFormats.format(re.getRegister().getRegisterDate(), true)));
82  A b = new A();
83  b.addEventListener(Events.ON_CLICK, new EventListener() {
84  @Override
85  public void onEvent(Event event) throws Exception {
86  FinancialsMenu.showRegister(re.getRegister());
87  }
88  });
89  Vlayout vbox = new Vlayout();
90  vbox.appendChild(LabelTypes.getSoftLabel(re.getAccountString()));
91  vbox.appendChild(LabelTypes.getCaptionLabel(re.getRegister().getView().getName()));
92  b.appendChild(vbox);
93  row.appendChild(b);
94  row.appendChild(new Label(DecimalFormats.format(re.getDebit())));
95  }
96  }
97 
98  setRowCount(list.size());
99  }
100 
101  private void addColumns() {
102  Columns cols = getColumns(true);
103  appendChild(cols);
104 
105  Column col = new Column("#", null, "60px");
106  cols.appendChild(col);
107 
108  col = new Column(I_.get("Date"), null, "90px");
109  cols.appendChild(col);
110 
111  col = new Column(I_.get("Account"), null, "90%");
112  cols.appendChild(col);
113 
114  col = new Column(I_.get("Amount"), null, "120px");
115  col.setAlign("right");
116  cols.appendChild(col);
117  }
118 
119 }
static final String format(Date d, boolean dateOnly)
static boolean near(double value, int digits)
Definition: Zero.java:30
Columns getColumns(boolean create)
Rows getRows(boolean create)