BrightSide Workbench Full Report + Source Code
CategoryParticipantGrid2.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.dossier.zul.dossier;
19 
20 import java.util.Iterator;
21 import org.turro.contacts.util.ContactCombobox;
22 import org.turro.dossier.entity.Category;
23 import org.turro.dossier.entity.CategoryParticipant;
24 import org.turro.dossier.entity.ParticipantRole;
25 import org.turro.i18n.I_;
26 import org.turro.plugin.contacts.IContact;
27 import org.zkoss.zk.ui.event.Event;
28 import org.zkoss.zk.ui.event.EventListener;
29 import org.zkoss.zk.ui.event.Events;
30 import org.zkoss.zul.Checkbox;
31 import org.zkoss.zul.Column;
32 import org.zkoss.zul.Columns;
33 import org.zkoss.zul.Grid;
34 import org.zkoss.zul.Listbox;
35 import org.zkoss.zul.Listitem;
36 import org.zkoss.zul.Row;
37 import org.zkoss.zul.Rows;
38 import org.zkoss.zul.Toolbar;
39 import org.zkoss.zul.Toolbarbutton;
40 import org.zkoss.zul.Vbox;
41 
46 public class CategoryParticipantGrid2 extends Grid {
47 
48  private Category category;
49  private Rows rows;
50  private Toolbar toolbar;
51  private Toolbarbutton addButton;
52 
54  addColumns();
55  rows = new Rows();
56  appendChild(rows);
57  }
58 
59  public void setCategory(Category category) {
60  this.category = category;
61  rows.getChildren().clear();
62  if(category != null) {
63  addRows();
64  }
65  }
66 
67  public void setAddToolbar(boolean addToolbar) {
68  if(addToolbar) {
69  toolbar = new Toolbar();
70  getParent().appendChild(toolbar);
71  addToolbarButtons();
72  }
73  }
74 
75  private void addColumns() {
76  Columns cols = new Columns();
77  cols.setSizable(true);
78  cols.setMenupopup("auto");
79  appendChild(cols);
80 
81  Column col = new Column(I_.get("Name"));
82  cols.appendChild(col);
83 
84  col = new Column(I_.get("Role"));
85  cols.appendChild(col);
86  }
87 
88  public void addRows() {
89  for(final CategoryParticipant p : category.getParticipants()) {
90  Row row = new Row();
91  row.setValue(p);
92  rows.appendChild(row);
93 
94  Vbox vbox = new Vbox();
95  vbox.setWidth("100%");
96  row.appendChild(vbox);
97 
98  final ContactCombobox contact = new ContactCombobox();
99  contact.setRole("dossier:list");
100  contact.setIContact(p.getIContact());
101  contact.addEventListener(Events.ON_CHANGE, new EventListener() {
102  @Override
103  public void onEvent(Event event) throws Exception {
104  IContact ci = contact.getIContact();
105  p.setIdContact(ci.getId());
106  if(ci.isValid()) {
107  p.setName(ci.getName());
108  }
109  }
110 
111  });
112  vbox.appendChild(contact);
113 
114  final Checkbox cbAttach = new Checkbox(I_.get("Show all attachments"));
115  cbAttach.setStyle("font-size:11px;color:#444;");
116  cbAttach.setChecked(p.isShowAllAttachments());
117  cbAttach.addEventListener(Events.ON_CHECK, new EventListener() {
118 
119  @Override
120  public void onEvent(Event event) throws Exception {
121  p.setShowAllAttachments(cbAttach.isChecked());
122  }
123 
124  });
125  vbox.appendChild(cbAttach);
126 
127  final Checkbox cbIssues = new Checkbox(I_.get("Show all issues"));
128  cbIssues.setStyle("font-size:11px;color:#444;");
129  cbIssues.setChecked(p.isShowAllIssues());
130  cbIssues.addEventListener(Events.ON_CHECK, new EventListener() {
131 
132  @Override
133  public void onEvent(Event event) throws Exception {
134  p.setShowAllIssues(cbIssues.isChecked());
135  }
136 
137  });
138  vbox.appendChild(cbIssues);
139 
140  final Checkbox cbEmails = new Checkbox(I_.get("Receive all emails"));
141  cbEmails.setStyle("font-size:11px;color:#444;");
142  cbEmails.setChecked(p.isReceiveAllEmails());
143  cbEmails.addEventListener(Events.ON_CHECK, new EventListener() {
144 
145  @Override
146  public void onEvent(Event event) throws Exception {
147  p.setReceiveAllEmails(cbEmails.isChecked());
148  }
149 
150  });
151  vbox.appendChild(cbEmails);
152 
153  final Checkbox cbParticipants = new Checkbox(I_.get("Show participants"));
154  cbParticipants.setStyle("font-size:11px;color:#444;");
155  cbParticipants.setChecked(p.isShowParticipants());
156  cbParticipants.addEventListener(Events.ON_CHECK, new EventListener() {
157 
158  @Override
159  public void onEvent(Event event) throws Exception {
160  p.setShowParticipants(cbParticipants.isChecked());
161  }
162 
163  });
164  vbox.appendChild(cbParticipants);
165 
166  final Checkbox cbBinding = new Checkbox(I_.get("Binding votes"));
167  cbBinding.setStyle("font-size:11px;color:#444;");
168  cbBinding.setChecked(p.isBindingVote());
169  cbBinding.addEventListener(Events.ON_CHECK, new EventListener() {
170 
171  @Override
172  public void onEvent(Event event) throws Exception {
173  p.setBindingVote(cbBinding.isChecked());
174  }
175 
176  });
177  vbox.appendChild(cbBinding);
178 
179  final Listbox role = new Listbox();
180  role.setMold("select");
181  role.addEventListener(Events.ON_SELECT, new EventListener() {
182 
183  @Override
184  public void onEvent(Event event) throws Exception {
185  p.setRole((ParticipantRole) role.getSelectedItem().getValue());
186  if(p.getRole().equals(ParticipantRole.PARTICIPANT_SUBJECT)) {
187  contact.setRole("");
188  } else {
189  contact.setRole("dossier:list");
190  }
191  }
192 
193  });
194  row.appendChild(role);
195 
196  for(ParticipantRole pr : ParticipantRole.values()) {
197  Listitem li = new Listitem(I_.byKey(pr.toString()));
198  li.setValue(pr);
199  li.setSelected(li.getValue().equals(p.getRole()));
200  role.appendChild(li);
201  }
202 
203  }
204  }
205 
206  private void addToolbarButtons() {
207  addButton = new Toolbarbutton(
208  I_.get("Add participant"),
209  "/_zul/images/new.png"
210  );
211  addButton.addEventListener(Events.ON_CLICK, new EventListener() {
212 
213  @Override
214  public void onEvent(Event event) throws Exception {
217  p.setCategory(category);
218  category.getParticipants().add(p);
219  setCategory(category);
220  }
221 
222  });
223  toolbar.appendChild(addButton);
224  }
225 
226  public void beforeSave() {
227  Iterator<CategoryParticipant> it = category.getParticipants().iterator();
228  while(it.hasNext()) {
229  CategoryParticipant p = it.next();
230  if(!p.getIContact().isValid()) {
231  it.remove();
232  }
233  }
234  }
235 
236 }
Set< Category > getChildren()
Definition: Category.java:84
Set< CategoryParticipant > getParticipants()
Definition: Category.java:116
static String byKey(String key)
Definition: I_.java:83
static String get(String msg)
Definition: I_.java:41