BrightSide Workbench Full Report + Source Code
BalanceTopItem.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 java.util.List;
21 import org.turro.financials.entity.MajorAccount;
22 import org.turro.i18n.I_;
23 import org.turro.zkoss.label.LabelTypes;
24 import org.zkoss.zk.ui.ext.AfterCompose;
25 import org.zkoss.zul.Treecell;
26 import org.zkoss.zul.Treechildren;
27 import org.zkoss.zul.Treeitem;
28 import org.zkoss.zul.Treerow;
29 import org.zkoss.zul.Vbox;
30 
35 public class BalanceTopItem extends Treeitem implements AfterCompose {
36 
37  private Treechildren children;
38  private boolean loadOnDemand;
39 
40  public BalanceTopItem(boolean loadOnDemand) {
41  super();
42  this.loadOnDemand = loadOnDemand;
43  }
44 
45  @Override
46  public BalanceTree getTree() {
47  return (BalanceTree) super.getTree();
48  }
49 
50  public void showContents() {
51  fillFolder();
52  setOpen(true);
53  }
54 
55  public void reloadContents() {
56  children.getChildren().clear();
57  showContents();
58  }
59 
60  private void addCells() {
61  Double[] dA = getTree().getFilter().getAmountsA("");
62  Treerow row = new Treerow();
63  row.setSclass("topItem");
64  appendChild(row);
65  row.appendChild(new Treecell(I_.get("Account balance")));
66  row.appendChild(new Treecell(""));
67  if(getTree().getFilter().hasTwoGroup()) {
68  Double[] dB = getTree().getFilter().getAmountsB("");
69  row.appendChild(getGroupMoneyCell(getTree(), dA[0], dB[0]));
70  row.appendChild(getGroupMoneyCell(getTree(), dA[1], dB[1]));
71  row.appendChild(getGroupMoneyCell(getTree(), dA[0] - dA[1], dB[0] - dB[1]));
72  } else {
73  row.appendChild(new Treecell(getTree().formatCurrency(dA[0])));
74  row.appendChild(new Treecell(getTree().formatCurrency(dA[1])));
75  row.appendChild(new Treecell(getTree().formatCurrency(dA[0] - dA[1])));
76  }
77  }
78 
79  private void addChildrenSpace() {
80  children = new Treechildren();
81  appendChild(children);
82  fillFolder();
83  setOpen(true);
84  }
85 
86  public boolean isLoadOnDemand() {
87  return loadOnDemand;
88  }
89 
90  public void setLoadOnDemand(boolean loadOnDemand) {
91  this.loadOnDemand = loadOnDemand;
92  }
93 
94  private void fillFolder() {
95  if(children.getChildren().isEmpty()) {
96  List<MajorAccount> l = getTree().getFilter().getMajorAccounts("");
97  for(MajorAccount ma : l) {
98  BalanceMajorItem bmi = new BalanceMajorItem(ma, true);
99  children.appendChild(bmi);
100  bmi.afterCompose();
101  }
102  }
103  }
104 
105  @Override
107  return (BalanceMajorItem) getParentItem();
108  }
109 
110  @Override
111  public void afterCompose() {
112  addCells();
113  addChildrenSpace();
114  }
115 
116  public static Treecell getGroupMoneyCell(BalanceTree tree, Double a, Double b) {
117  Treecell tc = new Treecell();
118  Vbox vbox = new Vbox();
119  vbox.setAlign("end");
120  vbox.appendChild(LabelTypes.getSoftLabel(tree.formatCurrency(a)));
121  vbox.appendChild(LabelTypes.getSoftLabel(tree.formatCurrency(b)));
122  vbox.appendChild(LabelTypes.getCaptionLabel(tree.formatCurrency(a - b)));
123  tc.appendChild(vbox);
124  return tc;
125  }
126 
127 }
List< MajorAccount > getMajorAccounts(String parent)
static Treecell getGroupMoneyCell(BalanceTree tree, Double a, Double b)
static String get(String msg)
Definition: I_.java:41
static Label getCaptionLabel(String value)
Definition: LabelTypes.java:40
static Label getSoftLabel(String value)
Definition: LabelTypes.java:28