BrightSide Workbench Full Report + Source Code
Elephant/elephant-mail/src/main/java/org/turro/sendable/MailRecipients.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2018 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.sendable;
20 
21 import java.util.Collection;
22 import org.turro.action.Contacts;
23 import org.turro.command.Command;
24 import org.turro.elephant.security.IUser;
25 import org.turro.elephant.util.Images;
26 import org.turro.entities.EntityCombobox;
27 import org.turro.i18n.I_;
28 import org.turro.plugin.contacts.ContactList;
29 import org.turro.plugin.contacts.IContact;
30 import org.turro.zkoss.dialog.SelectionDialog;
31 import org.turro.zkoss.layout.GridLayout;
32 import org.turro.zul.frame.Framework;
33 import org.zkoss.zk.ui.event.Event;
34 import org.zkoss.zk.ui.event.EventListener;
35 import org.zkoss.zk.ui.event.Events;
36 import org.zkoss.zul.A;
37 import org.zkoss.zul.Row;
38 
43 public class MailRecipients extends GridLayout {
44 
45  private Collection<IContact> recipients = new ContactList();
46  private Row editRow;
47 
48  public MailRecipients(Collection<IContact> recipients) {
49  this.recipients.addAll(recipients);
50  setColumns("350px,40px");
51  addRecipients();
52  }
53 
54  public static void selectRecipients(Collection<IContact> recipients, Command command) {
55  MailRecipients mr = new MailRecipients(recipients);
56  mr.setStyle("overflow:auto;");
58  Framework.getCurrent().getPage(),
59  I_.get("Recipients"),
60  mr, "425px", "350px", command);
61  }
62 
63  private void addRecipients() {
64  for(final IContact c : recipients) {
65  if(c.isWebUser() && Contacts.hasValidEmail(c)) {
66  addRecipient(c);
67  addRow();
68  }
69  }
70  editRow = getCurrentRow();
71  final EntityCombobox cc = new EntityCombobox();
72  cc.setRoot("contact");
73  cc.setWidth("390px");
74  cc.addEventListener(Events.ON_OK, new EventListener<Event>() {
75  @Override
76  public void onEvent(Event event) throws Exception {
77  event.stopPropagation();
78  IContact c = Contacts.getContact(cc.getEntity());
79  if(c.isWebUser() && Contacts.hasValidEmail(c)) {
80  insertBeforeRow(editRow);
81  addRecipient(c);
82  cc.setEntity(null);
83  }
84  }
85  });
86  addSpannedComponent(cc, 2);
87  }
88 
89  private void addRecipient(final IContact c) {
90  final Row row = getCurrentRow();
91  row.setValue(c);
92  addCaption(c.getName() + " : " + c.getConnector(IUser.CONNECTOR_EMAIL));
93  A del = new A(null, Images.getImage("edit-delete"));
94  del.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
95  @Override
96  public void onEvent(Event event) throws Exception {
97  row.detach();
98  }
99  });
100  addComponent(del);
101  }
102 
103  public Collection<IContact> getRecipients() {
104  recipients = new ContactList();
105  for(Object o : getRows().getChildren()) {
106  if(o instanceof Row) {
107  if(((Row) o).getValue() instanceof IContact) {
108  recipients.add((IContact) ((Row) o).getValue());
109  }
110  }
111  }
112  return recipients;
113  }
114 
115 }
static boolean hasValidEmail(IContact contact)
Definition: Contacts.java:95
static String get(String msg)
Definition: I_.java:41
static void selectRecipients(Collection< IContact > recipients, Command command)
GridLayout addSpannedComponent(HtmlBasedComponent comp, int cols)
static Framework getCurrent()
Definition: Framework.java:203