BrightSide Workbench Full Report + Source Code
AddressInfo.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.zul.label;
20 
21 import org.turro.contacts.Address;
22 import org.turro.contacts.Contact;
23 import org.turro.contacts.db.ContactsPU;
24 import org.turro.plugin.contacts.IContact;
25 import org.turro.zkoss.label.LabelTypes;
26 import org.zkoss.zk.ui.ext.AfterCompose;
27 import org.zkoss.zul.Hlayout;
28 import org.zkoss.zul.Vlayout;
29 
34 public class AddressInfo extends Vlayout implements AfterCompose {
35 
36  private Contact provider;
37  private Address address;
38 
39  public AddressInfo() {
40  }
41 
42  public AddressInfo(Address address) {
43  this.address = address;
44  setValues();
45  }
46 
47  public AddressInfo(Address address, Contact provider) {
48  this.address = address;
49  this.provider = provider;
50  setValues();
51  }
52 
53  public AddressInfo(String addressId, IContact provider) {
54  this.address = new ContactsPU().find(Address.class, addressId);
55  this.provider = (Contact) provider.getContact();
56  setValues();
57  }
58 
59  public void setProvider(Contact provider) {
60  this.provider = provider;
61  }
62 
63  public void setAddress(Address address) {
64  this.address = address;
65  }
66 
67  private void setValues() {
68  getChildren().clear();
69  if((address != null)) {
70  if(provider != null && !address.getContact().getId().equals(provider.getId())) {
71  Hlayout hbox = new Hlayout();
72  hbox.setSclass("z-valign-middle");
73  hbox.setValign("middle");
74  hbox.setSpacing("10px");
75  hbox.appendChild(LabelTypes.getCaptionLabel(address.getDescription()));
76  hbox.appendChild(new ContactInfo(address.getContact()));
77  appendChild(hbox);
78  } else {
79  appendChild(LabelTypes.getCaptionLabel(address.getDescription()));
80  }
81  appendChild(LabelTypes.getSoftLabel(address.getAddressString()));
82  }
83  }
84 
85  @Override
86  public void afterCompose() {
87  setValues();
88  }
89 
90 }
org.turro.contacts.Contact getContact()
Definition: Address.java:166
AddressInfo(Address address, Contact provider)
AddressInfo(String addressId, IContact provider)
static Label getCaptionLabel(String value)
Definition: LabelTypes.java:40