BrightSide Workbench Full Report + Source Code
BalanceAccountItem.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.register;
19 
20 import org.turro.financials.entity.Account;
21 import org.turro.financials.menu.FinancialsMenu;
22 import org.zkoss.zk.ui.event.Event;
23 import org.zkoss.zk.ui.event.EventListener;
24 import org.zkoss.zk.ui.event.Events;
25 import org.zkoss.zk.ui.ext.AfterCompose;
26 import org.zkoss.zul.Toolbarbutton;
27 import org.zkoss.zul.Treecell;
28 import org.zkoss.zul.Treeitem;
29 import org.zkoss.zul.Treerow;
30 
35 public class BalanceAccountItem extends Treeitem implements AfterCompose {
36 
37  private Account account;
38 
39  public BalanceAccountItem(Account account) {
40  super();
41  this.account = account;
42  }
43 
44  @Override
45  public BalanceTree getTree() {
46  return (BalanceTree) super.getTree();
47  }
48 
49  private void addCells() {
50  Double[] dA = getTree().getFilter().getAmountsA(account.getId());
51  Treerow row = new Treerow();
52  row.setSclass("account");
53  appendChild(row);
54  row.appendChild(new Treecell(account.getId()));
55  row.appendChild(new Treecell(account.getDescription()));
56  if(getTree().getFilter().hasTwoGroup()) {
57  Double[] dB = getTree().getFilter().getAmountsB(account.getId());
58  row.appendChild(BalanceTopItem.getGroupMoneyCell(getTree(), dA[0], dB[0]));
59  row.appendChild(BalanceTopItem.getGroupMoneyCell(getTree(), dA[1], dB[1]));
60  row.appendChild(BalanceTopItem.getGroupMoneyCell(getTree(), dA[0] - dA[1], dB[0] - dB[1]));
61  } else {
62  row.appendChild(new Treecell(getTree().formatCurrency(dA[0])));
63  row.appendChild(new Treecell(getTree().formatCurrency(dA[1])));
64  row.appendChild(new Treecell(getTree().formatCurrency(dA[0] - dA[1])));
65  }
66  Toolbarbutton tb = new Toolbarbutton();
67  tb.setImage("/_zul/images/statement.png");
68  tb.addEventListener(Events.ON_CLICK, new EventListener() {
69  @Override
70  public void onEvent(Event event) throws Exception {
71  FinancialsMenu.showStatement(account.getId() + "*");
72  }
73  });
74  Treecell tc = new Treecell();
75  tc.appendChild(tb);
76  row.appendChild(tc);
77  }
78 
79  @Override
82  }
83 
84  @Override
85  public void afterCompose() {
86  addCells();
87  }
88 
89 }
static Treecell getGroupMoneyCell(BalanceTree tree, Double a, Double b)