BrightSide Workbench Full Report + Source Code
elephant-dossier/src/main/java/org/turro/dossier/gantt/WorkloadGantt.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2020 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.gantt;
20 
21 import java.util.Collection;
22 import java.util.HashMap;
23 import org.turro.dossier.entity.Dossier;
24 import org.turro.dossier.entity.Issue;
25 import org.turro.dossier.entity.IssueParticipant;
26 import org.turro.zkoss.svg.GanttResource;
27 import org.turro.zkoss.svg.GanttResourceData;
28 import org.turro.zkoss.svg.GanttResourceItem;
29 import org.zkoss.zk.ui.ext.AfterCompose;
30 
35 public class WorkloadGantt extends GanttResource implements AfterCompose {
36 
37  private String selectItem;
38  private double scale = 1.0;
39  private Dossier dossier;
40 
41  public WorkloadGantt() {
42  }
43 
44  public String getSelectItem() {
45  return selectItem;
46  }
47 
48  public void setSelectItem(String selectItem) {
49  this.selectItem = selectItem;
50  }
51 
52  public double getScale() {
53  return scale;
54  }
55 
56  public void setScale(double scale) {
57  this.scale = scale;
58  }
59 
60  public Dossier getDossier() {
61  return dossier;
62  }
63 
64  public void setDossier(Dossier dossier) {
65  this.dossier = dossier;
66  }
67 
68  public void reload() {
69  loadData();
70  repaint();
71  }
72 
73  @Override
74  public void afterCompose() {
75  loadData();
76  repaint();
77  }
78 
79  public void repaint() {
80  setVisible(false);
81  getChildren().clear();
82  clear();
83  if(dossier != null) {
84  startComposing(selectItem, null, null, scale);
85  generateContent(null);
86  setVisible(true);
87  }
88  }
89 
90  private void loadData() {
91  if(dossier != null) {
92  setData(fillModel());
93  }
94  }
95 
96  private GanttResourceData fillModel() {
97  HashMap<String, GanttResourceItem> map = new HashMap<>();
98 
99  for(Issue issue : dossier.getAllIssues()) {
100  for(IssueParticipant responsible : (Collection<IssueParticipant>) issue.getIssueParticipants().getResponsibles()) {
101  GanttResourceItem gri = map.get(responsible.getIdContact());
102  if(gri == null) {
103  gri = new GanttResourceItem(1, responsible.getIdContact(), responsible.getName());
104  map.put(responsible.getIdContact(), gri);
105  }
106  double hours = issue.getHours(),
107  sumHours = issue.getSumHours();
108  if(issue.getStatus().isFinished()) {
109  gri.setExpected(gri.getExpected() + (sumHours == 0.0 ? 1.0 : sumHours));
110  } else {
111  gri.setVariable(gri.getVariable() + (hours == 0.0 ? Math.max(sumHours, 1.0) : Math.max(sumHours, hours)));
112  }
113  }
114  }
115 
116  GanttResourceData grd = new GanttResourceData();
117  for(GanttResourceItem gri : map.values()) {
118  grd.add(gri);
119  gri.setSet(grd);
120  }
121  return grd;
122  }
123 
124 }
Collection< Issue > getAllIssues()
Definition: Dossier.java:281
void setData(GanttResourceData data)
void startComposing(String onUserEvent, String width, String height, double scale)
void generateContent(Map args)
Definition: Svg.java:73