BrightSide Workbench Full Report + Source Code
CustomerOwnersGrid.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.crm.zul.customer;
20 
21 import java.util.Date;
22 import org.turro.crm.entity.*;
23 import org.turro.crm.zul.vendor.FormulaListbox;
24 import org.turro.crm.zul.vendor.VendorCombobox;
25 import org.turro.i18n.I_;
26 import org.turro.jpa.entity.EntityCollections;
27 import org.turro.zkoss.grid.CollectionGrid;
28 import org.turro.zkoss.grid.EditableCell;
29 import org.zkoss.zk.ui.HtmlBasedComponent;
30 import org.zkoss.zul.Row;
31 
36 public class CustomerOwnersGrid extends CollectionGrid<CustomerOwner> {
37 
38  private Customer customer;
39 
40  public CustomerOwnersGrid() {
41  addColumns();
42  }
43 
44  public void setCustomer(Customer customer) {
45  this.customer = customer;
46  setCollection(customer.getOwnedBy());
47  }
48 
49  @Override
50  protected void initiateRow(Row row, CustomerOwner value) {
51  if(value == null) {
52  value = new CustomerOwner();
53  value.setOwningDate(new Date());
54  value.setCustomer(customer);
55  customer.getOwnedBy().add(value);
56  }
57  row.setValue(value);
58  }
59 
60  @Override
61  protected boolean deleteRow(Row row) {
62  CustomerOwner t = (CustomerOwner) row.getValue();
63  EntityCollections.entities(customer.getOwnedBy()).remove(t);
64  t.setCustomer(null);
65  return true;
66  }
67 
68  @Override
69  protected boolean isValid(CustomerOwner v) {
70  return !v.isEmpty();
71  }
72 
73  @Override
74  protected HtmlBasedComponent createEditor(EditableCell editableCell) {
75  if(editableCell.getCellIndex() == 0) {
76  Object value = getCellValue(editableCell);
77  VendorCombobox cdc = new VendorCombobox();
78  if(value != null) cdc.setObjectValue((Vendor) value);
79  return cdc;
80  } else if(editableCell.getCellIndex() == 1) {
81  Object value = getCellValue(editableCell);
82  FormulaListbox cdc = new FormulaListbox();
84  cdc.setMold("select");
85  if(value != null) cdc.setObjectValue((Formula) value);
86  return cdc;
87  } if(editableCell.getCellIndex() == 2) {
88  Object value = getCellValue(editableCell);
89  FormulaListbox cdc = new FormulaListbox();
91  cdc.setMold("select");
92  if(value != null) cdc.setObjectValue((Formula) value);
93  return cdc;
94  }
95  return super.createEditor(editableCell);
96  }
97 
98  @Override
99  protected String formatCell(EditableCell editableCell, Object value) {
100  if(editableCell.getCellIndex() == 0) {
101  return value != null ? ((Vendor) value).getName() : null;
102  } else if(editableCell.getCellIndex() == 1) {
103  return value != null ? ((Formula) value).getName() : null;
104  } else if(editableCell.getCellIndex() == 2) {
105  return value != null ? ((Formula) value).getName() : null;
106  }
107  return super.formatCell(editableCell, value);
108  }
109 
110  private void addColumns() {
111  addColumn(I_.get("Vendor"), Vendor.class, "vendor", null, 0, false, false).setHflex("6");
112  addColumn(I_.get("Comission"), Formula.class, "comission", null, 0, false, false).setHflex("2");
113  addColumn(I_.get("Alert"), Formula.class, "alert", null, 0, false, false).setHflex("2");
114  addColumn(I_.get("Creation"), Date.class, "owningDate", null, 0, true, false).setHflex("1");
115  }
116 
117 }
118 
void setOwningDate(Date owningDate)
void setCustomer(Customer customer)
Set< CustomerOwner > getOwnedBy()
Definition: Customer.java:88
String formatCell(EditableCell editableCell, Object value)
void initiateRow(Row row, CustomerOwner value)
HtmlBasedComponent createEditor(EditableCell editableCell)
void setFormulaType(FormulaType formulaType)
static String get(String msg)
Definition: I_.java:41
static EntityCollections entities(Collection values)
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)