BrightSide Workbench Full Report + Source Code
ContactControl.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2013 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.string.Strings;
22 import org.turro.contacts.Contact;
23 import org.turro.contacts.db.ContactsPU;
24 import org.turro.contacts.zul.label.ContactInfo;
25 import org.turro.plugin.contacts.IContact;
26 import org.zkoss.zk.ui.Executions;
27 import org.zkoss.zk.ui.IdSpace;
28 import org.zkoss.zk.ui.event.Event;
29 import org.zkoss.zk.ui.event.Events;
30 import org.zkoss.zk.ui.ext.AfterCompose;
31 import org.zkoss.zk.ui.select.Selectors;
32 import org.zkoss.zk.ui.select.annotation.Listen;
33 import org.zkoss.zk.ui.select.annotation.Wire;
34 import org.zkoss.zul.Div;
35 import org.zkoss.zul.Hbox;
36 
41 public class ContactControl extends Div implements IdSpace, AfterCompose {
42 
43  @Wire
44  private Hbox layoutbox;
45  @Wire
46  private ContactCombobox contactbox;
47  @Wire
48  private ContactInfo contactinf;
49 
50  private Contact contact;
51  private boolean enterprise;
52  private boolean readOnly;
53 
54  public ContactControl() {
55  Executions.createComponents("/WEB-INF/_zul/bs/comps/contact/contactControl.zul", this, null);
56  Selectors.wireComponents(this, this, false);
57  Selectors.wireEventListeners(this, this);
58  }
59 
60  @Listen("onChange = #contactbox")
61  public void contactChange() {
62  contact = contactbox.getContact();
63  updateControls();
64  Events.postEvent(new Event(Events.ON_CHANGE, this));
65  }
66 
67  public boolean isEnterprise() {
68  return enterprise;
69  }
70 
71  public void setEnterprise(boolean enterprise) {
72  this.enterprise = enterprise;
73  }
74 
75  public Contact getContact() {
76  return contact;
77  }
78 
79  public void setContact(Contact contact) {
80  this.contact = contact;
81  updateControls();
82  }
83 
84  public IContact getIContact() {
85  return new DefaultContact(contact);
86  }
87 
88  public void setIContact(IContact contact) {
89  this.contact = (Contact) contact.getContact();
90  updateControls();
91  }
92 
93  public String getIdContact() {
94  return contact != null ? contact.getId() : null;
95  }
96 
97  public void setIdContact(String idContact) {
98  this.contact = Strings.isBlank(idContact) ? null :
99  new ContactsPU().find(Contact.class, idContact);
100  updateControls();
101  }
102 
103  public boolean isReadOnly() {
104  return readOnly;
105  }
106 
107  public void setReadOnly(boolean readOnly) {
108  this.readOnly = readOnly;
109  }
110 
111  private void updateControls() {
112  if(contact != null && !Strings.isBlank(contact.getId())) {
113  contactbox.setContact(contact);
114  contactinf.setContact(contact);
115  contactinf.setVisible(true);
116  } else {
117  contactbox.setContact(null);
118  contactinf.setContact(null);
119  contactinf.setVisible(false);
120  }
121  invalidate();
122  contactbox.setReadonly(readOnly);
123  contactinf.setDisabled(readOnly);
124  }
125 
126  private void initControls() {
127  contactinf.setOnlyIcon(true);
128  updateControls();
129  }
130 
131  @Override
132  public void afterCompose() {
133  initControls();
134  }
135 
136 }
void setEnterprise(boolean enterprise)