BrightSide Workbench Full Report + Source Code
IssueSummary.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.issue;
19 
20 import java.util.ArrayList;
21 import java.util.Arrays;
22 import java.util.List;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import org.turro.dossier.db.DossierPU;
26 import org.turro.dossier.dossier.DossierData;
27 import org.turro.dossier.entity.Dossier;
28 import org.turro.dossier.entity.Issue;
29 import org.turro.dossier.issue.IssueWrapper;
30 import org.turro.dossier.zul.menu.DossierMenu;
31 import org.turro.elephant.context.Application;
32 import org.turro.elephant.context.ElephantContext;
33 import org.turro.elephant.db.WhereClause;
34 import org.turro.elephant.util.BooleanFormats;
35 import org.turro.i18n.I_;
36 import org.turro.jpa.Dao;
37 import org.turro.jpa.grid.RendererOnDemand;
38 import org.turro.zkoss.grid.PagingGrid;
39 import org.turro.zkoss.label.LabelExtended;
40 import org.zkoss.lang.Strings;
41 import org.zkoss.zk.ui.event.Event;
42 import org.zkoss.zk.ui.event.EventListener;
43 import org.zkoss.zk.ui.event.Events;
44 import org.zkoss.zul.Column;
45 import org.zkoss.zul.Columns;
46 import org.zkoss.zul.Hbox;
47 import org.zkoss.zul.Label;
48 import org.zkoss.zul.ListModelList;
49 import org.zkoss.zul.Row;
50 import org.zkoss.zul.Vbox;
51 
56 public class IssueSummary extends PagingGrid {
57 
58  private String issueColumns;
59  private List<String> cols;
60 
61  public void setDossier(Dossier dossier) {
62  cols = issueColumns == null ? new ArrayList<>() :
63  Arrays.asList(issueColumns.split("\\s*\\,\\s*"));
64  if(cols.isEmpty()) {
65  cols.add("date");
66  cols.add("description");
67  cols.add("status");
68  cols.add("modification");
69  cols.add("publishable");
70  }
71  addColumns();
72  setIssueIdList(createListFromDossier(dossier));
73  }
74 
75  public void setIssueColumns(String issueColumns) {
76  this.issueColumns = issueColumns;
77  }
78 
79  public void setIssueIdList(List<Long> issues) {
80  addRows(issues);
81  }
82 
83  private void addColumns() {
84  Columns columns = new Columns();
85  appendChild(columns);
86 
87  for(String col : cols) {
88  if("description".equals(col)) {
89  Column column = new Column(I_.get("Description"));
90  columns.appendChild(column);
91  } else if("status".equals(col)) {
92  Column column = new Column(I_.get("Status"));
93  columns.appendChild(column);
94  try {
95  column.setSort("auto");
96  } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
97  Logger.getLogger(IssueSummary.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
98  }
99  column.setWidth("130px");
100  } else if("modification".equals(col)) {
101  Column column = new Column(I_.get("Modification"));
102  columns.appendChild(column);
103  column.setWidth("100px");
104  } else if("date".equals(col)) {
105  Column column = new Column(I_.get("Date"));
106  columns.appendChild(column);
107  column.setWidth("100px");
108  } else if("publishable".equals(col)) {
109  Column column = new Column(I_.get("Publishable"));
110  columns.appendChild(column);
111  column.setWidth("100px");
112  }
113  }
114  }
115 
116  private void addRows(List<Long> issues) {
117 
118  setRowRenderer(new RendererOnDemand<Issue, Long>(() -> new DossierPU()) {
119  @Override
120  protected void renderRow(Row row, final Issue issue) {
121  fillRow(row, issue);
122  }
123  });
124 
125  setModel(new ListModelList<>(issues));
126 
127  setRowCount(issues.size());
128 
129  }
130 
131  private List<Long> createListFromDossier(Dossier dossier) {
132  Dao dao = new DossierPU();
133  WhereClause wc = new WhereClause();
134  wc.addClause("select issue.id from Issue as issue");
135  wc.addClause("where issue.dossier = :dossier");
136  wc.addClause("order by issue.issueDate");
137  wc.addNamedValue("dossier", dossier);
138  return dao.getResultList(wc);
139  }
140 
141  private void fillRow(Row row, final Issue issue) {
142  DossierData dd = new IssueWrapper(issue).getData();
143  for(String col : cols) {
144  if("description".equals(col)) {
145  Vbox vbox = new Vbox();
146  row.appendChild(vbox);
147  LabelExtended lext = new LabelExtended();
148  lext.setMultiline(true);
149  lext.setValue(Strings.isEmpty(issue.getDescription()) ?
150  I_.get("No description!") : issue.getDescription());
151  if(Application.getApplication().isInRole("issue:show")) {
152  lext.setStyle("cursor:pointer");
153  lext.addEventListener(Events.ON_CLICK, new EventListener() {
154  @Override
155  public void onEvent(Event event) throws Exception {
156  DossierMenu.showIssue(issue.getId());
157  }
158  });
159  }
160  vbox.appendChild(lext);
161  if(dd.isExpenses()) {
162  Hbox hbox = new Hbox();
163  Label label = new Label(I_.get("Expenses"));
164  label.setStyle("color:navy;font-size:11px");
165  hbox.appendChild(label);
166  label = new Label(dd.getExpensesString());
167  label.setStyle("color:#666;font-size:11px");
168  hbox.appendChild(label);
169  vbox.appendChild(hbox);
170  }
171  if(dd.isHours()) {
172  Hbox hbox = new Hbox();
173  Label label = new Label(I_.get("Hours"));
174  label.setStyle("color:navy;font-size:11px");
175  hbox.appendChild(label);
176  label = new Label(dd.getHoursString());
177  label.setStyle("color:#666;font-size:11px");
178  hbox.appendChild(label);
179  vbox.appendChild(hbox);
180  }
181  if(dd.isPrice()) {
182  Hbox hbox = new Hbox();
183  Label label = new Label(I_.get("Price"));
184  label.setStyle("color:navy;font-size:11px");
185  hbox.appendChild(label);
186  label = new Label(dd.getPriceString());
187  label.setStyle("color:#666;font-size:11px");
188  hbox.appendChild(label);
189  vbox.appendChild(hbox);
190  }
191  } else if("status".equals(col)) {
192  LabelExtended lext = new LabelExtended();
193  lext.setResourceValue(issue.getStatus().toString());
194  row.appendChild(lext);
195  } else if("modification".equals(col)) {
196  LabelExtended lext = new LabelExtended();
197  lext.setDate(issue.getModification());
198  row.appendChild(lext);
199  } else if("date".equals(col)) {
200  LabelExtended lext = new LabelExtended();
201  lext.setDate(issue.getIssueDate());
202  row.appendChild(lext);
203  } else if("publishable".equals(col)) {
204  LabelExtended lext = new LabelExtended();
205  lext.setValue(BooleanFormats.format(issue.isPublishable()));
206  row.appendChild(lext);
207  }
208  }
209  }
210 
211 }
void setIssueIdList(List< Long > issues)
void setIssueColumns(String issueColumns)
static String get(String msg)
Definition: I_.java:41