BrightSide Workbench Full Report + Source Code
DossierGrid.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.dossier;
19 
20 import java.util.Comparator;
21 import java.util.List;
22 import java.util.Set;
23 import org.turro.attach.zul.control.AttachmentControl;
24 import org.turro.contacts.zul.label.ContactInfo;
25 import org.turro.dossier.db.DossierPU;
26 import org.turro.dossier.dossier.DossierData;
27 import org.turro.dossier.dossier.DossierWrapper;
28 import org.turro.dossier.dw.DossierDWReport;
29 import org.turro.dossier.entity.Dossier;
30 import org.turro.dossier.entity.DossierVersion;
31 import org.turro.dossier.entity.DossierVersionStatus;
32 import org.turro.dossier.entity.Participant;
33 import org.turro.dossier.search.DossierIds;
34 import org.turro.dossier.search.DossierResults;
35 import org.turro.elephant.context.Application;
36 import org.turro.elephant.util.Messages;
37 import org.turro.i18n.I_;
38 import org.turro.jpa.grid.RendererOnDemand;
39 import org.turro.log.SystemLogType;
40 import org.turro.log.SystemLogger;
41 import org.turro.util.CompareUtil;
42 import org.turro.zkoss.dialog.SelectionDialog;
43 import org.turro.zkoss.grid.PagingGrid;
44 import org.turro.zkoss.label.LabelExtended;
45 import org.turro.zkoss.label.LabelTypes;
46 import org.turro.zul.frame.Framework;
47 import org.zkoss.zk.ui.Component;
48 import org.zkoss.zk.ui.event.Event;
49 import org.zkoss.zk.ui.event.EventListener;
50 import org.zkoss.zk.ui.event.Events;
51 import org.zkoss.zul.A;
52 import org.zkoss.zul.Column;
53 import org.zkoss.zul.Columns;
54 import org.zkoss.zul.Group;
55 import org.zkoss.zul.GroupsModelArray;
56 import org.zkoss.zul.Hlayout;
57 import org.zkoss.zul.Image;
58 import org.zkoss.zul.Label;
59 import org.zkoss.zul.Row;
60 import org.zkoss.zul.Rows;
61 import org.zkoss.zul.Vlayout;
62 
67 public class DossierGrid extends PagingGrid {
68 
69  private Rows rows;
70 
71  public DossierGrid() {
72  addColumns();
73  }
74 
75 // public void setDossierList(List<Dossier> dossiers) {
76 // addRows(dossiers);
77 // }
78 
79  public void setDossierResults(DossierResults results) {
80  if(results != null) {
81 // setDossierList(results.getDossierList());
82  addRows(results.getDossierIdList());
83  }
84  }
85 
86  private void addColumns() {
87  Columns cols = new Columns();
88  cols.setSizable(true);
89  cols.setMenupopup("auto");
90  appendChild(cols);
91 
92  //addDetailColumn();
93 
94  Column col = new Column("#");
95  col.setWidth("60px");
96  cols.appendChild(col);
97  col = new Column(I_.get("Description"));
98  cols.appendChild(col);
99  col = new Column(I_.get("Creation"));
100  col.setWidth("120px");
101  cols.appendChild(col);
102  col = new Column(I_.get("Status"));
103  col.setWidth("200px");
104  cols.appendChild(col);
105  col = new Column(I_.get("Data"));
106  col.setWidth("250px");
107  cols.appendChild(col);
108  if(Application.getApplication().isInRole("dossier:delete")) {
109  col = new Column();
110  col.setWidth("25px");
111  cols.appendChild(col);
112  }
113  }
114 
115  private void addRows(List dossiers) {
116 
117  setRowRenderer(new RendererOnDemand<Dossier, DossierIds>(() -> new DossierPU()) {
118  @Override
119  protected Object getId(DossierIds id) {
120  return id.dossierId;
121  }
122  @Override
123  protected void renderRow(Row row, final Dossier dossier) {
124  fillRow(row, dossier);
125  }
126  @Override
127  protected void renderGroup(Group group, Dossier dossier) {
128  group.setLabel(dossier.getCategory().getFullDescription());
129  }
130  });
131 
132  setModel(new GroupsModelArray<DossierIds, String, String, Object>(
133  (DossierIds[]) dossiers.toArray(new DossierIds[0]),
134  new Comparator<DossierIds>() {
135  @Override
136  public int compare(DossierIds o1, DossierIds o2) {
137  return CompareUtil.compare(o1.categoryId, o2.categoryId);
138  }
139  }
140  ));
141 
142  setRowCount(dossiers.size());
143  }
144 
145 // private void createGroup(Category category, boolean expanded) {
146 // String label = category == null ? I_.get("Without category") : category.getFullDescription();
147 // Group group = new GroupExtended(label);
148 // group.setOpen(expanded);
149 // rows.appendChild(group);
150 // }
151 
152  private void fillRow(Row row, final Dossier dossier) {
153  Label label = new Label(dossier.getId() + "");
154  row.appendChild(label);
155 
156  Vlayout vbox = new Vlayout();
157  row.appendChild(vbox);
158 
159  Hlayout hbox = new Hlayout();
160  vbox.appendChild(hbox);
161  hbox.appendChild(new DossierLabel(dossier, false));
162 
163  Set<DossierVersion> dvs = dossier.getActiveVersions();
164  if(!dvs.isEmpty()) {
165  hbox.appendChild(LabelTypes.getTinyLabel(" ["));
166  for(DossierVersion dv : dvs) {
167  if(dv.isActive()) {
168  hbox.appendChild(createLabel(dv));
169  }
170  }
171  hbox.appendChild(LabelTypes.getTinyLabel("]"));
172  }
173 
174  Participant subject = dossier.getSubject();
175  if(subject != null) {
176  ContactInfo ci = new ContactInfo(subject.getIdContact());
177  ci.setSclass("softLabel");
178  vbox.appendChild(ci);
179  }
180 
181  LabelExtended lext = new LabelExtended();
182  lext.setStyle("color:gray;font-size:11px");
183  lext.setValue(dossier.getExtraDescription());
184  lext.setMaxChars(70);
185  lext.setShowTooltip(true);
186  vbox.appendChild(lext);
187 
188  vbox = new Vlayout();
189  row.appendChild(vbox);
190 
191  lext = new LabelExtended();
192  lext.setDate(dossier.getCreation());
193  vbox.appendChild(lext);
194 
195  hbox = new Hlayout();
196  vbox.appendChild(hbox);
197 
198  lext = new LabelExtended();
199  lext.setStyle("color:gray;font-size:11px;");
200  lext.setDate(new DossierWrapper(dossier).getIssueLastModification());
201  hbox.appendChild(lext);
202 
203  hbox.appendChild(new Image("/_zul/images/activity.png"));
204 
205  vbox.appendChild(hbox);
206 
207  vbox = new Vlayout();
208  row.appendChild(vbox);
209 
210  lext = new LabelExtended();
211  lext.setResourceValue(dossier.getStatus().toString());
212  vbox.appendChild(lext);
213 
214  DossierDWReport dr = new DossierDWReport();
215  dr.setReportValues(null, null, dossier.getId());
216 
217  label = new Label(((long) dr.getOnWork()) + " " +
218  I_.get("Of") + " " + ((long) dr.getIssueCount()) + " " +
219  I_.get("Work in progress"));
220  label.setStyle("color:gray;font-size:11px;");
221  vbox.appendChild(label);
222 
223  label = new Label(dr.getEfectivity() + "%" + " " +
224  I_.get("Efectivity"));
225  label.setStyle("color:gray;font-size:11px;");
226  vbox.appendChild(label);
227 
228  vbox = new Vlayout();
229  row.appendChild(vbox);
230 
231  if(Application.getApplication().isInRole("dossier:attach")) {
232  A a = new A(I_.get("Attachments"), "/_zul/images/clip.png");
233  a.addEventListener(Events.ON_CLICK, new EventListener() {
234  @Override
235  public void onEvent(Event event) throws Exception {
236 // DossierAttachTree dat = new DossierAttachTree();
237 // dat.setVertical(true);
238 // dat.setDossier(dossier);
239 // SelectionDialog.showComponent(getPage(), I_.get("Attachments"),
240 // dat, "900px", "500px");
241  AttachmentControl ac = new AttachmentControl();
242  ac.setEntity(dossier);
243  ac.setPublicOnly(!(new DossierWrapper(dossier).getCanShowAllAttachments()));
244  SelectionDialog.showComponent(getPage(), I_.get("Attachments"),
245  ac, "80%", "80%", null);
246  }
247  });
248  vbox.appendChild(a);
249  }
250 
251  DossierData dd = dr.getData();
252  if(dd.isExpenses()) {
253  label = new Label(I_.get("Expenses"));
254  label.setStyle("color:navy;font-size:11px");
255  vbox.appendChild(label);
256  label = new Label(dd.getExpensesString());
257  label.setStyle("color:#666;font-size:11px");
258  vbox.appendChild(label);
259  }
260  if(dd.isHours()) {
261  label = new Label(I_.get("Hours"));
262  label.setStyle("color:navy;font-size:11px");
263  vbox.appendChild(label);
264  label = new Label(dd.getHoursString());
265  label.setStyle("color:#666;font-size:11px");
266  vbox.appendChild(label);
267  }
268  if(dd.isPrice()) {
269  label = new Label(I_.get("Price"));
270  label.setStyle("color:navy;font-size:11px");
271  vbox.appendChild(label);
272  label = new Label(dd.getPriceString());
273  label.setStyle("color:#666;font-size:11px");
274  vbox.appendChild(label);
275  }
276 
277  if(Application.getApplication().isInRole("dossier:delete")) {
278  Image img = new Image("/_zul/images/edit-delete.png");
279  img.setStyle("cursor:pointer");
280  img.addEventListener(Events.ON_CLICK, new EventListener() {
281  @Override
282  public void onEvent(Event event) throws Exception {
283  Messages.confirmDeletion().show(() -> {
284  SystemLogger.getInstance().doLog(SystemLogType.LOG_INFO, dossier, "deleted",
285  dossier.getFullDescription());
286  new DossierWrapper(dossier).delete();
287  Framework.getCurrent().invalidateSelected();
288  });
289  }
290  });
291  row.appendChild(img);
292  }
293  }
294 
295  private Component createLabel(DossierVersion dv) {
296  Label l = LabelTypes.getTinyLabel(dv.getVersionId());
297  DossierVersionStatus dvs = dv.getStatus();
298  if(dvs.equals(DossierVersionStatus.VERSION_READY)) {
299  l.setStyle("color:green !important;");
300  } else if(dvs.equals(DossierVersionStatus.VERSION_STOPPED)) {
301  l.setStyle("color:red !important;");
302  } else if(dvs.equals(DossierVersionStatus.VERSION_NOTRECOMMENDED)) {
303  l.setStyle("color:blue !important;");
304  }
305  return l;
306  }
307 
308 }
java.util.List< DossierIds > getDossierIdList()
void setDossierResults(DossierResults results)
static String get(String msg)
Definition: I_.java:41