BrightSide Workbench Full Report + Source Code
DossierRow.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.Set;
21 import org.turro.attach.zul.control.AttachmentControl;
22 import org.turro.contacts.zul.label.ContactInfo;
23 import org.turro.dossier.dossier.DossierData;
24 import org.turro.dossier.dossier.DossierWrapper;
25 import org.turro.dossier.dw.DossierDWReport;
26 import org.turro.dossier.entity.*;
27 import org.turro.elephant.context.Application;
28 import org.turro.elephant.util.Messages;
29 import org.turro.i18n.I_;
30 import org.turro.log.SystemLogType;
31 import org.turro.log.SystemLogger;
32 import org.turro.zkoss.dialog.SelectionDialog;
33 import org.turro.zkoss.label.LabelExtended;
34 import org.turro.zkoss.label.LabelTypes;
35 import org.turro.zul.frame.Framework;
36 import org.zkoss.zk.ui.Component;
37 import org.zkoss.zk.ui.event.Event;
38 import org.zkoss.zk.ui.event.EventListener;
39 import org.zkoss.zk.ui.event.Events;
40 import org.zkoss.zul.*;
41 
46 public class DossierRow extends Row {
47 
48  @Override
49  public void setValue(Object value) {
50  super.setValue(value);
51 
52  //addDetail();
53 
54  final Dossier dossier = (Dossier) getValue();
55 
56  Label label = new Label(dossier.getId() + "");
57  appendChild(label);
58 
59  Vlayout vbox = new Vlayout();
60  appendChild(vbox);
61 
62  Hlayout hbox = new Hlayout();
63  vbox.appendChild(hbox);
64  hbox.appendChild(new DossierLabel(dossier, false));
65 
66  Set<DossierVersion> dvs = dossier.getActiveVersions();
67  if(!dvs.isEmpty()) {
68  hbox.appendChild(LabelTypes.getTinyLabel(" ["));
69  for(DossierVersion dv : dvs) {
70  if(dv.isActive()) {
71  hbox.appendChild(createLabel(dv));
72  }
73  }
74  hbox.appendChild(LabelTypes.getTinyLabel("]"));
75  }
76 
77  Participant subject = dossier.getSubject();
78  if(subject != null) {
79  ContactInfo ci = new ContactInfo(subject.getIdContact());
80  ci.setSclass("softLabel");
81  vbox.appendChild(ci);
82  }
83 
84  LabelExtended lext = new LabelExtended();
85  lext.setStyle("color:gray;font-size:11px");
86  lext.setValue(dossier.getExtraDescription());
87  lext.setMaxChars(70);
88  lext.setShowTooltip(true);
89  vbox.appendChild(lext);
90 
91  vbox = new Vlayout();
92  appendChild(vbox);
93 
94  lext = new LabelExtended();
95  lext.setDate(dossier.getCreation());
96  vbox.appendChild(lext);
97 
98  hbox = new Hlayout();
99  vbox.appendChild(hbox);
100 
101  lext = new LabelExtended();
102  lext.setStyle("color:gray;font-size:11px;");
103  lext.setDate(new DossierWrapper(dossier).getIssueLastModification());
104  hbox.appendChild(lext);
105 
106  hbox.appendChild(new Image("/_zul/images/activity.png"));
107 
108  vbox.appendChild(hbox);
109 
110  vbox = new Vlayout();
111  appendChild(vbox);
112 
113  lext = new LabelExtended();
114  lext.setResourceValue(dossier.getStatus().toString());
115  vbox.appendChild(lext);
116 
117  DossierDWReport dr = new DossierDWReport();
118  dr.setReportValues(null, null, dossier.getId());
119 
120  label = new Label(((long) dr.getOnWork()) + " " +
121  I_.get("Of") + " " + ((long) dr.getIssueCount()) + " " +
122  I_.get("Work in progress"));
123  label.setStyle("color:gray;font-size:11px;");
124  vbox.appendChild(label);
125 
126  label = new Label(dr.getEfectivity() + "%" + " " +
127  I_.get("Efectivity"));
128  label.setStyle("color:gray;font-size:11px;");
129  vbox.appendChild(label);
130 
131  vbox = new Vlayout();
132  appendChild(vbox);
133 
134  if(Application.getApplication().isInRole("dossier:attach")) {
135  A a = new A(I_.get("Attachments"), "/_zul/images/clip.png");
136  a.addEventListener(Events.ON_CLICK, new EventListener() {
137  @Override
138  public void onEvent(Event event) throws Exception {
139 // DossierAttachTree dat = new DossierAttachTree();
140 // dat.setVertical(true);
141 // dat.setDossier(dossier);
142 // SelectionDialog.showComponent(getPage(), I_.get("Attachments"),
143 // dat, "900px", "500px");
145  ac.setEntity(dossier);
146  ac.setPublicOnly(!(new DossierWrapper(dossier).getCanShowAllAttachments()));
147  SelectionDialog.showComponent(getPage(), I_.get("Attachments"),
148  ac, "80%", "80%", null);
149  }
150  });
151  vbox.appendChild(a);
152  }
153 
154  DossierData dd = dr.getData();
155  if(dd.isExpenses()) {
156  label = new Label(I_.get("Expenses"));
157  label.setStyle("color:navy;font-size:11px");
158  vbox.appendChild(label);
159  label = new Label(dd.getExpensesString());
160  label.setStyle("color:#666;font-size:11px");
161  vbox.appendChild(label);
162  }
163  if(dd.isHours()) {
164  label = new Label(I_.get("Hours"));
165  label.setStyle("color:navy;font-size:11px");
166  vbox.appendChild(label);
167  label = new Label(dd.getHoursString());
168  label.setStyle("color:#666;font-size:11px");
169  vbox.appendChild(label);
170  }
171  if(dd.isPrice()) {
172  label = new Label(I_.get("Price"));
173  label.setStyle("color:navy;font-size:11px");
174  vbox.appendChild(label);
175  label = new Label(dd.getPriceString());
176  label.setStyle("color:#666;font-size:11px");
177  vbox.appendChild(label);
178  }
179 
180  if(Application.getApplication().isInRole("dossier:delete")) {
181  Image img = new Image("/_zul/images/edit-delete.png");
182  img.setStyle("cursor:pointer");
183  img.addEventListener(Events.ON_CLICK, new EventListener() {
184  @Override
185  public void onEvent(Event event) throws Exception {
186  Messages.confirmDeletion().show(() -> {
187  SystemLogger.getInstance().doLog(SystemLogType.LOG_INFO, dossier, "deleted",
188  dossier.getFullDescription());
189  new DossierWrapper(dossier).delete();
190  Framework.getCurrent().invalidateSelected();
191  });
192  }
193  });
194  appendChild(img);
195  }
196 
197  }
198 
199  private void addDetail() {
200  final Detail detail = new Detail();
201  appendChild(detail);
202 
203  detail.addEventListener(Events.ON_OPEN, new EventListener() {
204  @Override
205  public void onEvent(Event event) throws Exception {
206  fillDetail(detail);
207  }
208  });
209  }
210 
211  private void fillDetail(Detail detail) {
212  if(detail.getChildren().isEmpty()) {
213  Dossier dossier = (Dossier) getValue();
214 
215  Grid grid = new Grid();
216  detail.appendChild(grid);
217 
218  Rows rows = new Rows();
219  grid.appendChild(rows);
220 
221  Row row;
222 
223  for(FieldValue fv : dossier.getFieldValues()) {
224  row = new Row();
225  rows.appendChild(row);
226  row.appendChild(new Label(fv.getFieldDef().getLabelKey()));
227  row.appendChild(new Label(fv.getValue()));
228  }
229  }
230  }
231 
232  private Component createLabel(DossierVersion dv) {
233  Label l = LabelTypes.getTinyLabel(dv.getVersionId());
234  DossierVersionStatus dvs = dv.getStatus();
235  if(dvs.equals(DossierVersionStatus.VERSION_READY)) {
236  l.setStyle("color:green");
237  } else if(dvs.equals(DossierVersionStatus.VERSION_STOPPED)) {
238  l.setStyle("color:red");
239  } else if(dvs.equals(DossierVersionStatus.VERSION_NOTRECOMMENDED)) {
240  l.setStyle("color:blue");
241  }
242  return l;
243  }
244 
245 }
246 
Set< DossierVersion > getActiveVersions()
Definition: Dossier.java:269
Set< FieldValue > getFieldValues()
Definition: Dossier.java:151
static Messages confirmDeletion()
Definition: Messages.java:87
static String get(String msg)
Definition: I_.java:41
static ISystemLogger getInstance()
static void showComponent(Page page, String title, Component component, String width, String height, final Command command)
LabelExtended setDate(Date date)
LabelExtended setShowTooltip(boolean showTooltip)
LabelExtended setResourceValue(String resourceValue)
LabelExtended setMaxChars(int maxChars)
static Label getTinyLabel(String value)
Definition: LabelTypes.java:34
static Framework getCurrent()
Definition: Framework.java:203