BrightSide Workbench Full Report + Source Code
dossier/ParticipantGrid.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.command.Command;
22 import org.turro.command.Context;
23 import org.turro.contacts.Contact;
24 import org.turro.contacts.zul.label.ContactInfo;
25 import org.turro.dossier.entity.CategoryParticipant;
26 import org.turro.dossier.entity.Dossier;
27 import org.turro.dossier.entity.IDossierParticipant;
28 import org.turro.dossier.entity.Participant;
29 import org.turro.i18n.I_;
30 import org.turro.zkoss.dialog.SelectionDialog;
31 import org.turro.zkoss.grid.PagingGrid;
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.Column;
36 import org.zkoss.zul.Columns;
37 import org.zkoss.zul.Hlayout;
38 import org.zkoss.zul.Image;
39 import org.zkoss.zul.Label;
40 import org.zkoss.zul.Row;
41 import org.zkoss.zul.Rows;
42 import org.zkoss.zul.Toolbarbutton;
43 
48 public class ParticipantGrid extends PagingGrid {
49 
50  private Dossier dossier;
51  private final Rows rows;
52  private Toolbarbutton editButton;
53 
54  public ParticipantGrid() {
55  addColumns();
56  rows = new Rows();
57  appendChild(rows);
58  }
59 
60  public void edit() {
61  if(dossier != null) {
63  dpg.setSclass("grid-header-wrap");
64  dpg.setAllowDeletions(true);
65  dpg.setAllowInsertions(true);
66  SelectionDialog.showComponent(getPage(), I_.get("Participants"),
67  dpg, "900px", "500px", new Command() {
68  @Override
69  public Object execute(Context context) {
70  doClean();
71  setDossier(dossier);
72  Events.postEvent(new Event(Events.ON_CHANGE));
73  return null;
74  }
75  });
76  }
77  }
78 
79  public void setDossier(Dossier dossier) {
80  this.dossier = dossier;
81  rows.getChildren().clear();
82  if(dossier != null) {
83  addRows();
84  }
85  }
86 
87  public void setAddToolbar(boolean addToolbar) {
88  if(addToolbar) {
89  addToolbarButtons();
90  }
91  }
92 
93  private void addColumns() {
94  Columns cols = new Columns();
95  cols.setSizable(true);
96  cols.setMenupopup("auto");
97  appendChild(cols);
98 
99  Column col = new Column(I_.get("Name"));
100  cols.appendChild(col);
101 
102  col = new Column(I_.get("Role"));
103  col.setWidth("100px");
104  cols.appendChild(col);
105 
106  col = new Column(I_.get("Discriminator"));
107  col.setWidth("110px");
108  cols.appendChild(col);
109  }
110 
111  public void addRows() {
112  for(final IDossierParticipant p : dossier.getFullParticipants()) {
113  if(isEmpty(p)) continue;
114  Row row = new Row();
115  row.setValue(p);
116  rows.appendChild(row);
117 
118  Hlayout hbox = new Hlayout();
119  row.appendChild(hbox);
120  if(p instanceof CategoryParticipant) {
121  hbox.appendChild(new Image("/_zul/images/forward.png"));
122  }
123  if(p.isShowAllAttachments()) {
124  hbox.appendChild(new Image("/_zul/images/clip.png"));
125  }
126  if(p.isShowAllIssues()) {
127  hbox.appendChild(new Image("/_zul/images/issue.png"));
128  }
129  if(p.isReceiveAllEmails()) {
130  hbox.appendChild(new Image("/_zul/images/mail_forward.png"));
131  }
132  if(p.isShowParticipants()) {
133  hbox.appendChild(new Image("/_zul/images/contacts.png"));
134  }
135  if(p.isBindingVote()) {
136  hbox.appendChild(new Image("/_zul/images/accepted.png"));
137  }
138  if(p.isDriver()) {
139  hbox.appendChild(new Image("/_zul/images/driver.png"));
140  }
141  if(p.isCoordinator()) {
142  hbox.appendChild(new Image("/_zul/images/coordinator.png"));
143  }
144  if(p.isBeneficiary()) {
145  hbox.appendChild(new Image("/_zul/images/beneficiary.png"));
146  }
147  if(p.isOfferer()) {
148  hbox.appendChild(new Image("/_zul/images/offerer.png"));
149  }
150  if(p.isResearch()) {
151  hbox.appendChild(new Image("/_zul/images/research.png"));
152  }
153  if(p.isFunding()) {
154  hbox.appendChild(new Image("/_zul/images/funding.png"));
155  }
156  if(p.isSupport()) {
157  hbox.appendChild(new Image("/_zul/images/support.png"));
158  }
159  if(p.isConsortium()) {
160  hbox.appendChild(new Image("/_zul/images/consortium.png"));
161  }
162  if(p.isAdmin()) {
163  hbox.appendChild(new Image("/_zul/images/admin.png"));
164  }
165 
166  hbox.appendChild(new ContactInfo((Contact) p.getIContact().getContact()));
167  Label label = new Label(I_.byKey(p.getRole().toString()));
168  row.appendChild(label);
169  label = new Label(p.getDiscriminator());
170  row.appendChild(label);
171  }
172  setRowCount(rows.getChildren().size());
173  }
174 
175  private void addToolbarButtons() {
176  editButton = new Toolbarbutton(
177  I_.get("Edit participants"),
178  "/_zul/images/edit.png"
179  );
180  editButton.addEventListener(Events.ON_CLICK, new EventListener() {
181  @Override
182  public void onEvent(Event event) throws Exception {
183  ParticipantGrid.this.edit();
184  }
185 
186  });
187  getParent().appendChild(editButton);
188  }
189 
190  private void doClean() {
191  Iterator<Participant> it = dossier.getParticipants().iterator();
192  while(it.hasNext()) {
193  Participant p = it.next();
194  if(p.isEmpty()) {
195  it.remove();
196  } else {
197  p.setIContact(p.getIContact());
198  }
199  }
200  dossier.resetParticipants();
201  }
202 
203  private boolean isEmpty(IDossierParticipant p) {
204  if(p instanceof CategoryParticipant) {
205  return ((CategoryParticipant) p).isEmpty();
206  } else if(p instanceof Participant) {
207  return ((Participant) p).isEmpty();
208  }
209  return true;
210  }
211 
212 }
Set< Participant > getParticipants()
Definition: Dossier.java:175
ParticipantSet< IDossierParticipant > getFullParticipants()
Definition: Dossier.java:399
static String byKey(String key)
Definition: I_.java:83
static String get(String msg)
Definition: I_.java:41
static void showComponent(Page page, String title, Component component, String width, String height, final Command command)
void setAllowDeletions(boolean allowDeletions)
void setAllowInsertions(boolean allowInsertions)