BrightSide Workbench Full Report + Source Code
CustomerOrderLinesGrid.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.Date;
22 import java.util.logging.Level;
23 import java.util.logging.Logger;
24 import org.turro.elephant.context.Application;
25 import org.turro.erp.db.ErpPU;
26 import org.turro.erp.entity.CustomerOrder;
27 import org.turro.erp.reference.OrderReferenceGrid;
28 import org.turro.erp.workorder.CustomerOrderWrapper;
29 import org.turro.financials.contract.ServiceStoreListbox;
30 import org.turro.financials.entity.Contract;
31 import org.turro.financials.entity.Product;
32 import org.turro.financials.model.business.CompanyWrapper;
33 import org.turro.financials.product.ProductCombobox;
34 import org.turro.zkoss.grid.CollectionGrid;
35 import org.turro.zkoss.grid.EditableCell;
36 import org.turro.zkoss.grid.EditableColumn;
37 import org.zkoss.zk.ui.HtmlBasedComponent;
38 import org.zkoss.zul.Row;
39 
44 public class CustomerOrderLinesGrid extends CollectionGrid<CustomerOrder> {
45 
46  private CustomerOrder customerOrder;
47 
48  public void setCustomerOrder(CustomerOrder customerOrder) {
49  this.customerOrder = customerOrder;
51  addColumns();
52  }
53 
55  return customerOrder;
56  }
57 
58  public void setNewValues(CustomerOrder customerOrder) {
59  this.customerOrder = customerOrder;
60  }
61 
62  @Override
63  protected void initiateRow(Row row, CustomerOrder value) {
64  if(value == null) {
65  value = new CustomerOrder();
66  value.setCustomerId(customerOrder.getCustomerId());
67  value.setOrderDate(customerOrder.getOrderDate());
68  value.setOrderId(customerOrder.getOrderId());
69  }
70  row.setValue(value);
71  }
72 
73  @Override
74  protected boolean canDeleteRow(Row row) {
75  CustomerOrder co = (CustomerOrder) row.getValue();
76  return co.getOrderReference() == null;
77  }
78 
79  @Override
80  protected boolean canEditRow(Row row) {
81  CustomerOrder co = (CustomerOrder) row.getValue();
82  return co.getOrderReference() == null;
83  }
84 
85  @Override
86  protected boolean deleteRow(Row row) {
87  CustomerOrder co = (CustomerOrder) row.getValue();
88  if(co.getOrderReference() == null) {
89  new ErpPU().deleteObject(co);
90  return true;
91  }
92  return false;
93  }
94 
95  @Override
96  protected boolean isValid(CustomerOrder v) {
97  return !v.isEmpty();
98  }
99 
100  @Override
101  protected String formatCell(EditableCell editableCell, Object value) {
102  if(value instanceof Contract) {
103  Contract ctc = (Contract) value;
104  return ctc == null ? null : ctc.getPartialDescription();
105  } else if(value instanceof Product) {
106  Product p = (Product) value;
107  return p == null ? null : p.getDescription();
108  }
109  return super.formatCell(editableCell, value);
110  }
111 
112  @Override
113  protected HtmlBasedComponent createEditor(EditableCell editableCell) {
114  if(editableCell.getColumn() instanceof EditableColumn) {
115  EditableColumn ec = (EditableColumn) editableCell.getColumn();
116  if(ec.getJavaClass().equals(Contract.class)) {
117  Object value = getCellValue(editableCell);
119  if(value != null) sslb.setObjectValue((Contract) value);
120  sslb.setMold("select");
121  return sslb;
122  } else if(ec.getJavaClass().equals(Product.class)) {
123  Object value = getCellValue(editableCell);
124  ProductCombobox pcb = new ProductCombobox();
125  if(value != null) pcb.setObjectValue((Product) value);
126  return pcb;
127  }
128  }
129  return super.createEditor(editableCell);
130  }
131 
132  private void addColumns() {
133  try {
134  int fractionDigits = CompanyWrapper.getCurrencyFormatter().getMaximumFractionDigits();
135  addColumn(Application.getString("lQuantity"), "double", "quantity", null, 3, false, false).setWidth("90px");
136  addColumn(Application.getString("lDescription"), String.class, "description", null, 20, false, false).setHflex("2");
137  addColumn(Application.getString("lObjectivePrice"), "double", "price", null, fractionDigits, false, false).setWidth("120px");
138  addColumn(Application.getString("lService"), Contract.class, "service", null, 0, false, false).setHflex("1");
139  addColumn(Application.getString("lBudget"), "boolean", "wantBudget", null, 0, false, false).setWidth("90px");
140  addColumn(Application.getString("lDelivery"), Date.class, "delivery", null, 0, true, false).setWidth("120px");
141  addColumn(Application.getString("lControl"), Date.class, "controlDate", null, 0, true, false).setWidth("120px");
142  } catch (ClassNotFoundException ex) {
143  Logger.getLogger(OrderReferenceGrid.class.getName()).log(Level.SEVERE, null, ex);
144  }
145  }
146 
147 }
static String getString(String key)
void setCustomerId(long customerId)
void setNewValues(CustomerOrder customerOrder)
String formatCell(EditableCell editableCell, Object value)
HtmlBasedComponent createEditor(EditableCell editableCell)
void setCustomerOrder(CustomerOrder customerOrder)
void initiateRow(Row row, CustomerOrder value)
void deleteObject(Object obj)
Definition: Dao.java:162
void setCollection(Collection< V > collection)
EditableColumn addColumn(String label, Class javaClass, String property, String format, int scale, boolean onlyDate, boolean readOnly)
Object getCellValue(EditableCell editableCell)