BrightSide Workbench Full Report + Source Code
viewer/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.viewer;
19 
20 import org.turro.attach.search.AttachResults;
21 import org.turro.dossier.db.DossierPU;
22 import org.turro.dossier.dossier.DossierWrapper;
23 import org.turro.dossier.entity.Dossier;
24 import org.turro.dossier.entity.FieldValue;
25 import org.turro.elephant.context.Application;
26 import org.turro.i18n.I_;
27 import org.turro.zkoss.label.LabelExtended;
28 import org.turro.zkoss.layout.GridLayout;
29 import org.zkoss.lang.Strings;
30 import org.zkoss.zk.ui.event.Event;
31 import org.zkoss.zk.ui.event.EventListener;
32 import org.zkoss.zk.ui.event.Events;
33 import org.zkoss.zul.Detail;
34 import org.zkoss.zul.Div;
35 import org.zkoss.zul.Hbox;
36 import org.zkoss.zul.Label;
37 import org.zkoss.zul.Row;
38 import org.zkoss.zul.Vbox;
39 
44 public class DossierRow extends Row {
45 
46  private String issueColumns;
47  private Detail detail;
48 
49  public void setIssueColumns(String issueColumns) {
50  this.issueColumns = issueColumns;
51  }
52 
53  @Override
54  public void setValue(Object value) {
55  super.setValue(value);
56 
57  addDetail();
58 
59  final Dossier dossier = (Dossier) getValue();
60  DossierGrid grid = (DossierGrid) getGrid();
61 
62  Vbox vbox = new Vbox();
63  appendChild(vbox);
64 
65  LabelExtended lext = new LabelExtended();
66  lext.setStyle("font-weight:bold;");
67  lext.setValue(Strings.isEmpty(dossier.getDescription()) ?
68  I_.get("No description!") : dossier.getDescription());
69  lext.setMultiline(true);
70  if(Application.getApplication().isInRole("dossier:show")) {
71  lext.setStyle(lext.getStyle() + "cursor:pointer");
72  lext.addEventListener(Events.ON_CLICK, new EventListener() {
73  @Override
74  public void onEvent(Event event) throws Exception {
75  if(detail != null) {
76  fillDetail();
77  detail.setOpen(!detail.isOpen());
78  }
79  }
80  });
81  }
82  vbox.appendChild(lext);
83 
84  Hbox hbox = new Hbox();
85  hbox.setStyle("");
86  vbox.appendChild(hbox);
87 
88  lext = new LabelExtended();
89  lext.setStyle("color:gray;font-size:11px;");
90  lext.setValue(dossier.getFullDescription());
91  hbox.appendChild(lext);
92 
93  lext = new LabelExtended();
94  lext.setStyle("color:maroon;font-size:11px;");
95  lext.setResourceValue(dossier.getStatus().name());
96  hbox.appendChild(lext);
97 
98  lext = new LabelExtended();
99  lext.setStyle("color:gray;font-size:11px;");
100  lext.setValue(dossier.getPublishableDescription());
101  lext.setMaxChars(70);
102  lext.setShowTooltip(true);
103  vbox.appendChild(lext);
104 
105  }
106 
107  private void addDetail() {
108  detail = new Detail();
109  appendChild(detail);
110 
111  detail.addEventListener(Events.ON_OPEN, new EventListener() {
112  @Override
113  public void onEvent(Event event) throws Exception {
114  fillDetail();
115  }
116  });
117  }
118 
119  private void fillDetail() {
120  if(!detail.getChildren().isEmpty()) return;
121  final Dossier dossier = (Dossier) getValue();
122  DossierGrid grid = (DossierGrid) getGrid();
123  if (!grid.isShowAttachments() && !grid.isShowFields() && !grid.isShowIssues()) {
124  return;
125  }
126  Div vdetail = new Div();
127  vdetail.setStyle("padding:5px");
128  detail.appendChild(vdetail);
129  Div div;
130  if (grid.isShowFields() && !dossier.getFieldValues().isEmpty()) {
131  GridLayout gl = new GridLayout("min,1");
132  for(FieldValue fv : dossier.getFieldValues()) {
133  if(!Strings.isBlank(fv.getValue()) && fv.getFieldDef().isPublishable()) {
134  gl.addCaption(fv.getFieldDef().getLabelKey());
135  gl.addComponent(new Label(fv.getObjectString()));
136  }
137  }
138  if(!(gl.getChildren().isEmpty())) {
139  vdetail.appendChild(gl);
140  }
141  }
142  if (grid.isShowIssues() && new DossierWrapper(dossier).getIssueCount() > 0) {
143  div = new Div();
144  div.setStyle("margin-top:10px");
145  vdetail.appendChild(div);
146  IssueGrid issueGrid = new IssueGrid();
147  issueGrid.setIssueColumns(issueColumns);
148  issueGrid.setDossier(dossier);
149  div.appendChild(issueGrid);
150  }
151  if (grid.isShowAttachments() && AttachResults.getCountAttachments(DossierPU.getObjectPath(dossier)) > 0) {
152  div = new Div();
153  div.setStyle("margin-top:10px");
154  vdetail.appendChild(div);
155  DossierAttachTree attach = new DossierAttachTree();
156  div.appendChild(attach);
157  attach.setDossier(dossier);
158  attach.afterCompose();
159  }
160  }
161 
162 }
163 
static String get(String msg)
Definition: I_.java:41
LabelExtended setShowTooltip(boolean showTooltip)
LabelExtended setResourceValue(String resourceValue)
LabelExtended setMaxChars(int maxChars)