BrightSide Workbench Full Report + Source Code
ProductReferenceListbox.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.erp.reference;
20 
21 import java.util.Collection;
22 import java.util.HashMap;
23 import org.turro.elephant.db.WhereClause;
24 import org.turro.erp.db.ErpPU;
25 import org.turro.erp.entity.OrderReference;
26 import org.turro.erp.menu.ErpMenu;
27 import org.turro.jpa.Dao;
28 import org.turro.zkoss.dialog.Listeners;
29 import org.turro.zkoss.input.CollectionListbox;
30 import org.zkoss.zk.ui.event.Events;
31 
36 public class ProductReferenceListbox extends CollectionListbox<OrderReference> {
37 
38  private OrderReference orderReference;
39 
40  public ProductReferenceListbox(OrderReference orderReference) {
41  this.orderReference = orderReference;
42  setAllowNull(true);
43  fillCollection();
44  }
45 
46  @Override
47  protected String convertToString(OrderReference v) {
48  return v.getQuantity() + ": " + v.getSomeDescription();
49  }
50 
51  private void fillCollection() {
52  WhereClause wc = new WhereClause();
53  wc.addClause("select or from OrderReference or");
54  wc.addClause("where or.workOrder.productId = or.productId");
55  wc.addClause("order by productId, quantity");
56  Dao dao = new ErpPU();
57  setCollection(dao.getResultList(wc));
58  }
59 
60  private long idRef;
61 
62  @Override
63  public void setObjectValue(OrderReference value) {
64  super.setObjectValue(value);
65  idRef = value != null ? value.getId() : 0L;
66  }
67 
68  @Override
70  OrderReference or = super.getObjectValue();
71 // if(or != null && or.getId() != idRef) {
72 // Collection c = Listeners.cancelListener(this, Events.ON_BLUR);
73 // HashMap<String, Object> map = new HashMap<String, Object>();
74 // // pending: clone from or changing values
75 // map.put("orderReference", or);
76 // ErpMenu.showModalZulFile("lProductOrder", "/WEB-INF/_zul/erp/reference/referenceClone.zul", map);
77 // Listeners.activateListeners(this, Events.ON_BLUR, c);
78 // }
79  return or;
80  }
81 
82 }
void setCollection(Collection< V > collection)