BrightSide Workbench Full Report + Source Code
ConnectorGridOld.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.contacts.zul.contact;
19 
20 import org.turro.auth.Authentication;
21 import org.turro.contacts.Connector;
22 import org.turro.contacts.Contact;
23 import org.turro.elephant.context.Application;
24 import org.turro.elephant.util.Messages;
25 import org.turro.i18n.I_;
26 import org.zkoss.zk.ui.event.Event;
27 import org.zkoss.zk.ui.event.EventListener;
28 import org.zkoss.zk.ui.event.Events;
29 import org.zkoss.zul.Grid;
30 import org.zkoss.zul.Hbox;
31 import org.zkoss.zul.Image;
32 import org.zkoss.zul.Row;
33 import org.zkoss.zul.Rows;
34 import org.zkoss.zul.Separator;
35 import org.zkoss.zul.Textbox;
36 import org.zkoss.zul.Toolbar;
37 import org.zkoss.zul.Toolbarbutton;
38 
43 public class ConnectorGridOld extends Grid {
44 
45  private Contact contact;
46  private Rows rows;
47  private Toolbar toolbar;
48  private Toolbarbutton addButton;
49 
50  public ConnectorGridOld() {
51  rows = new Rows();
52  appendChild(rows);
53  }
54 
55  public void setContact(Contact contact) {
56  this.contact = contact;
57  rows.getChildren().clear();
58  if(contact != null) {
59  addRows();
60  }
61  }
62 
63  public void setAddToolbar(boolean addToolbar) {
64  if(addToolbar) {
65  toolbar = new Toolbar();
66  getParent().appendChild(toolbar);
67  addToolbarButtons();
68  }
69  }
70 
71  public void addRows() {
72  for(final Connector c : contact.getConnectors()) {
73  final Row row = new Row();
74  row.setValue(c);
75  rows.appendChild(row);
76 
77  Hbox hbox = new Hbox();
78  row.appendChild(hbox);
79 
81  name.setConnectorName(c.getDescription());
82  name.addEventListener(Events.ON_CHANGE, new EventListener() {
83  @Override
84  public void onEvent(Event event) throws Exception {
85  c.setDescription(name.getConnectorName());
86  }
87  });
88  hbox.appendChild(name);
89 
90  if(Application.getApplication().isInRole("contact-connector:delete")) {
91  hbox.appendChild(new Separator("vertical"));
92  Image img = new Image("/_zul/images/edit-delete.png");
93  img.setStyle("cursor:pointer");
94  img.addEventListener(Events.ON_CLICK, new EventListener() {
95  @Override
96  public void onEvent(Event event) throws Exception {
97  Messages.confirmDeletion().show(() -> {
98  contact.getConnectors().remove(c);
99  c.setContact(null);
100  row.detach();
101  });
102  }
103  });
104  hbox.appendChild(img);
105  }
106 
107  final Textbox value = new Textbox();
108  value.setWidth("500px");
109  value.setText(c.getValue());
110  value.addEventListener(Events.ON_CHANGE, new EventListener() {
111  @Override
112  public void onEvent(Event event) throws Exception {
113  c.setValue(value.getText());
114  }
115  });
116  row.appendChild(value);
117 
118  }
119  }
120 
121  private void addToolbarButtons() {
122  addButton = new Toolbarbutton(
123  I_.get("Add"),
124  "/_zul/images/new.png"
125  );
126  addButton.addEventListener(Events.ON_CLICK, new EventListener() {
127 
128  @Override
129  public void onEvent(Event event) throws Exception {
130  Connector c = new Connector();
131  c.setContact(contact);
133  contact.getConnectors().add(c);
134  setContact(contact);
135  }
136 
137  });
138  toolbar.appendChild(addButton);
139  }
140 
141 }
void setContact(org.turro.contacts.Contact contact)
Definition: Connector.java:103
void setOwner(String owner)
Definition: Connector.java:71
Set< Connector > getConnectors()
Definition: Contact.java:367
static Messages confirmDeletion()
Definition: Messages.java:87
static String get(String msg)
Definition: I_.java:41