BrightSide Workbench Full Report + Source Code
ContactCombobox.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.contacts.util;
19 
20 import java.util.LinkedList;
21 import java.util.logging.Level;
22 import java.util.logging.Logger;
23 import org.turro.collections.parser.ParserException;
24 import org.turro.action.Contacts;
25 import org.turro.collections.KeyValueMap;
26 import org.turro.contacts.Contact;
27 import org.turro.elephant.context.ElephantContext;
28 import org.turro.entities.ContactEntities;
29 import org.turro.plugin.contacts.IContact;
30 import org.turro.zkoss.input.GenericCombobox;
31 import org.zkoss.lang.Strings;
32 
37 public class ContactCombobox extends GenericCombobox<Contact> {
38 
39  private String role;
40  private boolean onlyUsers;
41 
42  public void setRole(String role) {
43  this.role = role;
44  }
45 
46  public void setOnlyUsers(boolean onlyUsers) {
47  this.onlyUsers = onlyUsers;
48  }
49 
50  public Contact getContact() {
51  return getObjectValue();
52  }
53 
54  public void setContact(Contact contact) {
55  setObjectValue(contact);
56  }
57 
58  public IContact getIContact() {
59  Contact contact = getContact();
61  c.setContact(contact);
62  return c;
63  }
64 
65  public void setIContact(IContact iContact) {
66  setObjectValue(iContact != null ? (Contact) iContact.getContact() : null);
67  }
68 
69  public String getIdContact() {
70  Contact contact = getContact();
71  if(contact != null) {
72  return contact.getId();
73  }
74  return null;
75  }
76 
77  public void setIdContact(String idContact) {
79  }
80 
81  @Override
82  public void populateList(String value, LinkedList list, int nRows) {
83  try {
84  KeyValueMap kvm = new KeyValueMap(!Strings.isBlank(role) ? "role=" + role : "");
86  list.addAll(ce.getEntitites("contact", value, nRows, kvm));
87  } catch (ParserException ex) {
88  Logger.getLogger(ContactCombobox.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
89  }
90  }
91 
92  @Override
93  public String getTextFromObject(Contact value) {
94  return value.getFullName();
95  }
96 
97 }
static IContact getEmpty()
Definition: Contacts.java:56
static IContact getContactById(String id)
Definition: Contacts.java:72
void populateList(String value, LinkedList list, int nRows)
Collection getEntitites(String search, int maxResults, KeyValueMap kvm)
void setContact(Object contact)