BrightSide Workbench Full Report + Source Code
MonitorVM.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2016 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 
19 package org.turro.dossier.monitor;
20 
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.List;
24 import java.util.Set;
25 import org.turro.attach.zul.control.AttachmentControl;
26 import org.turro.auth.Authentication;
27 import org.turro.dossier.db.DossierPU;
28 import org.turro.dossier.dossier.DossierWrapper;
29 import org.turro.dossier.entity.Category;
30 import org.turro.dossier.entity.Dossier;
31 import org.turro.dossier.entity.DossierStatus;
32 import org.turro.dossier.entity.DossierType;
33 import org.turro.dossier.search.DossierIds;
34 import org.turro.dossier.search.DossierResults;
35 import org.turro.dossier.util.DossiersInfo;
36 import org.turro.dossier.zul.menu.DossierMenu;
37 import org.turro.elephant.context.Application;
38 import org.turro.i18n.I_;
39 import org.turro.jpa.Dao;
40 import org.turro.plugin.contacts.IContact;
41 import org.turro.zkoss.dialog.SelectionDialog;
42 import org.turro.zul.frame.Framework;
43 import org.zkoss.bind.annotation.BindingParam;
44 import org.zkoss.bind.annotation.Command;
45 import org.zkoss.bind.annotation.NotifyChange;
46 import org.zkoss.zul.GroupsModel;
47 import org.zkoss.zul.SimpleGroupsModel;
48 
53 public class MonitorVM {
54 
55  private final DossierResults query;
56  private final boolean show, all;
57  private boolean waiting = true;
58 
59  public MonitorVM() {
60  query = new DossierResults();
62  query.setOrderBy("order by dossier.category.fullDescription");
64  show = app.isInRole("dossier:show");
65  all = app.isInRole("dossier:all");
66  }
67 
68  @Command
69  public void showInfo(@BindingParam("monitor") DossierMonitor monitor) {
70  if(show && (all || monitor.getWrapper().isParticipant())) {
71  DossiersInfo.popup(monitor.getDossier());
72  }
73  }
74 
75  @NotifyChange("model")
76  @Command("update")
77  public void update() {}
78 
79  @NotifyChange("model")
80  @Command
81  public void selectCategory(@BindingParam("category") Category category) {
82  if(category instanceof Category) {
83  setSelectedCategory((Category) category);
84  } else {
85  setSelectedCategory(null);
86  }
87  }
88 
89  @NotifyChange("model")
90  @Command
91  public void selectContact(@BindingParam("contact") IContact contact) {
92  setParticipant(contact);
93  }
94 
95  @NotifyChange("model")
96  @Command
97  public void selectFromAll(@BindingParam("checked") boolean checked) {
98  setCkOthers(checked);
99  }
100 
101  @Command
102  public void showAttachments(@BindingParam("wrapper") DossierWrapper wrapper) {
103  if(show && (all || wrapper.isParticipant())) {
105  ac.setEntity(wrapper.getEntity());
106  SelectionDialog.showComponent(Framework.getCurrent().getPage(), I_.get("Attachments"),
107  ac, "80%", "80%", null);
108  }
109  }
110 
111  @Command
112  public void addInformation(@BindingParam("dossier") Dossier dossier) {
113  DossierMenu.addDossierInformation(dossier, null);
114  }
115 
116  public void setSearchValue(String searchValue) {
117  query.setDossierValue(searchValue);
118  }
119 
120  public String getSearchValue() {
121  return query.getDossierValue();
122  }
123 
124  public void setSelectedCategory(Category category) {
125  query.setCategory(category);
126  }
127 
129  return query.getCategory();
130  }
131 
132  public void setParticipant(IContact contact) {
133  query.setByParticipant(contact);
134  }
135 
137  return query.getByParticipant();
138  }
139 
140  public Set<DossierStatus> getStatus() {
141  return query.getStatus();
142  }
143 
144  public void setStatus(Set<DossierStatus> status) {
145  query.setStatus(status);
146  }
147 
148  public Set<DossierType> getType() {
149  return query.getType();
150  }
151 
152  public void setType(Set<DossierType> type) {
153  query.setType(type);
154  }
155 
156  public boolean isCkOthers() {
157  return query.isCkOthers();
158  }
159 
160  public void setCkOthers(boolean ckOthers) {
161  query.setCkOthers(ckOthers);
162  }
163 
164  public GroupsModel<DossierMonitor, Object, Object> getModel() {
165  List<List<DossierMonitor>> data = new ArrayList<>();
166  List<String> headers = new ArrayList<>();
167  List<DossierMonitor> loading = null;
168 
169  Long catId = null;
170  Dao dao = new DossierPU();
171 
172  if(!waiting) {
173  Collection<DossierIds> dl = query.getDossierIdList();
174 
175  DossierIds.initDaoList(dao, dl);
176 
177  for(final DossierIds item : dl) {
178  Long current = item.categoryId;
179  if(catId == null || !(current.equals(catId))) {
180  catId = current;
181  headers.add(item.getCategory().getFullDescription());
182  loading = new ArrayList<>();
183  data.add(loading);
184  }
185  if(loading != null) {
186  loading.add(new DossierMonitor(dao, item.dossierId));
187  }
188  }
189  }
190 
191  waiting = false;
192 
193  return new SimpleGroupsModel<>(data, headers);
194  }
195 
196 }
GroupsModel< DossierMonitor, Object, Object > getModel()
Definition: MonitorVM.java:164
Set< DossierStatus > getStatus()
Definition: MonitorVM.java:140
void setStatus(Set< DossierStatus > status)
Definition: MonitorVM.java:144
void setSelectedCategory(Category category)
Definition: MonitorVM.java:124
void setParticipant(IContact contact)
Definition: MonitorVM.java:132
void selectContact(@BindingParam("contact") IContact contact)
Definition: MonitorVM.java:91
void showInfo(@BindingParam("monitor") DossierMonitor monitor)
Definition: MonitorVM.java:69
void setSearchValue(String searchValue)
Definition: MonitorVM.java:116
void showAttachments(@BindingParam("wrapper") DossierWrapper wrapper)
Definition: MonitorVM.java:102
void addInformation(@BindingParam("dossier") Dossier dossier)
Definition: MonitorVM.java:112
void selectCategory(@BindingParam("category") Category category)
Definition: MonitorVM.java:81
void setType(Set< DossierType > type)
Definition: MonitorVM.java:152
void selectFromAll(@BindingParam("checked") boolean checked)
Definition: MonitorVM.java:97
void setCkOthers(boolean ckOthers)
Definition: MonitorVM.java:160
static void initDaoList(Dao dao, Collection< DossierIds > list)
Definition: DossierIds.java:67
java.util.List< DossierIds > getDossierIdList()
void setType(Set< DossierType > type)
void setStatus(Set< DossierStatus > status)
void setDossierValue(String dossierValue)
void setByParticipant(IContact byParticipant)
static void popup(Issue issue)
static void addDossierInformation(Dossier dossier, Command command)
static String get(String msg)
Definition: I_.java:41
static void showComponent(Page page, String title, Component component, String width, String height, final Command command)
static Framework getCurrent()
Definition: Framework.java:203