BrightSide Workbench Full Report + Source Code
ComplexNameControl.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 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.name;
20 
21 import org.turro.contacts.Contact;
22 import org.turro.string.Strings;
23 import org.zkoss.zk.ui.Executions;
24 import org.zkoss.zk.ui.Page;
25 import org.zkoss.zk.ui.event.Event;
26 import org.zkoss.zk.ui.event.Events;
27 import org.zkoss.zk.ui.select.Selectors;
28 import org.zkoss.zk.ui.select.annotation.Listen;
29 import org.zkoss.zk.ui.select.annotation.Wire;
30 import org.zkoss.zul.Div;
31 import org.zkoss.zul.Textbox;
32 
37 public class ComplexNameControl extends Div {
38 
39  @Wire private Textbox full;
40  @Wire private Textbox informal;
41  @Wire private Textbox formal;
42 
43  private Contact entity;
44 
45  @Listen("onChange = #full")
46  public void onFull() {
47  entity.getComplexName().setFull(full.getValue());
48  entity.setName(full.getValue());
49  Events.postEvent(new Event(Events.ON_CHANGE, this));
50  }
51 
52  @Listen("onChange = #informal")
53  public void onInformal() {
54  entity.getComplexName().setInformal(informal.getValue());
55  Events.postEvent(new Event(Events.ON_CHANGE, this));
56  }
57 
58  @Listen("onChange = #formal")
59  public void onFormal() {
60  entity.getComplexName().setFormal(formal.getValue());
61  Events.postEvent(new Event(Events.ON_CHANGE, this));
62  }
63 
64  @Listen("onClick = #guess")
65  public void onGuess() {
66  entity.getComplexName().guessFrom(full.getValue(), entity.getType().isJuridical());
67  if(!Strings.isBlank(entity.getComplexName().getFull())) {
68  full.setValue(entity.getComplexName().getFull());
69  }
70  informal.setValue(entity.getComplexName().getInformal());
71  formal.setValue(entity.getComplexName().getFormal());
72  Events.postEvent(new Event(Events.ON_CHANGE, this));
73  }
74 
75  public void setEntity(Contact entity) {
76  this.entity = entity;
77  if(!Strings.isBlank(entity.getComplexName().getFull())) {
78  full.setValue(entity.getComplexName().getFull());
79  }
80  informal.setValue(entity.getComplexName().getInformal());
81  formal.setValue(entity.getComplexName().getFormal());
82  }
83 
84  public ComplexNameControl() {
85  }
86 
87  @Override
88  public void onPageAttached(Page newpage, Page oldpage) {
89  super.onPageAttached(newpage, oldpage);
90  Executions.createComponents("/WEB-INF/_zul/bs/comps/contact/complexNameControl.zul", this, null);
91  Selectors.wireComponents(this, this, false);
92  Selectors.wireEventListeners(this, this);
93  }
94 
95 }
void setName(String name)
Definition: Contact.java:217
ComplexName getComplexName()
Definition: Contact.java:152
void onPageAttached(Page newpage, Page oldpage)
void guessFrom(String name, boolean entity)