BrightSide Workbench Full Report + Source Code
ContactListbox.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.contacts.util;
20 
21 import org.turro.contacts.Contact;
22 import org.turro.contacts.db.ContactsPU;
23 import org.turro.elephant.db.SQLHelper;
24 import org.turro.jpa.Dao;
25 import org.turro.security.Permissions;
26 import org.turro.zkoss.input.CollectionListbox;
27 import org.zkoss.lang.Strings;
28 
33 public class ContactListbox extends CollectionListbox<Contact> {
34 
35  private Dao dao;
36 
37  public void setProvider(Contact provider) {
38  if(provider != null) {
39  updateCollection(new WorkersAdapter(provider));
40  }
41  }
42 
43  public void setPartialName(String name) {
44  if(!Strings.isBlank(name) && name.trim().length() > 2) {
45  if(dao == null) {
46  dao = new ContactsPU();
47  }
48  updateCollection(dao.getResultList(
49  "select c from Contact as c where c.name like ? order by c.name",
50  new String[] { "%" + name.trim() + "%" }));
51  }
52  }
53 
54  public void setRole(String role) {
55  if(dao == null) {
56  dao = new ContactsPU();
57  }
58  updateCollection(dao.getResultList(
59  "select contact from Contact as contact where " +
60  getInRole(role) +
61  " order by contact.name"));
62  }
63 
64  @Override
65  protected String convertToString(Contact v) {
66  return v.getName();
67  }
68 
69  private static String getInRole(String role) {
70  String roleIn = "";
71  if(role != null) {
73  if(!Strings.isBlank(in)) {
74  roleIn = "exists (" +
75  "select syndication from Syndication as syndication" +
76  "where syndication.name in (" + in + ")" +
77  "and syndication.contact = c" +
78  ")";
79  } else {
80  roleIn = "1 = 2";
81  }
82  }
83  return roleIn;
84  }
85 
86 }
static String convertToIn(Collection collection)
Definition: SQLHelper.java:43
static Set< String > getSecurityGroupIdsBy(String role)