BrightSide Workbench Full Report + Source Code
ContactItem.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 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.model;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 import org.turro.string.Strings;
24 import org.turro.contacts.Contact;
25 import org.turro.contacts.content.DirectoryType;
26 import org.turro.contacts.profile.Profile;
27 import org.turro.elephant.context.Application;
28 import org.turro.i18n.I_;
29 import org.turro.jpa.Dao;
30 import org.turro.plugin.contacts.ContactRelations;
31 import org.turro.plugin.contacts.IContactRelation;
32 
37 public class ContactItem {
38 
39  private final Dao dao;
40  private final String contactId;
41  private final boolean open;
42  private Contact contact;
43  private List<String> images;
44  private boolean selected;
45 
46  public ContactItem(Dao dao, String contactId, boolean open) {
47  this.dao = dao;
48  this.contactId = contactId;
49  this.open = open;
50  }
51 
52  public boolean isOpen() {
53  return open;
54  }
55 
56  public String getContactId() {
57  return contactId;
58  }
59 
60  public Contact getContact() {
61  if(contact == null) {
62  contact = dao.find(Contact.class, contactId);
63  }
64  return contact;
65  }
66 
67  public String getName() {
68  String name = getContact().getFullName();
69  name += " [" + I_.byKey(getContact().getType().toString()) +
70  (!Strings.isBlank(getContact().getGrouping()) ? " - " + getContact().getGrouping() : "") + "]";
71  return name;
72  }
73 
74  public List<String> getImages() {
75  if(images == null) {
76  images = new ArrayList<>();
77  Profile profile = getContact().getProfile();
78  if(profile.isCompany()) images.add(DirectoryType.DIRECTORY_COMPANIES.getImage());
79  if(profile.isCenter()) images.add(DirectoryType.DIRECTORY_CENTERS.getImage());
80  if(profile.isWorker()) images.add(DirectoryType.DIRECTORY_PROFESSIONALS.getImage());
81  if(profile.isResponsible()) images.add(DirectoryType.DIRECTORY_EDUCATORS.getImage());
82  if(profile.isStudent()) images.add(DirectoryType.DIRECTORY_STUDENTS.getImage());
83  if(getContact().isDeactivated()) images.add("cancel");
84  }
85  return images;
86  }
87 
88  public String getStyle() {
89  return getContact().isInactive() ? "font-style:oblique" : "";
90  }
91 
92  public boolean isSelected() {
93  return selected;
94  }
95 
96  public void setSelected(boolean selected) {
97  this.selected = selected;
98  }
99 
100  public String getLocale() {
102  }
103 
104  public List<IContactRelation> getRelations() {
106  }
107 
108 }
String getLocaleString(Locale currLocale)
Definition: Contact.java:590
void setSelected(boolean selected)
ContactItem(Dao dao, String contactId, boolean open)
List< IContactRelation > getRelations()
static String byKey(String key)
Definition: I_.java:83
static List< IContactRelation > getRelations(IContact contact, int mode)