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