BrightSide Workbench Full Report + Source Code
DossierActivityRow.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 org.turro.action.Contacts;
21 import org.turro.attach.db.AttachPU;
22 import org.turro.attach.entity.Attachment;
23 import org.turro.dossier.entity.IssueComment;
24 import org.turro.elephant.util.DateFormats;
25 import org.turro.i18n.I_;
26 import org.turro.jpa.DaoTransaction;
27 import org.turro.plugin.contacts.IContact;
28 import org.turro.zkoss.label.LabelExtended;
29 import org.zkoss.zk.ui.event.Event;
30 import org.zkoss.zk.ui.event.EventListener;
31 import org.zkoss.zk.ui.event.Events;
32 import org.zkoss.zul.Filedownload;
33 import org.zkoss.zul.Hbox;
34 import org.zkoss.zul.Label;
35 import org.zkoss.zul.Row;
36 import org.zkoss.zul.Vbox;
37 
42 public class DossierActivityRow extends Row {
43 
44  @Override
45  public void setValue(Object value) {
46  super.setValue(value);
47 
48  setValign("top");
49 
50  if(value instanceof IssueComment) {
51  final IssueComment ic = (IssueComment) value;
52 
53  Vbox vbox = new Vbox();
54  appendChild(vbox);
55 
56  Label label = new Label(ic.getParticipantName());
57  label.setSclass("participant");
58  vbox.appendChild(label);
59 
60  label = new Label(DateFormats.format(ic.getModification(), false));
61  label.setSclass("modification");
62  vbox.appendChild(label);
63 
64  vbox = new Vbox();
65  appendChild(vbox);
66 
67  LabelExtended lext = new LabelExtended();
68  lext.setSclass("comment");
69  lext.setWordWrap(80);
70  lext.setPre(true);
71  lext.setValue(ic.getComment());
72  vbox.appendChild(lext);
73 
74  Hbox hbox = new Hbox();
75  hbox.setSclass("values");
76  boolean hasValues = false;
77 
78  if(ic.getExpenses() != 0) {
79  label = new Label(I_.get("Expenses"));
80  label.setSclass("caption");
81  hbox.appendChild(label);
82  label = new Label(ic.getExpenses() + "");
83  label.setSclass("value");
84  hbox.appendChild(label);
85  hasValues = true;
86  }
87 
88  if(ic.getHours() != 0) {
89  label = new Label(I_.get("Hours"));
90  label.setSclass("caption");
91  hbox.appendChild(label);
92  label = new Label(ic.getHours() + "");
93  label.setSclass("value");
94  hbox.appendChild(label);
95  hasValues = true;
96  }
97 
98  if(ic.getPrice() != 0) {
99  label = new Label(I_.get("Price"));
100  label.setSclass("caption");
101  hbox.appendChild(label);
102  label = new Label(ic.getPrice() + "");
103  label.setSclass("value");
104  hbox.appendChild(label);
105  hasValues = true;
106  }
107 
108  if(hasValues) {
109  vbox.appendChild(hbox);
110  }
111 
112  } else if(value instanceof Attachment) {
113  final Attachment attachment = (Attachment) value;
114 
115  Vbox vbox = new Vbox();
116  appendChild(vbox);
117 
118  IContact contact = Contacts.getEmpty();
119  contact.loadByLogin(attachment.getOwner());
120 
121  Label label = new Label(contact != null ? contact.getName() : attachment.getOwner());
122  label.setSclass("participant");
123  vbox.appendChild(label);
124 
125  label = new Label(DateFormats.format(attachment.getModification(), false));
126  label.setSclass("modification");
127  vbox.appendChild(label);
128 
129  vbox = new Vbox();
130  appendChild(vbox);
131 
132  label = new Label(attachment.getFileName());
133  label.setSclass("attachment");
134  label.setStyle("cursor:pointer");
135  label.addEventListener(Events.ON_CLICK, new EventListener() {
136 
137  @Override
138  public void onEvent(Event event) throws Exception {
139  doDownload(attachment);
140  }
141  });
142  vbox.appendChild(label);
143 
144  LabelExtended lext = new LabelExtended();
145  lext.setWordWrap(80);
146  lext.setPre(true);
147  lext.setValue(attachment.getComment());
148  vbox.appendChild(lext);
149 
150  }
151  }
152 
153  private void doDownload(Attachment attachment) {
154  try(DaoTransaction transaction = new DaoTransaction(new AttachPU())) {
155  attachment = transaction.saveObject(attachment);
156  Filedownload.save(attachment.getAttachContent().getFileContent(), attachment.getFileContentType(), attachment.getFileName());
157  }
158  }
159 
160 }
static IContact getEmpty()
Definition: Contacts.java:56
static final String format(Date d, boolean dateOnly)
static String get(String msg)
Definition: I_.java:41
LabelExtended setWordWrap(int wordWrap)
Object loadByLogin(String login)