BrightSide Workbench Full Report + Source Code
RelationLayout.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2020 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.zul.relation;
20 
21 import java.util.List;
22 import java.util.function.Consumer;
23 import org.turro.contacts.Contact;
24 import org.turro.contacts.zul.label.ContactInfo;
25 import org.turro.entities.Entities;
26 import org.turro.entities.IElephantEntity;
27 import org.turro.plugin.contacts.ContactRelations;
28 import org.turro.plugin.contacts.IContactRelation;
29 import org.turro.util.Chars;
30 import org.turro.zkoss.label.LabelTypes;
31 import org.zkoss.zk.ui.HtmlBasedComponent;
32 import org.zkoss.zk.ui.event.Event;
33 import org.zkoss.zk.ui.event.Events;
34 import org.zkoss.zul.A;
35 import org.zkoss.zul.Hlayout;
36 import org.zkoss.zul.Image;
37 import org.zkoss.zul.Label;
38 import org.zkoss.zul.Vlayout;
39 
44 public class RelationLayout extends Vlayout {
45 
46  private final Contact contact;
47  private boolean hasContent;
48  private Consumer<Contact> onClick;
49 
50  public RelationLayout(Contact contact) {
51  this.contact = contact;
52  }
53 
54  public void setOnClick(Consumer<Contact> onClick) {
55  this.onClick = onClick;
56  }
57 
58  public void fillContactInfo() {
59  processContactInfo(ContactRelations.getRelations(contact.getId(), ContactRelations.MODE_ALL));
60  }
61 
62  private void processContactInfo(List<IContactRelation> contactRelationList) {
63  for(IContactRelation relation : contactRelationList) {
64  hasContent = true;
65  Hlayout rbox = new Hlayout();
66  rbox.appendChild(getIcon(relation.getValidated()));
67  rbox.appendChild(new Image(relation.getImage()));
68  if(relation.asWorker()) {
69  rbox.appendChild(LabelTypes.getSoftLabel(relation.getDue()));
70  rbox.appendChild(LabelTypes.getSoftLabel(Chars.forward().spaced().toString()));
71  ContactInfo ci = new ContactInfo(relation.getRelatedId());
72  ci.setSclass("softLabel");
73  rbox.appendChild(ci);
74  } else {
75  ContactInfo ci = new ContactInfo(relation.getRelatedId());
76  ci.setSclass("softLabel");
77  rbox.appendChild(ci);
78  rbox.appendChild(LabelTypes.getSoftLabel(Chars.forward().spaced().toString()));
79  rbox.appendChild(LabelTypes.getSoftLabel(relation.getDue()));
80  }
81  appendChild(rbox);
82  }
83  }
84 
85  public void fill() {
87  }
88 
89  private void process(List<IContactRelation> contactRelationList) {
90  for(IContactRelation relation : contactRelationList) {
91  hasContent = true;
92  Hlayout rbox = new Hlayout();
93  rbox.appendChild(getIcon(relation.getValidated()));
94  rbox.appendChild(new Image(relation.getImage()));
95  IElephantEntity iee = Entities.getController("/contact/" + relation.getRelatedId());
96  if(relation.asWorker()) {
97  Label l = new Label(relation.getDue());
98  l.setSclass("relation");
99  rbox.appendChild(l);
100  rbox.appendChild(new Label(Chars.forward().spaced().toString()));
101  Label label = new Label(iee.getName());
102  label.setStyle("cursor:pointer");
103  label.setSclass("contact");
104  if(onClick != null) {
105  label.addEventListener(Events.ON_CLICK, (Event event) -> {
106  onClick.accept((Contact) iee.getEntity());
107  });
108  }
109  rbox.appendChild(label);
110  } else {
111  Label label = new Label(iee.getName());
112  label.setStyle("cursor:pointer");
113  label.setSclass("contact");
114  if(onClick != null) {
115  label.addEventListener(Events.ON_CLICK, (Event event) -> {
116  onClick.accept((Contact) iee.getEntity());
117  });
118  }
119  rbox.appendChild(label);
120  rbox.appendChild(new Label(Chars.forward().spaced().toString()));
121  Label l = new Label(relation.getDue());
122  l.setSclass("relation");
123  rbox.appendChild(l);
124  }
125  appendChild(rbox);
126  }
127  }
128 
129  public HtmlBasedComponent getIcon(boolean validated) {
130  A a = new A();
131  a.setStyle("cursor:none;");
132  if(validated) {
133  a.setIconSclass("z-icon-check");
134  } else {
135  a.setIconSclass("z-icon-times");
136  }
137  return a;
138  }
139 
140  public boolean hasContent() {
141  return hasContent;
142  }
143 
144 }
HtmlBasedComponent getIcon(boolean validated)
void setOnClick(Consumer< Contact > onClick)
static IElephantEntity getController(String path)
Definition: Entities.java:78
static List< IContactRelation > getRelations(IContact contact, int mode)
static Label getSoftLabel(String value)
Definition: LabelTypes.java:28