BrightSide Workbench Full Report + Source Code
SaleProspectCtrl.java
Go to the documentation of this file.
1 package org.turro.crm.zul.sale;
2 
3 import org.turro.crm.db.CrmPU;
4 import org.turro.crm.entity.SaleProspect;
5 import org.turro.crm.search.SaleProspectResults;
6 import org.turro.zkoss.label.LabelExtended;
7 import org.zkoss.lang.Strings;
8 import org.zkoss.zk.ui.Component;
9 import org.zkoss.zk.ui.WrongValueException;
10 import org.zkoss.zk.ui.event.Event;
11 import org.zkoss.zk.ui.event.EventListener;
12 import org.zkoss.zk.ui.event.Events;
13 import org.zkoss.zk.ui.ext.AfterCompose;
14 import org.zkoss.zul.*;
15 
20 public class SaleProspectCtrl extends Bandbox implements AfterCompose {
21 
22  private LabelExtended description;
23  private SaleProspect saleProspect;
24  private int wordWrap = 0, maxChars = 0, parentCount = 1;
25  private boolean showDescription = false;
26 
27  public SaleProspectCtrl() {
28  addPopup();
29  }
30 
31  public boolean isShowDescription() {
32  return showDescription;
33  }
34 
35  public void setShowDescription(boolean showDescription) {
36  this.showDescription = showDescription;
37  if(showDescription) {
38  addEventListener(Events.ON_CHANGE, new EventListener() {
39  @Override
40  public void onEvent(Event event) throws Exception {
41  description.setValue(loadValue());
42  }
43  });
44  }
45  }
46 
48  return saleProspect;
49  }
50 
51  public void setSaleProspect(SaleProspect saleProspect) {
52  this.saleProspect = saleProspect;
53  if(saleProspect != null) {
54  setValue(saleProspect.getId() + "");
55  }
56  }
57 
58  public int getMaxChars() {
59  return maxChars;
60  }
61 
62  public void setMaxChars(int maxChars) {
63  this.maxChars = maxChars;
64  }
65 
66  public int getParentCount() {
67  return parentCount;
68  }
69 
70  public void setParentCount(int parentCount) {
71  this.parentCount = parentCount;
72  }
73 
74  public int getWordWrap() {
75  return wordWrap;
76  }
77 
78  public void setWordWrap(int wordWrap) {
79  this.wordWrap = wordWrap;
80  }
81 
82  @Override
83  public void afterCompose() {
84  if(!showDescription) return;
85  description = new LabelExtended();
86  description.setValue(loadValue());
87  description.setWordWrap(wordWrap);
88  description.setMaxChars(maxChars);
89  Component comp = getParent();
90  for(int i = 1; i < parentCount; i++) {
91  comp = comp.getParent();
92  }
93  comp.appendChild(description);
94  }
95 
96  @Override
97  public void setValue(String value) throws WrongValueException {
98  if(Strings.isEmpty(value)) value = "0";
99  super.setValue(value);
100  }
101 
102  private void addPopup() {
103  Bandpopup popup = new Bandpopup();
104  appendChild(popup);
105 
106  final Listbox saleProspects = new Listbox();
107  saleProspects.addEventListener(Events.ON_SELECT, new EventListener() {
108  @Override
109  public void onEvent(Event event) throws Exception {
110  SaleProspectCtrl.this.setValue(saleProspects.getSelectedItem().getLabel());
111  SaleProspectCtrl.this.loadValue();
112  Events.postEvent(new Event(Events.ON_CHANGE, SaleProspectCtrl.this));
113  SaleProspectCtrl.this.close();
114  }
115  });
116  popup.appendChild(saleProspects);
117 
118  SaleProspectResults results = new SaleProspectResults();
119 
120  for(SaleProspect sp : results.getSaleProspectList()) {
121  Listitem item = new Listitem();
122  saleProspects.appendChild(item);
123 
124  Listcell cell = new Listcell(sp.getId() + "");
125  item.appendChild(cell);
126 
127  cell = new Listcell(sp.getCustomer().getName() + " - " + sp.getDescription());
128  item.appendChild(cell);
129  }
130 
131  }
132 
133  private String loadValue() {
134  if(!Strings.isEmpty(getValue()) && Long.valueOf(getValue()) > 0) {
135  saleProspect = new CrmPU().find(SaleProspect.class, Long.valueOf(getValue()));
136  if(saleProspect != null) {
137  return saleProspect.getDescription();
138  }
139  }
140  return "";
141  }
142 
143 }
void setShowDescription(boolean showDescription)
void setSaleProspect(SaleProspect saleProspect)
LabelExtended setWordWrap(int wordWrap)
LabelExtended setMaxChars(int maxChars)