BrightSide Workbench Full Report + Source Code
WorkOrderGrid.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.erp.workorder;
19 
20 import java.util.Collection;
21 import org.turro.command.CommandUtil;
22 import org.turro.elephant.context.Application;
23 import org.turro.elephant.util.DateFormats;
24 import org.turro.erp.entity.WorkOrder;
25 import org.turro.zkoss.grid.PagingGrid;
26 import org.zkoss.zk.ui.ext.AfterCompose;
27 import org.zkoss.zul.*;
28 
33 public class WorkOrderGrid extends PagingGrid implements AfterCompose {
34 
35  private WorkOrderFilter filter = new WorkOrderFilter();
36  private WorkOrderFilterGrid filterGrid;
37 
39  return filter;
40  }
41 
42  public void setFilterGrid(WorkOrderFilterGrid filterGrid) {
43  this.filterGrid = filterGrid;
44  }
45 
46  public void reload() {
47  if(getRows() != null) {
48  getRows().detach();
49  }
50  addRows();
51  }
52 
53  @Override
54  public void afterCompose() {
55  addColumns();
56  }
57 
58  private void addRows() {
59  if(!filterGrid.hasValues()) return;
60 
61  Collection<WorkOrder> list = filter.getWorkOrders(filterGrid.getValues());
62 
63  Rows rows = getRows(true);
64  appendChild(rows);
65 
66  boolean openGroup = list.size() < 40;
67 
68  for(final WorkOrder workOrder : list) {
69  filter.checkGroup(this, workOrder, openGroup);
70  Row row = new Row();
71  rows.appendChild(row);
72  if(workOrder.isDraft() && !workOrder.isProductOrder()) {
73  row.setSclass("draft");
74  }
75  row.appendChild(new Label(workOrder.getId() + ""));
76  row.appendChild(new Label(DateFormats.format(workOrder.getWorkOrderDate(), true)));
77  row.appendChild(new Label(workOrder.getWorkOrderId() + ""));
78  row.appendChild(CommandUtil.getLink(workOrder));
79 // row.appendChild(new Label(DecimalFormats.format(doc.getTotalAmount(),
80 // DecimalFormats.getStringFormat(doc.getCurrency().getDefaultFractionDigits()))));
81  }
82 
83  setRowCount(list.size());
84  }
85 
86  private void addColumns() {
87  Columns cols = getColumns(true);
88  appendChild(cols);
89 
90  Column col = new Column("#", null, "80px");
91  cols.appendChild(col);
92 
93  col = new Column(Application.getString("lDate"), null, "100px");
94  cols.appendChild(col);
95 
96  col = new Column(Application.getString("lNumber"), null, "180px");
97  cols.appendChild(col);
98 
99  col = new Column(Application.getString("lDescription"));
100  cols.appendChild(col);
101 
102 // col = new Column(Application.getString("lAmount"), null, "120px");
103 // col.setAlign("right");
104 // cols.appendChild(col);
105  }
106 
107 }
void checkGroup(Grid grid, WorkOrder workOrder, boolean open)
Collection< WorkOrder > getWorkOrders(List< IFilterValue > values)
void setFilterGrid(WorkOrderFilterGrid filterGrid)
List< IFilterValue > getValues()
Columns getColumns(boolean create)
Rows getRows(boolean create)