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