BrightSide Workbench Full Report + Source Code
ContractCombobox.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.contract;
19 
20 import java.util.LinkedList;
21 import java.util.List;
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.ContractDefinition;
26 import org.turro.financials.entity.DocumentDefinition;
27 import org.turro.financials.model.contract.ContractWrapper;
28 import org.turro.jpa.Dao;
29 import org.turro.zkoss.input.GenericCombobox;
30 
35 public class ContractCombobox extends GenericCombobox<Contract> {
36 
37  private boolean onlyStores, onlyActive;
38  private ContractDefinition contractDefinition;
39  private DocumentDefinition documentDefinition;
40 
41  public boolean isOnlyActive() {
42  return onlyActive;
43  }
44 
45  public void setOnlyActive(boolean onlyActive) {
46  this.onlyActive = onlyActive;
47  }
48 
49  public boolean isOnlyStores() {
50  return onlyStores;
51  }
52 
53  public void setOnlyStores(boolean onlyStores) {
54  this.onlyStores = onlyStores;
55  }
56 
57  public void setContractDefinition(ContractDefinition contractDefinition) {
58  this.contractDefinition = contractDefinition;
59  }
60 
61  public void setDocumentDefinition(DocumentDefinition documentDefinition) {
62  this.documentDefinition = documentDefinition;
63  }
64 
65  @Override
66  public void populateList(String value, LinkedList list, int nRows) {
67  Dao dao = new FinancialsPU();
68  WhereClause wc = new WhereClause();
69  wc.addClause("select contract from Contract as contract");
70  wc.addClause("where 1=1");
71  if(onlyStores) {
72  wc.addClause("and contract.stock = TRUE");
73  }
74  if(contractDefinition != null) {
75  wc.addClause("and contract.contractDefinition = :ctcdef");
76  wc.addNamedValue("ctcdef", contractDefinition);
77  }
78  if(documentDefinition != null) {
79  wc.addClause("and exists (");
80  wc.addClause(" select reldoc from contract.contractDefinition.relatedDocuments as reldoc");
81  wc.addClause(" where reldoc.documentDefinition = :docdef");
82  wc.addClause(")");
83  wc.addNamedValue("docdef", documentDefinition);
84  }
85  wc.addLikeFields(new String[] { "contract.name" }, value);
86  wc.addClause("order by contract.name");
87  List<Contract> l = dao.getResultList(wc, nRows);
88  if(onlyActive) {
90  }
91  list.addAll(l);
92  }
93 
94  @Override
95  public String getTextFromObject(Contract value) {
96  return value.getName();
97  }
98 
99 }
void addLikeFields(String[] fields, String value)
void addNamedValue(String name, Object value)
void populateList(String value, LinkedList list, int nRows)
void setDocumentDefinition(DocumentDefinition documentDefinition)
void setContractDefinition(ContractDefinition contractDefinition)