BrightSide Workbench Full Report + Source Code
Duplicates.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.proposal;
20 
21 import java.util.List;
22 import org.turro.string.Strings;
23 import org.turro.contacts.Contact;
24 import org.turro.contacts.proposal.ContactProposal;
25 import org.turro.contacts.proposal.GenericAttribute;
26 import org.turro.contacts.proposal.IAttribute;
27 import org.turro.i18n.I_;
28 import org.turro.zul.frame.Framework;
29 import org.zkoss.zk.ui.Executions;
30 import org.zkoss.zk.ui.IdSpace;
31 import org.zkoss.zk.ui.event.Event;
32 import org.zkoss.zk.ui.event.Events;
33 import org.zkoss.zk.ui.select.Selectors;
34 import org.zkoss.zk.ui.select.annotation.Listen;
35 import org.zkoss.zk.ui.select.annotation.Wire;
36 import org.zkoss.zul.Button;
37 import org.zkoss.zul.Caption;
38 import org.zkoss.zul.Groupbox;
39 import org.zkoss.zul.Label;
40 import org.zkoss.zul.Vlayout;
41 import org.zkoss.zul.Window;
42 
47 public class Duplicates extends Window implements IdSpace {
48 
49  private final Contact contact;
50  private ContactProposal proposal;
51  private boolean canSave = true;
52 
53  @Wire private Vlayout posdups;
54  @Wire private Button save, cancel;
55 
56  public Duplicates(Contact contact) {
57  this.contact = contact;
58  setBorder(true);
59  setTitle(I_.get("Posibles duplicates"));
60  setClosable(false);
61  Executions.createComponents("/WEB-INF/_zul/contact/duplicates.zul", this, null);
62  Selectors.wireComponents(this, this, false);
63  Selectors.wireEventListeners(this, this);
64  Framework.getCurrent().appendChild(this);
65  }
66 
67  public boolean saveNow() {
68  proposal = new ContactProposal(contact, !Strings.isBlank(contact.getId()));
69  boolean saveIt = proposal.isSureNew();
70  if(saveIt) {
71  detach();
72  }
73  return saveIt;
74  }
75 
76  public boolean canSave() {
77  return canSave;
78  }
79 
80  public void checkIt() {
81  if(!proposal.isNoAction()) {
82  canSave = false;
83  }
84  addAttributes();
85  if(canSave) {
86  save.setLabel(I_.get("Confirm saving"));
87  } else {
88  save.setVisible(false);
89  }
90  cancel.setLabel(I_.get("Cancel"));
91  }
92 
93  @Listen("onClick = #save")
94  public void onSave() {
95  canSave = true;
96  Events.postEvent(new Event(Events.ON_CLOSE, this));
97  }
98 
99  @Listen("onClick = #cancel")
100  public void onCancel() {
101  canSave = false;
102  Events.postEvent(new Event(Events.ON_CLOSE, this));
103  }
104 
105  private void addAttributes() {
106  for(GenericAttribute ga : proposal.getAttributes()) {
107  if(!ga.getRelated().isEmpty()) {
108  Groupbox gb = new Groupbox();
109  posdups.appendChild(gb);
110 
111  Caption gbc = new Caption(ga.getAttributeName() + ": " + ga.getAsString());
112  gb.appendChild(gbc);
113 
114  Vlayout cvbox = new Vlayout();
115  gb.appendChild(cvbox);
116 
117  for(IAttribute ia : (List<IAttribute>) ga.getRelated()) {
118  cvbox.appendChild(new Label(
119  ia.getAsString() + ": " + ia.getContact().getName()
120  ));
121  }
122  }
123  }
124  }
125 
126 }
static String get(String msg)
Definition: I_.java:41
static Framework getCurrent()
Definition: Framework.java:203