BrightSide Workbench Full Report + Source Code
CampaignVendorGrid.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2013 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.Campaign;
22 import org.turro.crm.entity.CampaignVendor;
23 import org.turro.crm.entity.Formula;
24 import org.turro.crm.entity.FormulaType;
25 import org.turro.crm.entity.Vendor;
26 import org.turro.crm.zul.vendor.FormulaListbox;
27 import org.turro.crm.zul.vendor.VendorCombobox;
28 import org.turro.i18n.I_;
29 import org.turro.jpa.entity.EntityCollections;
30 import org.turro.zkoss.grid.CollectionGrid;
31 import org.turro.zkoss.grid.EditableCell;
32 import org.zkoss.zk.ui.HtmlBasedComponent;
33 import org.zkoss.zul.Row;
34 
39 public class CampaignVendorGrid extends CollectionGrid<CampaignVendor> {
40 
41  private Campaign campaign;
42 
43  public CampaignVendorGrid() {
44  addColumns();
45  }
46 
47  public void setCampaign(Campaign campaign) {
48  this.campaign = campaign;
50  }
51 
52  @Override
53  protected void initiateRow(Row row, CampaignVendor value) {
54  if(value == null) {
55  value = new CampaignVendor();
56  value.setCampaign(campaign);
57  campaign.getCampaignVendors().add(value);
58  }
59  row.setValue(value);
60  }
61 
62  @Override
63  protected boolean deleteRow(Row row) {
64  CampaignVendor t = (CampaignVendor) row.getValue();
65  EntityCollections.entities(campaign.getCampaignVendors()).remove(t);
66  t.setCampaign(null);
67  return true;
68  }
69 
70  @Override
71  protected boolean isValid(CampaignVendor 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 }
void setCampaign(Campaign campaign)
Set< CampaignVendor > getCampaignVendors()
Definition: Campaign.java:106
String formatCell(EditableCell editableCell, Object value)
HtmlBasedComponent createEditor(EditableCell editableCell)
void initiateRow(Row row, CampaignVendor value)
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)