BrightSide Workbench Full Report + Source Code
CustomerOrderGrid.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2012 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 
19 package org.turro.erp.sales;
20 
21 import java.util.Collection;
22 import org.turro.string.Strings;
23 import org.turro.elephant.context.Application;
24 import org.turro.elephant.util.DateFormats;
25 import org.turro.erp.entity.CustomerOrder;
26 import org.turro.erp.menu.ErpMenu;
27 import org.turro.zkoss.grid.PagingGrid;
28 import org.zkoss.zk.ui.event.Event;
29 import org.zkoss.zk.ui.event.EventListener;
30 import org.zkoss.zk.ui.event.Events;
31 import org.zkoss.zk.ui.ext.AfterCompose;
32 import org.zkoss.zul.*;
33 
38 public class CustomerOrderGrid extends PagingGrid implements AfterCompose {
39 
40  private CustomerOrderFilter filter = new CustomerOrderFilter();
41  private CustomerOrderFilterGrid filterGrid;
42 
44  return filter;
45  }
46 
47  public void setFilterGrid(CustomerOrderFilterGrid filterGrid) {
48  this.filterGrid = filterGrid;
49  }
50 
51  public void reload() {
52  if(getRows() != null) {
53  getRows().detach();
54  }
55  addRows();
56  }
57 
58  @Override
59  public void afterCompose() {
60  addColumns();
61  }
62 
63  private void addRows() {
64  if(!filterGrid.hasValues()) return;
65 
66  Collection<CustomerOrder> list = filter.getCustomerOrders(filterGrid.getValues());
67 
68  Rows rows = getRows(true);
69  appendChild(rows);
70 
71  boolean openGroup = list.size() < 40;
72 
73  for(final CustomerOrder customerOrder : list) {
74  filter.checkGroup(this, customerOrder, openGroup);
75  Row row = new Row();
76  rows.appendChild(row);
77  row.appendChild(new Label(DateFormats.formatNull(customerOrder.getOrderDate(), true)));
78  row.appendChild(new Label(customerOrder.getOrderId() + ""));
79  Hbox hbox = new Hbox();
80  row.appendChild(hbox);
81  A b = new A(Strings.truncateAndWarn(customerOrder.getDescription(), 50));
82  b.setImage("/_zul/images/order.png");
83  b.addEventListener(Events.ON_CLICK, new EventListener() {
84  @Override
85  public void onEvent(Event event) throws Exception {
86  ErpMenu.showCustomerOrder(customerOrder.getId());
87  }
88  });
89  hbox.appendChild(b);
90 // row.appendChild(new Label(DecimalFormats.format(doc.getTotalAmount(),
91 // DecimalFormats.getStringFormat(doc.getCurrency().getDefaultFractionDigits()))));
92  }
93 
94  setRowCount(list.size());
95  }
96 
97  private void addColumns() {
98  Columns cols = getColumns(true);
99  appendChild(cols);
100 
101  Column col = new Column(Application.getString("lDate"), null, "100px");
102  cols.appendChild(col);
103 
104  col = new Column(Application.getString("lNumber"), null, "180px");
105  cols.appendChild(col);
106 
107  col = new Column(Application.getString("lDescription"));
108  cols.appendChild(col);
109 
110 // col = new Column(Application.getString("lAmount"), null, "120px");
111 // col.setAlign("right");
112 // cols.appendChild(col);
113  }
114 
115 }
116 
static String formatNull(Date d, boolean dateOnly)
static void showCustomerOrder(Long id)
Definition: ErpMenu.java:182
void checkGroup(Grid grid, CustomerOrder customerOrder, boolean open)
Collection< CustomerOrder > getCustomerOrders(List< IFilterValue > values)
void setFilterGrid(CustomerOrderFilterGrid filterGrid)
List< IFilterValue > getValues()
Columns getColumns(boolean create)
Rows getRows(boolean create)