18 package org.turro.dossier.zul.viewer;
20 import java.util.List;
22 import org.amic.util.string.Strings;
23 import org.turro.contacts.util.ContactCombobox;
24 import org.turro.dossier.db.DossierPU;
25 import org.turro.dossier.entity.Category;
26 import org.turro.dossier.entity.Dossier;
27 import org.turro.dossier.entity.ParticipantRole;
28 import org.turro.elephant.context.Application;
29 import org.turro.i18n.I_;
30 import org.turro.plugin.contacts.IContact;
31 import org.turro.zkoss.grid.GroupExtended;
32 import org.turro.zkoss.grid.PagingGrid;
33 import org.turro.zkoss.layout.HSeparator;
34 import org.zkoss.zk.ui.event.Event;
35 import org.zkoss.zk.ui.event.EventListener;
36 import org.zkoss.zk.ui.event.Events;
37 import org.zkoss.zk.ui.ext.AfterCompose;
38 import org.zkoss.zul.Checkbox;
39 import org.zkoss.zul.Column;
40 import org.zkoss.zul.Columns;
41 import org.zkoss.zul.Group;
42 import org.zkoss.zul.Hbox;
43 import org.zkoss.zul.Label;
44 import org.zkoss.zul.Listbox;
45 import org.zkoss.zul.Listitem;
46 import org.zkoss.zul.Row;
47 import org.zkoss.zul.Rows;
48 import org.zkoss.zul.Textbox;
49 import org.zkoss.zul.Toolbar;
50 import org.zkoss.zul.Toolbarbutton;
51 import org.zkoss.zul.Vbox;
60 private Toolbar toolbar;
61 private Toolbarbutton searchButton;
63 private String searchValue =
"", issueColumns;
64 private boolean onlyActive =
true, searchBar =
true;
66 private String fixedViewpoint;
67 private long fixedCategoryId = -1;
68 private boolean showFields =
true, showIssues =
true, showAttachments =
true, divToolbar =
false;
77 this.fixedCategoryId = fixedCategoryId;
78 if(fixedCategoryId == 0) {
80 }
else if(fixedCategoryId > 0) {
86 this.fixedContact = fixedContact;
91 this.fixedViewpoint = fixedViewpoint;
92 if(!Strings.isBlank(fixedViewpoint)) {
98 this.divToolbar = divToolbar;
102 return showAttachments;
106 this.showAttachments = showAttachments;
114 this.showFields = showFields;
122 this.showIssues = showIssues;
126 this.searchValue = searchValue;
134 this.issueColumns = issueColumns;
138 this.searchBar = searchBar;
145 private void addColumns() {
146 Columns cols =
new Columns();
147 cols.setVisible(
false);
151 Column col =
new Column(
I_.
get(
"Dossiers"));
152 cols.appendChild(col);
155 private void addRows(Map<IContact, List<Dossier>> dossiers) {
158 for(List l : dossiers.values()) {
163 if(rows !=
null) removeChild(rows);
168 if(dossiers.keySet().isEmpty()) {
170 row.appendChild(
new Label(
""));
171 row.appendChild(
new Label(I_.get(
"Empty list")));
172 rows.appendChild(row);
174 for(
final IContact subject : dossiers.keySet()) {
175 createGroup(subject);
176 for(
final Dossier dossier : dossiers.get(subject)) {
177 DossierRow row =
new DossierRow();
178 rows.appendChild(row);
179 row.setIssueColumns(issueColumns);
180 row.setValue(dossier);
188 private void createGroup(IContact subject) {
189 String label = subject.getName();
190 Group group =
new GroupExtended(label);
191 rows.appendChild(group);
194 private void addSearchBar() {
196 if(toolbar !=
null) getParent().removeChild(toolbar);
198 if(!searchBar)
return;
200 toolbar =
new Toolbar();
201 getParent().insertBefore(toolbar,
this);
202 toolbar.setStyle(
"font-size:11px");
204 Vbox toolbox =
new Vbox();
205 toolbar.appendChild(toolbox);
207 Hbox firstRow =
new Hbox();
208 firstRow.setSpacing(
"10px");
209 toolbox.appendChild(firstRow);
211 Hbox secondRow =
new Hbox();
213 secondRow.setSpacing(
"10px");
214 toolbox.appendChild(secondRow);
219 final ContactCombobox contactCombo =
new ContactCombobox();
220 final CategoryListbox categoryListbox =
new CategoryListbox();
223 if(Strings.isBlank(fixedViewpoint)) {
225 firstRow.appendChild(vbox);
227 vbox.appendChild(
new Label(I_.get(
"Viewpoint")));
229 final Listbox role =
new Listbox();
230 role.setStyle(
"font-size:11px");
231 role.setMold(
"select");
232 role.addEventListener(Events.ON_SELECT,
new EventListener() {
234 public void onEvent(Event event)
throws Exception {
235 viewpoint.
setViewpoint((ParticipantRole) role.getSelectedItem().getValue());
236 if(contactCombo !=
null) {
237 contactCombo.setRole(contactComboRole());
238 categoryListbox.setViewpoint(viewpoint);
242 vbox.appendChild(role);
244 for(ParticipantRole pr : ParticipantRole.values()) {
245 Listitem li =
new Listitem(I_.byKey(pr.toString()));
247 li.setSelected(li.getValue().equals(viewpoint.
getViewpoint()));
248 role.appendChild(li);
252 if(fixedCategoryId == -1) {
254 firstRow.appendChild(vbox);
256 vbox.appendChild(
new Label(I_.get(
"Category")));
258 categoryListbox.setStyle(
"font-size:11px");
259 categoryListbox.setMold(
"select");
260 categoryListbox.setViewpoint(viewpoint);
261 categoryListbox.addEventListener(Events.ON_SELECT,
new EventListener() {
263 public void onEvent(Event event)
throws Exception {
264 viewpoint.
setCategory(categoryListbox.getCategory());
267 vbox.appendChild(categoryListbox);
270 if(checkContactCombo()) {
273 secondRow.appendChild(vbox);
275 firstRow.appendChild(vbox);
278 vbox.appendChild(
new Label(I_.get(
"Contact")));
280 contactCombo.setStyle(
"font-size:11px");
281 contactCombo.setCols(30);
282 contactCombo.setIContact(viewpoint.
getContact());
283 contactCombo.setRole(contactComboRole());
284 contactCombo.addEventListener(Events.ON_CHANGE,
new EventListener() {
286 public void onEvent(Event event)
throws Exception {
287 viewpoint.
setContact(contactCombo.getIContact());
288 categoryListbox.setViewpoint(viewpoint);
291 vbox.appendChild(contactCombo);
295 firstRow.appendChild(vbox);
297 vbox.appendChild(
new Label(I_.get(
"Text")));
299 final Textbox searchValueInput =
new Textbox(searchValue);
300 searchValueInput.setStyle(
"font-size:11px");
301 searchValueInput.setCols(15);
302 searchValueInput.addEventListener(Events.ON_CHANGE,
new EventListener() {
304 public void onEvent(Event event)
throws Exception {
305 searchValue = searchValueInput.getText();
309 searchValueInput.addEventListener(Events.ON_OK,
new EventListener() {
311 public void onEvent(Event event)
throws Exception {
312 searchValue = searchValueInput.getText();
316 vbox.appendChild(searchValueInput);
319 firstRow.appendChild(vbox);
321 vbox.appendChild(
new HSeparator(
"16px"));
323 searchButton =
new Toolbarbutton(
325 "/_zul/images/search.png"
327 searchButton.addEventListener(Events.ON_CLICK,
new EventListener() {
329 public void onEvent(Event event)
throws Exception {
333 vbox.appendChild(searchButton);
336 if(divToolbar && checkContactCombo()) {
337 secondRow.appendChild(vbox);
339 firstRow.appendChild(vbox);
342 vbox.appendChild(
new HSeparator(
"16px"));
344 final Checkbox onlyActiveCheck =
new Checkbox(I_.get(
"Only active"));
345 onlyActiveCheck.setChecked(onlyActive);
346 onlyActiveCheck.setStyle(
"font-size:11px");
347 onlyActiveCheck.addEventListener(Events.ON_CHECK,
new EventListener() {
349 public void onEvent(Event event)
throws Exception {
350 onlyActive = onlyActiveCheck.isChecked();
353 vbox.appendChild(onlyActiveCheck);
358 private boolean checkContactCombo() {
359 return fixedContact ==
null &&
360 (viewpoint.
getViewpoint().equals(ParticipantRole.PARTICIPANT_SUBJECT) &&
361 Application.getApplication().isInRole(
"my-orders:subject")) ||
362 ((viewpoint.
getViewpoint().equals(ParticipantRole.PARTICIPANT_ASSISTANT) ||
363 viewpoint.
getViewpoint().equals(ParticipantRole.PARTICIPANT_OWNER)) &&
364 Application.getApplication().isInRole(
"dossier:all"));
367 private String contactComboRole() {
368 if(viewpoint.
getViewpoint().equals(ParticipantRole.PARTICIPANT_SUBJECT)) {
370 }
else if(viewpoint.
getViewpoint().equals(ParticipantRole.PARTICIPANT_ASSISTANT) ||
371 viewpoint.
getViewpoint().equals(ParticipantRole.PARTICIPANT_OWNER)) {
372 return "dossier:list";
377 private void searchDossiers() {
void setSearchBar(boolean searchBar)
DossierViewpoint getViewpoint()
void setFixedCategoryId(long fixedCategoryId)
void setIssueColumns(String issueColumns)
boolean isShowAttachments()
void setContact(IContact contact)
void setFixedViewpoint(String fixedViewpoint)
void setShowFields(boolean showFields)
void setDivToolbar(boolean divToolbar)
void setSearchValue(String searchValue)
void setShowIssues(boolean showIssues)
void setFixedContact(IContact fixedContact)
void setShowAttachments(boolean showAttachments)
void setCategory(Category category)
Map< IContact, List< Dossier > > getDossiersMap(String searchValue, boolean onlyActive)
ParticipantRole getViewpoint()
void setViewpoint(ParticipantRole viewpoint)
void setContact(IContact contact)
static String get(String msg)
void setRowCount(int rows)