19 package org.turro.financials.business;
21 import java.util.ArrayList;
22 import java.util.List;
24 import org.turro.financials.entity.Company;
25 import org.turro.financials.entity.Contract;
26 import org.turro.financials.entity.Department;
27 import org.turro.financials.entity.Headquarters;
28 import org.turro.financials.entity.Service;
29 import org.turro.financials.model.business.CompanyWrapper;
30 import org.turro.i18n.I_;
31 import org.zkoss.zk.ui.ext.AfterCompose;
32 import org.zkoss.zul.Tree;
33 import org.zkoss.zul.Treechildren;
34 import org.zkoss.zul.Treeitem;
40 public class CompanyTree extends Tree implements AfterCompose {
48 appendChild(
new Treechildren());
50 Treeitem li =
new Treeitem(company.
getName(), company);
51 li.appendChild(
new Treechildren());
52 getTreechildren().appendChild(li);
58 List<Contract> contracts =
new ArrayList<>();
59 processItem(getSelectedItem(), contracts);
63 private void processItem(Treeitem selectedItem, List<Contract> contracts) {
64 if(selectedItem !=
null) {
65 Object value = selectedItem.getValue();
68 }
else if(selectedItem.getTreechildren() !=
null) {
69 for(Treeitem ti : selectedItem.getTreechildren().getItems()) {
70 processItem(ti, contracts);
76 private void fillServices(Treeitem root) {
77 Company company = root.getValue();
78 Treeitem li =
new Treeitem(I_.get(
"Services"));
79 li.appendChild(
new Treechildren());
80 root.getTreechildren().appendChild(li);
81 for(Service service : company.getServices()) {
82 Treeitem lis =
new Treeitem(service.getName(), service);
83 lis.setTooltiptext(lis.getLabel());
84 li.getTreechildren().appendChild(lis);
85 fillContracts(lis, service.getStores());
89 private void fillHeadquarters(Treeitem root) {
90 Company company = root.getValue();
91 Treeitem li =
new Treeitem(I_.get(
"Headquarters"));
92 li.appendChild(
new Treechildren());
93 root.getTreechildren().appendChild(li);
94 for(Headquarters headquarters : company.getHeadquarters()) {
95 Treeitem lis =
new Treeitem(headquarters.getName(), headquarters);
96 lis.setTooltiptext(lis.getLabel());
97 li.getTreechildren().appendChild(lis);
98 fillDepartments(lis, headquarters.getDepartments());
102 private void fillDepartments(Treeitem root, Set<Department> departments) {
103 root.appendChild(
new Treechildren());
104 Treeitem li =
new Treeitem(I_.get(
"Departments"));
105 li.appendChild(
new Treechildren());
106 root.getTreechildren().appendChild(li);
107 for(Department department : departments) {
108 Treeitem lis =
new Treeitem(department.getName(), department);
109 lis.setTooltiptext(lis.getLabel());
110 li.getTreechildren().appendChild(lis);
111 fillContracts(lis, department.getStores());
115 private void fillContracts(Treeitem root, Set<Contract> stores) {
116 root.appendChild(
new Treechildren());
117 for(Contract contract : stores) {
118 Treeitem lis =
new Treeitem(contract.getPartialDescription(), contract);
119 lis.setTooltiptext(lis.getLabel());
120 root.getTreechildren().appendChild(lis);
List< Contract > getContracts()
static Company getDefaultCompany()