BrightSide Workbench Full Report + Source Code
AttendeesList.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.util;
20 
21 import java.util.Collection;
22 import org.turro.contacts.Contact;
23 import org.turro.contacts.zul.label.ContactInfo;
24 import org.turro.elephant.util.Images;
25 import org.turro.plugin.contacts.IContact;
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.zk.ui.ext.AfterCompose;
30 import org.zkoss.zul.A;
31 import org.zkoss.zul.Hlayout;
32 import org.zkoss.zul.Vlayout;
33 
38 public class AttendeesList extends Vlayout implements AfterCompose {
39 
40  private Collection<String> attendees;
41  private IContact provider;
42  private boolean readOnly, allowExternals;
43 
44  public AttendeesList() {
45  }
46 
47  public Collection<String> getAttendees() {
48  return attendees;
49  }
50 
51  public void setAttendees(Collection<String> attendees) {
52  this.attendees = attendees;
53  }
54 
55  public void setProvider(IContact provider) {
56  this.provider = provider;
57  }
58 
59  public void updateProvider(IContact provider) {
60  setProvider(provider);
61  afterCompose();
62  }
63 
64  public void setReadOnly(boolean readOnly) {
65  this.readOnly = readOnly;
66  }
67 
68  public void setAllowExternals(boolean allowExternals) {
69  this.allowExternals = allowExternals;
70  }
71 
72  @Override
73  public void afterCompose() {
74  addAttendees();
75  }
76 
77  private void addAttendees() {
78  getChildren().clear();
79  if(attendees != null) {
80  for(final String a : attendees) {
81  final Hlayout row = new Hlayout();
82  row.appendChild(new ContactInfo(a));
83  if(!readOnly) {
84  A del = new A(null, Images.getImage("edit-delete"));
85  del.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
86  @Override
87  public void onEvent(Event event) throws Exception {
88  attendees.remove(a);
89  row.detach();
90  Events.postEvent(new Event(Events.ON_CHANGE, AttendeesList.this, null));
91  }
92  });
93  row.appendChild(del);
94  }
95  appendChild(row);
96  }
97  }
98  if(!readOnly) {
99  Hlayout hbox = new Hlayout();
100  hbox.setSclass("z-valign-middle");
101  hbox.setValign("middle");
102  if(provider != null) {
103  final ContactListbox cl = new ContactListbox();
104  cl.setMold("select");
105  cl.setAllowNull(true);
106  cl.setProvider((Contact) provider.getContact());
107  cl.addEventListener(Events.ON_SELECT, new EventListener<Event>() {
108  @Override
109  public void onEvent(Event event) throws Exception {
110  Contact c = cl.getObjectValue();
111  if(c != null) attendees.add(c.getId());
112  Events.postEvent(new Event(Events.ON_CHANGE, AttendeesList.this, null));
113  addAttendees();
114  }
115  });
116  hbox.appendChild(cl);
117  }
118  if(allowExternals) {
119  final ContactCombobox cc = new ContactCombobox();
120  cc.addEventListener(Events.ON_SELECT, new EventListener<Event>() {
121  @Override
122  public void onEvent(Event event) throws Exception {
123  Contact c = cc.getContact();
124  if(c != null) attendees.add(c.getId());
125  Events.postEvent(new Event(Events.ON_CHANGE, AttendeesList.this, null));
126  addAttendees();
127  }
128  });
129  hbox.appendChild(cc);
130  }
131  if(!hbox.getChildren().isEmpty()) {
132  appendChild(hbox);
133  }
134  }
135  }
136 
137 }
void setProvider(IContact provider)
void setAllowExternals(boolean allowExternals)
void setAttendees(Collection< String > attendees)
void updateProvider(IContact provider)
static String getImage(String image)
Definition: Images.java:36