BrightSide Workbench Full Report + Source Code
viewer/IssueGrid.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.viewer;
19 
20 import java.util.ArrayList;
21 import java.util.Arrays;
22 import java.util.List;
23 import org.turro.dossier.db.DossierPU;
24 import org.turro.dossier.entity.Dossier;
25 import org.turro.dossier.entity.Issue;
26 import org.turro.elephant.db.WhereClause;
27 import org.turro.i18n.I_;
28 import org.turro.jpa.Dao;
29 import org.turro.zkoss.grid.PagingGrid;
30 import org.turro.zkoss.label.LabelExtended;
31 import org.zkoss.lang.Strings;
32 import org.zkoss.zul.Column;
33 import org.zkoss.zul.Columns;
34 import org.zkoss.zul.Row;
35 import org.zkoss.zul.Rows;
36 
41 public class IssueGrid extends PagingGrid {
42 
43  private Rows rows;
44  private Columns columns;
45  private String issueColumns;
46 
47  public IssueGrid() {
48  }
49 
50  public void setIssueColumns(String issueColumns) {
51  this.issueColumns = issueColumns;
52  }
53 
54  public void setDossier(Dossier dossier) {
55  setIssueList(createListFromDossier(dossier));
56  }
57 
58  public void setIssueList(List<Issue> issues) {
59  addRows(issues);
60  }
61 
62  private void addColumns(List<String> cols) {
63  if(columns != null) removeChild(columns);
64 
65  columns = new Columns();
66  columns.setVisible(false);
67  appendChild(columns);
68 
69  for(String col : cols) {
70  if("description".equals(col)) {
71  Column column = new Column("");
72  columns.appendChild(column);
73  } else if("status".equals(col)) {
74  Column column = new Column("");
75  column.setWidth("130px");
76  columns.appendChild(column);
77  } else if("modification".equals(col)) {
78  Column column = new Column("");
79  column.setWidth("100px");
80  columns.appendChild(column);
81  } else if("date".equals(col)) {
82  Column column = new Column("");
83  column.setWidth("100px");
84  columns.appendChild(column);
85  }
86  }
87  }
88 
89  private void addRows(List<Issue> issues) {
90 
91  setRowCount(issues.size());
92 
93  List<String> cols = issueColumns == null ? new ArrayList<String>() :
94  Arrays.asList(issueColumns.split("\\s*\\,\\s*"));
95  if(cols.isEmpty()) {
96  cols.add("date");
97  cols.add("description");
98  cols.add("status");
99  cols.add("modification");
100  }
101 
102  addColumns(cols);
103 
104  if(rows != null) removeChild(rows);
105 
106  rows = new Rows();
107  appendChild(rows);
108 
109  for(final Issue issue : issues) {
110  Row row = new Row();
111  for(String col : cols) {
112  if("description".equals(col)) {
113  LabelExtended lext = new LabelExtended();
114  lext.setMultiline(true);
115  lext.setValue(Strings.isEmpty(issue.getDescription()) ?
116  I_.get("No description!") : issue.getDescription());
117  row.appendChild(lext);
118  } else if("status".equals(col)) {
119  LabelExtended lext = new LabelExtended();
120  lext.setResourceValue(issue.getStatus().toString());
121  row.appendChild(lext);
122  } else if("modification".equals(col)) {
123  LabelExtended lext = new LabelExtended();
124  lext.setDate(issue.getModification());
125  row.appendChild(lext);
126  } else if("date".equals(col)) {
127  LabelExtended lext = new LabelExtended();
128  lext.setDate(issue.getIssueDate());
129  row.appendChild(lext);
130  }
131  }
132 
133  rows.appendChild(row);
134  }
135 
136  invalidate();
137  }
138 
139  private List<Issue> createListFromDossier(Dossier dossier) {
140  Dao dao = new DossierPU();
141  WhereClause wc = new WhereClause();
142  wc.addClause("select issue from Issue as issue");
143  wc.addClause("where issue.dossier = :dossier");
144  wc.addClause("and issue.publishable = TRUE");
145  wc.addClause("order by issue.issueDate");
146  wc.addNamedValue("dossier", dossier);
147  return dao.getResultList(wc);
148  }
149 
150 }
void setIssueList(List< Issue > issues)
void setIssueColumns(String issueColumns)