BrightSide Workbench Full Report + Source Code
PendingPetitionsGrid.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.dossier.zul.dossier;
20 
21 import java.util.List;
22 import org.turro.action.queue.ConstraintKeys;
23 import org.turro.dossier.db.DossierPU;
24 import org.turro.dossier.dossier.ParticipantSet;
25 import org.turro.dossier.entity.CategoryParticipant;
26 import org.turro.dossier.entity.Participant;
27 import org.turro.dossier.entity.ParticipantRequest;
28 import org.turro.elephant.db.WhereClause;
29 import org.turro.elephant.util.DateFormats;
30 import org.turro.elephant.util.Images;
31 import org.turro.entities.Entities;
32 import org.turro.i18n.I_;
33 import org.turro.jpa.Dao;
34 import org.turro.mail.queue.QueueManager;
35 import org.turro.zkoss.grid.PagingGrid;
36 import org.zkoss.zk.ui.Component;
37 import org.zkoss.zk.ui.event.Event;
38 import org.zkoss.zk.ui.event.Events;
39 import org.zkoss.zk.ui.ext.AfterCompose;
40 import org.zkoss.zul.Button;
41 import org.zkoss.zul.Checkbox;
42 import org.zkoss.zul.Column;
43 import org.zkoss.zul.Columns;
44 import org.zkoss.zul.Hlayout;
45 import org.zkoss.zul.Label;
46 import org.zkoss.zul.Row;
47 
52 public class PendingPetitionsGrid extends PagingGrid implements AfterCompose {
53 
55  addColumns();
56  }
57 
58  private void addColumns() {
59  Columns cols = new Columns();
60  cols.setSizable(true);
61  appendChild(cols);
62 
63  Column col = new Column(I_.get("Contact"));
64  col.setHflex("2");
65  cols.appendChild(col);
66  col = new Column(I_.get("Creation"));
67  col.setWidth("150px");
68  cols.appendChild(col);
69  col = new Column(I_.get("Dossier"));
70  col.setHflex("2");
71  cols.appendChild(col);
72  col = new Column();
73  col.setTooltiptext(I_.get("Coordinator"));
74  col.setImage(Images.getImage("coordinator"));
75  col.setWidth("25px");
76  cols.appendChild(col);
77  col = new Column();
78  col.setTooltiptext(I_.get("Beneficiary"));
79  col.setImage(Images.getImage("beneficiary"));
80  col.setWidth("25px");
81  cols.appendChild(col);
82  col = new Column();
83  col.setTooltiptext(I_.get("Offerer"));
84  col.setImage(Images.getImage("offerer"));
85  col.setWidth("25px");
86  cols.appendChild(col);
87  col = new Column();
88  col.setTooltiptext(I_.get("R&D"));
89  col.setImage(Images.getImage("research"));
90  col.setWidth("25px");
91  cols.appendChild(col);
92  col = new Column();
93  col.setTooltiptext(I_.get("Funding"));
94  col.setImage(Images.getImage("funding"));
95  col.setWidth("25px");
96  cols.appendChild(col);
97  col = new Column();
98  col.setTooltiptext(I_.get("Support"));
99  col.setImage(Images.getImage("support"));
100  col.setWidth("25px");
101  cols.appendChild(col);
102  col = new Column();
103  col.setTooltiptext(I_.get("Consortium"));
104  col.setImage(Images.getImage("consortium"));
105  col.setWidth("25px");
106  cols.appendChild(col);
107  col = new Column("");
108  col.setHflex("1");
109  cols.appendChild(col);
110  }
111 
112  private void addRows() {
113  WhereClause wc = new WhereClause();
114  wc.addClause("select pr from ParticipantRequest pr");
115  wc.addClause("order by idContact, dossier.id");
116  List<ParticipantRequest> prs = getDao().getResultList(wc);
117  for(ParticipantRequest pr : prs) {
118  Row row = new Row();
119  row.appendChild((Component) Entities.getController(pr.getIContact().getContact()).getLabelCtrl());
120  row.appendChild(new Label(DateFormats.format(pr.getCreation(), true)));
121  row.appendChild((Component) Entities.getController(pr.getDossier()).getLabelCtrl());
122  Checkbox asCoordinator = new Checkbox();
123  asCoordinator.setChecked(pr.isCoordinator());
124  row.appendChild(asCoordinator);
125  Checkbox asBeneficiary = new Checkbox();
126  asBeneficiary.setChecked(pr.isBeneficiary());
127  row.appendChild(asBeneficiary);
128  Checkbox asOfferer = new Checkbox();
129  asOfferer.setChecked(pr.isOfferer());
130  row.appendChild(asOfferer);
131  Checkbox asResearch = new Checkbox();
132  asResearch.setChecked(pr.isResearch());
133  row.appendChild(asResearch);
134  Checkbox asFunding = new Checkbox();
135  asFunding.setChecked(pr.isFunding());
136  row.appendChild(asFunding);
137  Checkbox asSupport = new Checkbox();
138  asSupport.setChecked(pr.isSupport());
139  row.appendChild(asSupport);
140  Checkbox asConsortium = new Checkbox();
141  asConsortium.setChecked(pr.isConsortium());
142  row.appendChild(asConsortium);
143  Hlayout hbox = new Hlayout();
144  Button add = new Button(I_.get("Add"));
145  add.addEventListener(Events.ON_CLICK, (Event event) -> {
146  Participant participant = pr.getDossier().addOrReturnAssistant(pr.getIContact());
147  participant.setDiscriminator(pr.getDiscriminator());
148  participant.setBeneficiary(asBeneficiary.isChecked());
149  participant.setCoordinator(asCoordinator.isChecked());
150  participant.setFunding(asFunding.isChecked());
151  participant.setOfferer(asOfferer.isChecked());
152  participant.setResearch(asResearch.isChecked());
153  participant.setSupport(asSupport.isChecked());
154  participant.setConsortium(asConsortium.isChecked());
155  getDao().saveObject(pr.getDossier());
156  CategoryParticipant cp;
157  ParticipantSet ps = new ParticipantSet(pr.getDossier().getCategory().getParticipants());
158  if(ps.isParticipant(pr.getIContact())) {
159  cp = (CategoryParticipant) ps.getActiveParticipation(pr.getIContact());
160  } else {
161  cp = pr.getDossier().getCategory().addAssistant(pr.getIContact());
162  }
163  cp.setShowAllIssues(true);
164  getDao().saveObject(pr.getDossier().getCategory());
165  getDao().deleteObject(pr);
166  new QueueManager().subscribeDefaults(ConstraintKeys.from(pr.getIContact()));
167  row.detach();
168  });
169  hbox.appendChild(add);
170  Button delete = new Button(I_.get("Delete"));
171  delete.addEventListener(Events.ON_CLICK, (Event event) -> {
172  getDao().deleteObject(pr);
173  row.detach();
174  });
175  hbox.appendChild(delete);
176  row.appendChild(hbox);
177  row.getChildren().stream().filter((o) -> (o instanceof AfterCompose)).forEachOrdered((o) -> {
178  ((AfterCompose) o).afterCompose();
179  });
180  getRows(true).appendChild(row);
181  }
182  }
183 
184  @Override
185  public void afterCompose() {
186  addRows();
187  }
188 
189  /* Dao */
190 
191  private Dao _dao;
192 
193  private Dao getDao() {
194  if(_dao == null) {
195  _dao = new DossierPU();
196  }
197  return _dao;
198  }
199 
200 }
201 
static String getImage(String image)
Definition: Images.java:36
static String get(String msg)
Definition: I_.java:41
Rows getRows(boolean create)