BrightSide Workbench Full Report + Source Code
IssueVoteGrid.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2013 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.issue;
20 
21 import org.turro.dossier.db.DossierPU;
22 import org.turro.dossier.entity.Dossier;
23 import org.turro.dossier.entity.Issue;
24 import org.turro.dossier.entity.IssueStatus;
25 import org.turro.dossier.search.DossierResults;
26 import org.turro.elephant.util.DateFormats;
27 import org.turro.elephant.util.Images;
28 import org.turro.i18n.I_;
29 import org.turro.voteit.MyVote;
30 import org.turro.voteit.VoteItUtil;
31 import org.turro.zkoss.grid.GroupExtended;
32 import org.turro.zkoss.grid.PagingGrid;
33 import org.zkoss.zk.ui.Component;
34 import org.zkoss.zk.ui.ext.AfterCompose;
35 import org.zkoss.zul.Column;
36 import org.zkoss.zul.Columns;
37 import org.zkoss.zul.Group;
38 import org.zkoss.zul.Hlayout;
39 import org.zkoss.zul.Image;
40 import org.zkoss.zul.Label;
41 import org.zkoss.zul.Row;
42 
47 public class IssueVoteGrid extends PagingGrid implements AfterCompose {
48 
49  public IssueVoteGrid() {
50  addColumns();
51  }
52 
53  private void addColumns() {
54  Columns cols = new Columns();
55  cols.setSizable(true);
56  cols.setMenupopup("auto");
57  appendChild(cols);
58 
59  Column col = new Column("#");
60  col.setWidth("150px");
61  cols.appendChild(col);
62  col = new Column(I_.get("Creation"));
63  col.setWidth("150px");
64  cols.appendChild(col);
65  col = new Column(I_.get("My vote"));
66  col.setWidth("200px");
67  cols.appendChild(col);
68  col = new Column(I_.get("Description"));
69  cols.appendChild(col);
70  }
71 
72  private void addRows() {
73  DossierResults dossierResults = new DossierResults();
74  for(Dossier dossier : dossierResults.getDossierList()) {
75  if(dossier.getFullParticipants().isVoteParticipant(dossierResults.getByParticipant())) {
76  boolean groupCreated = false;
77  for(Issue issue : dossier.getOpenIssues()) {
78  if(!groupCreated) {
79  createGroup(dossier);
80  groupCreated = true;
81  }
82  MyVote myVote = VoteItUtil.myVote(DossierPU.getObjectPath(issue), dossierResults.getByParticipant());
83  Row row = new Row();
84  if(myVote == null) {
85  row.setSclass("draft");
86  }
87  row.appendChild(new Label("#" + issue.getId()));
88  row.appendChild(new Label(DateFormats.format(issue.getIssueDate(), true)));
89  row.appendChild(getComponent(myVote, issue));
90  row.appendChild(new IssueLabel(issue));
91  getRows().appendChild(row);
92  }
93  }
94  }
95  }
96 
97  private void createGroup(Dossier dossier) {
98  Group group = new GroupExtended(dossier.getFullDescription());
99  group.setOpen(true);
100  getRows(true).appendChild(group);
101  }
102 
103  @Override
104  public void afterCompose() {
105  addRows();
106  }
107 
108  private Component getComponent(MyVote myVote, Issue issue) {
109  Hlayout hbox = new Hlayout();
110  if(myVote != null) {
111  if(myVote.getVote() == 1) {
112  hbox.appendChild(new Image(Images.getImage("ok")));
113  } else if(myVote.getVote() == -1) {
114  hbox.appendChild(new Image(Images.getImage("cancel")));
115  }
116  }
117  if(issue.getStatus().equals(IssueStatus.STATUS_REUNION)) {
118  hbox.appendChild(new Image(Images.getImage("contacts")));
119  }
120  return hbox;
121  }
122 
123 }
static String getImage(String image)
Definition: Images.java:36
static String get(String msg)
Definition: I_.java:41
Rows getRows(boolean create)