BrightSide Workbench Full Report + Source Code
WorkloadVM.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2015 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.workload;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.Set;
24 import org.turro.dossier.entity.Category;
25 import org.turro.dossier.entity.Dossier;
26 import org.turro.dossier.entity.Issue;
27 import org.turro.dossier.entity.IssueStatus;
28 import org.turro.dossier.entity.IssueType;
29 import org.turro.dossier.issue.IssueWrapper;
30 import org.turro.dossier.util.DossiersInfo;
31 import org.turro.dossier.zul.attach.IssueAttachTree;
32 import org.turro.dossier.zul.issue.IssueStage;
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.registry.Changes;
38 import org.turro.zkoss.dialog.SelectionDialog;
39 import org.turro.zul.frame.Framework;
40 import org.zkoss.bind.annotation.BindingParam;
41 import org.zkoss.bind.annotation.Command;
42 import org.zkoss.bind.annotation.NotifyChange;
43 import org.zkoss.zul.GroupsModel;
44 import org.zkoss.zul.SimpleGroupsModel;
45 
50 public class WorkloadVM {
51 
52  private final WorkloadQuery query;
53 
54  public WorkloadVM() {
55  query = new WorkloadQuery();
56  }
57 
58  @Command
59  public void showInfo(@BindingParam("item") WorkloadItem item) {
61  IssueWrapper iw = new IssueWrapper(item.getIssue());
62  if(app.isInRole("issue:show") &&
63  (app.isInRole("issue:all") || iw.isFullParticipant())) {
64  DossiersInfo.popup(item.getIssue());
65  }
66  }
67 
68  @NotifyChange("model")
69  @Command("update")
70  public void update() {}
71 
72  @NotifyChange("model")
73  @Command
74  public void selectEntity(@BindingParam("entity") Object entity) {
75  if(entity instanceof Category) {
76  setSelectedCategory((Category) entity);
77  setSelectedDossier(null);
78  } else if(entity instanceof Dossier) {
79  setSelectedDossier((Dossier) entity);
80  setSelectedCategory(null);
81  } else {
82  setSelectedCategory(null);
83  setSelectedDossier(null);
84  }
85  }
86 
87  @NotifyChange("model")
88  @Command
89  public void selectContact(@BindingParam("contact") IContact contact) {
90  setParticipant(contact);
91  }
92 
93  @Command
94  public void showAttachments(@BindingParam("issue") Issue issue) {
96  IssueWrapper iw = new IssueWrapper(issue);
97  if(app.isInRole("issue:show") &&
98  (app.isInRole("issue:all") || iw.isFullParticipant())) {
99  IssueAttachTree iat = new IssueAttachTree();
100  iat.setEntity(issue);
101  iat.setChanges(new Changes());
102  SelectionDialog.showComponent(Framework.getCurrent().getPage(), I_.get("Attachments"),
103  iat, "80%", "80%", null);
104  }
105  }
106 
107  @Command
108  public void addInformation(@BindingParam("issue") Issue issue) {
109  DossierMenu.addInformation(issue, null);
110  }
111 
112  public void setSearchValue(String searchValue) {
113  query.setSearchValue(searchValue);
114  }
115 
116  public String getSearchValue() {
117  return query.getSearchValue();
118  }
119 
120  public void setSelectedCategory(Category category) {
121  query.setCategory(category);
122  }
123 
125  return query.getCategory();
126  }
127 
128  public void setSelectedDossier(Dossier dossier) {
129  query.setDossier(dossier);
130  }
131 
133  return query.getDossier();
134  }
135 
136  public void setParticipant(IContact contact) {
137  query.setByParticipant(contact);
138  }
139 
141  return query.getByParticipant();
142  }
143 
144  public Set<IssueStatus> getStatus() {
145  return query.getStatus();
146  }
147 
148  public void setStatus(Set<IssueStatus> status) {
149  query.setStatus(status);
150  }
151 
152  public Set<IssueType> getTypes() {
153  return query.getTypes();
154  }
155 
156  public void setTypes(Set<IssueType> types) {
157  query.setTypes(types);
158  }
159 
160  public GroupsModel<WorkloadItem, Object, Object> getModel() {
161  List<List<WorkloadItem>> data = new ArrayList<>();
162  List<String> headers = new ArrayList<>();
163  List<WorkloadItem> loading = null;
164 
165  IssueStage stage = null;
166 
167  WorkloadSet ws = query.getResults();
168 
169  for(final WorkloadItem item : ws) {
170  IssueStage current = WorkloadSet.getStage(item);
171  if(!(current.equals(stage))) {
172  stage = current;
173  headers.add(stage.toString());
174  loading = new ArrayList<>();
175  data.add(loading);
176  }
177  if(loading != null) {
178  loading.add(item);
179  }
180  }
181 
182  return new SimpleGroupsModel<>(data, headers);
183  }
184 
185 }
static void popup(Issue issue)
void setStatus(Set< IssueStatus > status)
void setTypes(Set< IssueType > types)
void setByParticipant(IContact byParticipant)
void addInformation(@BindingParam("issue") Issue issue)
void selectEntity(@BindingParam("entity") Object entity)
Definition: WorkloadVM.java:74
void selectContact(@BindingParam("contact") IContact contact)
Definition: WorkloadVM.java:89
void showInfo(@BindingParam("item") WorkloadItem item)
Definition: WorkloadVM.java:59
void setSelectedCategory(Category category)
void setSearchValue(String searchValue)
void setParticipant(IContact contact)
GroupsModel< WorkloadItem, Object, Object > getModel()
void setStatus(Set< IssueStatus > status)
void showAttachments(@BindingParam("issue") Issue issue)
Definition: WorkloadVM.java:94
void setTypes(Set< IssueType > types)
void setSelectedDossier(Dossier dossier)
static void addInformation(Issue issue, final 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