18 package org.turro.dossier.zul.issue;
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;
58 private String issueColumns;
59 private List<String> cols;
62 cols = issueColumns ==
null ?
new ArrayList<>() :
63 Arrays.asList(issueColumns.split(
"\\s*\\,\\s*"));
66 cols.add(
"description");
68 cols.add(
"modification");
69 cols.add(
"publishable");
76 this.issueColumns = issueColumns;
83 private void addColumns() {
84 Columns columns =
new Columns();
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);
95 column.setSort(
"auto");
96 }
catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
97 Logger.getLogger(IssueSummary.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
null), ex);
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");
116 private void addRows(List<Long> issues) {
118 setRowRenderer(
new RendererOnDemand<Issue, Long>(() ->
new DossierPU()) {
120 protected void renderRow(Row row,
final Issue issue) {
125 setModel(
new ListModelList<>(issues));
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);
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() {
155 public void onEvent(Event event)
throws Exception {
156 DossierMenu.showIssue(issue.getId());
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);
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);
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);
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);
void setIssueIdList(List< Long > issues)
void setDossier(Dossier dossier)
void setIssueColumns(String issueColumns)
static String get(String msg)
void setRowCount(int rows)