BrightSide Workbench Full Report + Source Code
InTouchEdit.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.zul.intouch;
20 
21 import org.turro.contacts.Contact;
22 import org.turro.contacts.InTouch;
23 import org.turro.contacts.util.AddressListbox;
24 import org.turro.contacts.util.ContactListbox;
25 import org.turro.i18n.I_;
26 import org.turro.intouch.InTouchUtil;
27 import org.turro.zul.frame.Framework;
28 import org.zkoss.zk.ui.Executions;
29 import org.zkoss.zk.ui.IdSpace;
30 import org.zkoss.zk.ui.select.Selectors;
31 import org.zkoss.zk.ui.select.annotation.Listen;
32 import org.zkoss.zk.ui.select.annotation.Wire;
33 import org.zkoss.zul.Button;
34 import org.zkoss.zul.Datebox;
35 import org.zkoss.zul.Textbox;
36 import org.zkoss.zul.Window;
37 
42 public class InTouchEdit extends Window implements IdSpace {
43 
44  @Wire private InTouchNameCombobox name;
45  @Wire private ContactListbox contact;
46  @Wire private AddressListbox address;
47  @Wire private Datebox control;
48  @Wire private Textbox description;
49  @Wire private Button save;
50  @Wire private Button cancel;
51 
52  private InTouch inTouch;
53 
54  public InTouchEdit(Contact provider, InTouch inTouch) {
55  this.inTouch = inTouch;
56  setBorder(true);
57  setTitle(I_.get("In touch because"));
58  setClosable(false);
59  Executions.createComponents("/WEB-INF/_zul/contact/intouch.zul", this, null);
60  Selectors.wireComponents(this, this, false);
61  Selectors.wireEventListeners(this, this);
62  Framework.getCurrent().appendChild(this);
63  name.setObjectValue(inTouch.getName());
64  contact.setProvider(provider);
65  if(inTouch.getContact() == null && !contact.getCollection().isEmpty()) {
66  inTouch.setContact(contact.getCollection().iterator().next());
67  }
68  contact.setObjectValue(inTouch.getContact());
69  address.setProvider(provider);
70  address.setObjectValue(inTouch.getAddress());
71  control.setValue(inTouch.getControl());
72  description.setValue(inTouch.getDescription());
73  }
74 
75  @Listen("onClick = #save")
76  public void onSave() {
77  InTouchUtil.addInTouch(inTouch);
78  detach();
79  }
80 
81  @Listen("onClick = #cancel")
82  public void onCancel() {
83  detach();
84  }
85 
86  @Listen("onChange = #name")
87  public void onChangeName() {
88  inTouch.setName(name.getObjectValue());
89  }
90 
91  @Listen("onSelect = #contact")
92  public void onChangeContact() {
93  inTouch.setContact(contact.getObjectValue());
94  }
95 
96  @Listen("onSelect = #address")
97  public void onChangeAddress() {
98  inTouch.setAddress(address.getObjectValue());
99  }
100 
101  @Listen("onChange = #control")
102  public void onChangeControl() {
103  inTouch.setControl(control.getValue());
104  }
105 
106  @Listen("onChange = #description")
107  public void onChangeDescription() {
108  inTouch.setDescription(description.getValue());
109  }
110 
111 }
void setName(String name)
Definition: InTouch.java:81
void setContact(Contact contact)
Definition: InTouch.java:97
void setDescription(String description)
Definition: InTouch.java:113
void setControl(Date control)
Definition: InTouch.java:73
void setAddress(Address address)
Definition: InTouch.java:105
static String get(String msg)
Definition: I_.java:41
static void addInTouch(InTouch inTouch)
static Framework getCurrent()
Definition: Framework.java:203
InTouchEdit(Contact provider, InTouch inTouch)