BrightSide Workbench Full Report + Source Code
AccountCombobox.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.account;
19 
20 import java.util.LinkedList;
21 import org.turro.elephant.db.WhereClause;
22 import org.turro.financials.db.FinancialsPU;
23 import org.turro.financials.entity.Account;
24 import org.turro.financials.model.AccountFormat;
25 import org.turro.jpa.Dao;
26 import org.turro.zkoss.input.GenericCombobox;
27 
32 public class AccountCombobox extends GenericCombobox<Account> {
33 
34  private boolean allowWildcards, allowNewAccount;
35 
36  public boolean isAllowNewAccount() {
37  return allowNewAccount;
38  }
39 
40  public void setAllowNewAccount(boolean allowNewAccount) {
41  this.allowNewAccount = allowNewAccount;
42  }
43 
44  public boolean isAllowWildcards() {
45  return allowWildcards;
46  }
47 
48  public void setAllowWildcards(boolean allowWildcards) {
49  this.allowWildcards = allowWildcards;
50  }
51 
52  public String getAccountString() {
53  Account acc = getObjectValue();
54  if(acc != null) {
55  return acc.getId();
56  } else if(allowWildcards) {
57  return getText();
58  }
59  return null;
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 account from Account as account");
67  wc.addClause("where 1=1");
68  wc.addLikeFields(new String[] { "account.id", "account.description" }, value);
69  wc.addClause("order by account.description");
70  list.addAll(dao.getResultList(wc, nRows));
71  }
72 
73  @Override
74  public String getTextFromObject(Account value) {
75  return value.getId() + " - " + value.getDescription();
76  }
77 
78  @Override
80  Account acc = super.getObjectValue();
81  String text = getText();
82  if(allowNewAccount && acc == null && AccountFormat.isAccount(text)) {
83 // Collection c = Listeners.cancelListener(this, Events.ON_BLUR);
84  acc = new Account();
85  acc.setId(AccountFormat.expand(text));
86  acc.proposeDescription();
87 // acc.setDescription((String) InputDialog.getInput(
88 // getPage(), I_.get("Account"), "Description", acc.getDescription(), null, 0));
89 // Listeners.activateListeners(this, Events.ON_BLUR, c);
90  }
91  return acc;
92  }
93 
94 }
void addLikeFields(String[] fields, String value)
void populateList(String value, LinkedList list, int nRows)
void setAllowWildcards(boolean allowWildcards)
void setAllowNewAccount(boolean allowNewAccount)