BrightSide Workbench Full Report + Source Code
ProductByContractorCombobox.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.financials.product;
19 
20 import java.util.LinkedList;
21 import org.turro.string.Strings;
22 import org.turro.elephant.db.WhereClause;
23 import org.turro.financials.db.FinancialsPU;
24 import org.turro.financials.entity.Contract;
25 import org.turro.financials.entity.Product;
26 import org.turro.financials.entity.ProductByContractor;
27 import org.turro.jpa.Dao;
28 import org.turro.zkoss.input.GenericCombobox;
29 
34 public class ProductByContractorCombobox extends GenericCombobox<ProductByContractor> {
35 
36  protected Contract contract;
37  protected Product product;
38 
40  }
41 
43  this.contract = contract;
44  }
45 
46  public Contract getContract() {
47  return contract;
48  }
49 
50  public void setContract(Contract contract) {
51  this.contract = contract;
52  }
53 
54  public Product getProduct() {
55  return product;
56  }
57 
58  public void setProduct(Product product) {
59  this.product = product;
60  }
61 
62  @Override
63  public void populateList(String value, LinkedList list, int nRows) {
64  Dao dao = new FinancialsPU();
65  WhereClause wc = new WhereClause();
66  wc.addClause("select pbp from ProductByContractor as pbp");
67  wc.addClause("where pbp.contract = :contract");
68  wc.addNamedValue("contract", contract);
69  wc.addClause("and (");
70  if(!Strings.isBlank(value)) {
71  wc.setPrefix("");
72  wc.addLikeFields(new String[] { "pbp.product.description" }, value);
73  wc.addClause("or");
74  }
75  wc.addClause("pbp.contractorCode = :pcode");
76  wc.addNamedValue("pcode", value);
77  wc.addClause(")");
78  if(product != null) {
79  wc.addClause("and pbp.product = :product");
80  wc.addNamedValue("product", product);
81  }
82  wc.addClause("order by pbp.product.description");
83  for(Object o : dao.getResultList(wc, nRows)) {
84  list.add((ProductByContractor) o);
85  }
86  }
87 
88  @Override
89  public String getTextFromObject(ProductByContractor value) {
90  return "#" + value.getContractorCode() + " " + value.getProduct().getDescription();
91  }
92 
93 }
void addLikeFields(String[] fields, String value)
void addNamedValue(String name, Object value)
void populateList(String value, LinkedList list, int nRows)