BrightSide Workbench Full Report + Source Code
AutheticatedConnectorCheckbox.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2017 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.contact;
20 
21 import org.turro.string.Strings;
22 import org.turro.auth.Authentication;
23 import org.turro.contacts.Connector;
24 import org.turro.contacts.Contact;
25 import org.turro.contacts.db.ContactsPU;
26 import org.turro.jpa.Dao;
27 import org.turro.plugin.contacts.IContact;
28 import org.zkoss.zk.ui.event.Event;
29 import org.zkoss.zk.ui.event.EventListener;
30 import org.zkoss.zk.ui.event.Events;
31 import org.zkoss.zul.Checkbox;
32 
37 @Deprecated
38 public class AutheticatedConnectorCheckbox extends Checkbox {
39 
40  private String connector;
41  private IContact contact = Authentication.getIContact();
42 
44  super();
45  addListener();
46  }
47 
48  public String getConnector() {
49  return connector;
50  }
51 
52  public void setConnector(String connector) {
53  this.connector = connector;
54  if(contact != null && contact.isValid() && !Strings.isBlank(connector)) {
55  setChecked("TRUE".equalsIgnoreCase(contact.getConnector(connector)));
56  }
57  }
58 
59  private void setConnectorValue(boolean value) {
60  Dao dao = new ContactsPU();
61  if(contact != null && contact.isValid() && !Strings.isBlank(connector)) {
62  Contact c = (Contact) contact.getContact();
63  Connector con = c.getConnectorMap().get(connector);
64  if(con == null) {
65  con = new Connector();
66  con.setOwner(c.getOwner());
67  con.setOnlyOwner(false);
68  con.setContact(c);
69  con.setDescription(this.connector);
70  c.getConnectors().add(con);
71  }
72  con.setValue(value ? "TRUE" : "FALSE");
73  c = dao.saveObject(c);
74  contact.setContact(c);
75  }
76  }
77 
78  private void addListener() {
79  addEventListener(Events.ON_CHECK, new EventListener<Event>() {
80  @Override
81  public void onEvent(Event event) throws Exception {
82  setConnectorValue(isChecked());
83  }
84  });
85  }
86 
87 }
void setContact(org.turro.contacts.Contact contact)
Definition: Connector.java:103
void setOnlyOwner(boolean onlyOwner)
Definition: Connector.java:79
void setOwner(String owner)
Definition: Connector.java:71
void setDescription(String description)
Definition: Connector.java:87
void setValue(String value)
Definition: Connector.java:95
Map< String, Connector > getConnectorMap()
Definition: Contact.java:499
Set< Connector > getConnectors()
Definition: Contact.java:367
void setContact(Object contact)