19 package org.turro.dossier.zul.worksheet;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Iterator;
24 import java.util.List;
25 import java.util.Objects;
26 import org.turro.dossier.db.DossierPU;
27 import org.turro.dossier.dossier.DossierData;
28 import org.turro.dossier.entity.Issue;
29 import org.turro.dossier.entity.Worksheet;
30 import org.turro.dossier.issue.IssueWrapper;
31 import org.turro.dossier.search.IssueResults;
32 import org.turro.dossier.util.WorksheetUtil;
33 import org.turro.dossier.zul.menu.DossierMenu;
34 import org.turro.elephant.context.Application;
35 import org.turro.i18n.I_;
36 import org.turro.plugin.contacts.IContact;
37 import org.turro.zkoss.grid.PagingGrid;
38 import org.turro.zkoss.label.LabelExtended;
39 import org.zkoss.lang.Strings;
40 import org.zkoss.zk.ui.event.DropEvent;
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.Hlayout;
47 import org.zkoss.zul.Image;
48 import org.zkoss.zul.Label;
49 import org.zkoss.zul.ListModelList;
50 import org.zkoss.zul.Row;
51 import org.zkoss.zul.RowRenderer;
52 import org.zkoss.zul.Vlayout;
60 private boolean needSave;
62 private ListModelList<Worksheet> worksheetModel;
74 this.needSave = needSave;
78 return worksheetModel;
92 if(iw.getRelevanceOrderByContact() == 1) {
104 addRows(
new ArrayList<Worksheet>());
123 ArrayList<IssueWrapper> list =
new ArrayList<>();
129 if(iw.getRelevanceOrderByContact() == 1) {
130 boolean exists =
false;
132 if(Objects.equals(worksheet.getIssue().getId(), iw.getIssue().getId())) {
146 private void addColumns() {
147 Columns cols =
new Columns();
148 cols.setSizable(
true);
149 cols.setMenupopup(
"auto");
152 Column col =
new Column(
"#");
153 col.setWidth(
"80px");
154 cols.appendChild(col);
155 col =
new Column(
I_.
get(
"Description"));
157 cols.appendChild(col);
158 col =
new Column(
I_.
get(
"Reporter"));
160 cols.appendChild(col);
161 if(app.
isInRole(
"worksheet:delete")) {
163 col.setWidth(
"30px");
164 cols.appendChild(col);
168 private void addRows(List<Worksheet> workSheets) {
169 setRowRenderer(
new RowRenderer<Worksheet>() {
171 public void render(Row row, Worksheet workSheet,
int index) {
172 fillRow(row, workSheet);
175 worksheetModel =
new ListModelList<>(workSheets);
176 setModel(worksheetModel);
180 private void fillRow(
final Row row,
final Worksheet worksheet) {
181 row.setDraggable(
"row");
182 row.setDroppable(
"row");
183 final Issue issue = worksheet.getIssue();
184 final IssueWrapper iw =
new IssueWrapper(issue);
185 DossierData dd = iw.getData();
186 row.appendChild(
new Label(issue.getId() +
""));
187 Vlayout vbox =
new Vlayout();
188 row.appendChild(vbox);
189 LabelExtended lext =
new LabelExtended();
190 lext.setSclass(
"issue");
191 lext.setMultiline(
true);
192 lext.setValue(Strings.isEmpty(issue.getDescription()) ?
193 I_.get(
"No description!") : issue.getDescription());
195 lext.setStyle(
"cursor:pointer");
196 lext.addEventListener(Events.ON_CLICK,
new EventListener() {
198 public void onEvent(Event event)
throws Exception {
199 DossierMenu.showIssue(issue.getId());
203 vbox.appendChild(lext);
204 vbox.appendChild(
new Label(issue.getDossier().getFullDescription()));
205 if(dd.isExpenses()) {
206 Hlayout hbox =
new Hlayout();
207 Label label =
new Label(I_.get(
"Expenses"));
208 label.setStyle(
"color:navy;font-size:11px");
209 hbox.appendChild(label);
210 label =
new Label(dd.getExpensesString());
211 label.setStyle(
"color:#666;font-size:11px");
212 hbox.appendChild(label);
213 vbox.appendChild(hbox);
216 Hlayout hbox =
new Hlayout();
217 Label label =
new Label(I_.get(
"Hours"));
218 label.setStyle(
"color:navy;font-size:11px");
219 hbox.appendChild(label);
220 label =
new Label(dd.getHoursString());
221 label.setStyle(
"color:#666;font-size:11px");
222 hbox.appendChild(label);
223 vbox.appendChild(hbox);
226 Hlayout hbox =
new Hlayout();
227 Label label =
new Label(I_.get(
"Price"));
228 label.setStyle(
"color:navy;font-size:11px");
229 hbox.appendChild(label);
230 label =
new Label(dd.getPriceString());
231 label.setStyle(
"color:#666;font-size:11px");
232 hbox.appendChild(label);
233 vbox.appendChild(hbox);
235 row.appendChild(
new Label(iw.getReporterString()));
236 if(app.
isInRole(
"worksheet:delete")) {
237 Image img =
new Image(
"/_zul/images/edit-delete.png");
238 img.setStyle(
"cursor:pointer");
239 img.addEventListener(Events.ON_CLICK,
new EventListener() {
241 public void onEvent(Event event)
throws Exception {
242 Worksheet ws = worksheetModel.get(row.getIndex());
243 worksheetModel.remove(row.getIndex());
244 if(ws.getId() !=
null && ws.getId() > 0) {
245 new DossierPU().deleteObject(ws);
249 row.appendChild(img);
254 row.addEventListener(Events.ON_DROP,
new EventListener<DropEvent>() {
256 public void onEvent(DropEvent event)
throws Exception {
257 Row dragged = (Row) event.getDragged();
258 Row dropped = (Row) event.getTarget();
259 Worksheet ws = worksheetModel.get(dragged.getIndex());
260 worksheetModel.remove(dragged.getIndex());
261 worksheetModel.add(dropped.getIndex(), ws);
264 Events.postEvent(
new Event(Events.ON_CHANGE,
WorksheetGrid.this));
269 private void updateOrderValues() {
270 Iterator<Worksheet> it = worksheetModel.iterator();
272 while(it.hasNext()) {
273 it.next().setSheetOrder(index++);
void setSheetOrder(int sheetOrder)
void setIdContact(String idContact)
void setIssue(Issue issue)
int getRelevanceOrderByContact()
void setDossierId(Long dossierId)
java.util.List< IssueWrapper > getIssueList()
void setByParticipant(IContact byParticipant)
static void clearDone(List< Worksheet > list, IContact contact)
static Collection< Worksheet > getWorksheet(String idContact)
void setValues(IContact contact)
ListModelList< Worksheet > getWorksheetModel()
void setNeedSave(boolean needSave)
void addValue(IContact contact, IssueWrapper iw)
Collection< IssueWrapper > getNotInGrid(IContact contact)
boolean isInRole(String role)
static Application getApplication()
static String get(String msg)
void setRowCount(int rows)