BrightSide Workbench Full Report + Source Code
SaleProspectVendorGrid.java
Go to the documentation of this file.
1 package org.turro.crm.zul.sale;
2 
3 import java.util.Date;
4 import org.turro.crm.entity.FormulaType;
5 import org.turro.crm.entity.SaleProspect;
6 import org.turro.crm.entity.VendorProspect;
7 import org.turro.crm.zul.vendor.FormulaListbox;
8 import org.turro.crm.zul.vendor.VendorCombobox;
9 import org.turro.elephant.util.Messages;
10 import org.turro.i18n.I_;
11 import org.zkoss.zk.ui.event.Event;
12 import org.zkoss.zk.ui.event.EventListener;
13 import org.zkoss.zk.ui.event.Events;
14 import org.zkoss.zul.*;
15 
20 public class SaleProspectVendorGrid extends Grid {
21 
22  private SaleProspect saleProspect;
23  private boolean editable;
24  private Rows rows;
25  private Toolbar toolbar;
26  private Toolbarbutton addButton;
27 
29  rows = new Rows();
30  appendChild(rows);
31  }
32 
33  public void setEditable(boolean editable) {
34  this.editable = editable;
35  if(saleProspect != null) {
36  setSaleProspect(saleProspect);
37  }
38  updateButtons();
39  }
40 
41  public void setSaleProspect(SaleProspect saleProspect) {
42  this.saleProspect = saleProspect;
43  rows.getChildren().clear();
44  if(saleProspect != null) {
45  addRows();
46  }
47  }
48 
49  public void setAddToolbar(boolean addToolbar) {
50  if(addToolbar) {
51  toolbar = new Toolbar();
52  getParent().appendChild(toolbar);
53  addToolbarButtons();
54  }
55  }
56 
57  public void addRows() {
58  for(final VendorProspect vp : saleProspect.getVendorProspects()) {
59  final Row row = new Row();
60  row.setValue(vp);
61  rows.appendChild(row);
62 
63  Vbox vbox = new Vbox();
64  row.appendChild(vbox);
65 
66  if(editable) {
67  Hbox hbox = new Hbox();
68  vbox.appendChild(hbox);
69 
70  final VendorCombobox vendor = new VendorCombobox();
71  vendor.setObjectValue(vp.getVendor());
72  vendor.addEventListener(Events.ON_CHANGE, new EventListener() {
73  @Override
74  public void onEvent(Event event) throws Exception {
75  vp.setVendor(vendor.getObjectValue());
76  vp.setProspectDate(new Date());
77  }
78  });
79  hbox.appendChild(vendor);
80 
81  final Image img = new Image("/_zul/images/delete.png");
82  img.setStyle("cursor:pointer");
83  img.addEventListener(Events.ON_CLICK, new EventListener() {
84  @Override
85  public void onEvent(Event event) throws Exception {
86  Messages.confirmDeletion().show(() -> {
87  saleProspect.getVendorProspects().remove(vp);
88  setSaleProspect(saleProspect);
89  });
90  }
91  });
92  hbox.appendChild(img);
93 
94  final FormulaListbox comission = new FormulaListbox();
96  comission.setObjectValue(vp.getComission());
97  comission.addEventListener(Events.ON_SELECT, new EventListener() {
98  @Override
99  public void onEvent(Event event) throws Exception {
100  vp.setComission(comission.getObjectValue());
101  }
102  });
103  vbox.appendChild(comission);
104  comission.afterCompose();
105 
106  final FormulaListbox alert = new FormulaListbox();
108  alert.setObjectValue(vp.getAlert());
109  alert.addEventListener(Events.ON_SELECT, new EventListener() {
110  @Override
111  public void onEvent(Event event) throws Exception {
112  vp.setAlert(alert.getObjectValue());
113  }
114  });
115  vbox.appendChild(alert);
116  alert.afterCompose();
117 
118  } else {
119  Label label = new Label(vp.getVendor() != null ? vp.getVendor().getName() : "***");
120  vbox.appendChild(label);
121 
122  label = new Label(vp.getComission().getName());
123  vbox.appendChild(label);
124 
125  label = new Label(vp.getAlert().getName());
126  vbox.appendChild(label);
127  }
128  }
129  }
130 
131  private void addToolbarButtons() {
132  addButton = new Toolbarbutton(
133  I_.get("Add"),
134  "/_zul/images/new.png"
135  );
136  addButton.addEventListener(Events.ON_CLICK, new EventListener() {
137  @Override
138  public void onEvent(Event event) throws Exception {
139  VendorProspect vp = new VendorProspect();
140  vp.setSaleProspect(saleProspect);
141  saleProspect.getVendorProspects().add(vp);
142  setSaleProspect(saleProspect);
143  }
144  });
145  toolbar.appendChild(addButton);
146 
147  updateButtons();
148  }
149 
150  private void updateButtons() {
151  if(toolbar != null) {
152  addButton.setVisible(editable);
153  }
154  }
155 }
156 
Set< VendorProspect > getVendorProspects()
void setSaleProspect(SaleProspect saleProspect)
void setFormulaType(FormulaType formulaType)
static Messages confirmDeletion()
Definition: Messages.java:87
static String get(String msg)
Definition: I_.java:41