BrightSide Workbench Full Report + Source Code
DossierGantt.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.Objects;
22 import org.turro.dossier.entity.Dossier;
23 import org.turro.dossier.entity.Issue;
24 import org.turro.dossier.entity.IssuePredecessor;
25 import org.turro.dossier.entity.IssuePredecessorType;
26 import org.turro.zkoss.svg.Gantt;
27 import org.turro.zkoss.svg.GanttData;
28 import org.turro.zkoss.svg.GanttItem;
29 import org.turro.zkoss.svg.GanttPredecessor;
30 import org.zkoss.zk.ui.ext.AfterCompose;
31 
36 public class DossierGantt extends Gantt implements AfterCompose {
37 
38  private String selectItem;
39  private Dossier dossier;
40  private double scale = 1.0;
41  private boolean onlyPublishable = false;
42 
43  public DossierGantt() {
44  }
45 
46  public String getSelectItem() {
47  return selectItem;
48  }
49 
50  public void setSelectItem(String selectItem) {
51  this.selectItem = selectItem;
52  }
53 
54  public Dossier getDossier() {
55  return dossier;
56  }
57 
58  public void setDossier(Dossier dossier) {
59  this.dossier = dossier;
60  }
61 
62  public double getScale() {
63  return scale;
64  }
65 
66  public void setScale(double scale) {
67  this.scale = scale;
68  }
69 
70  public boolean isOnlyPublishable() {
71  return onlyPublishable;
72  }
73 
74  public void setOnlyPublishable(boolean onlyPublishable) {
75  this.onlyPublishable = onlyPublishable;
76  }
77 
78  public void reload() {
79  loadData();
80  repaint();
81  }
82 
83  @Override
84  public void afterCompose() {
85  loadData();
86  repaint();
87  }
88 
89  public void repaint() {
90  setVisible(false);
91  getChildren().clear();
92  clear();
93  if(dossier != null) {
94  startComposing(selectItem, null, null, scale);
95  generateContent(null);
96  setVisible(true);
97  }
98  }
99 
100  private void loadData() {
101  if(dossier != null) {
102  setData(getGanttData());
103  }
104  }
105 
106  private GanttData getGanttData() {
107  GanttData gd = new GanttData();
108  GanttItem dgi = gd.addGanttItem(dossier.getId(), null, dossier.getFullDescription(), 0, 0);
109  dgi.setMilestone(false);
110  dgi.setFinished(false);
111  for(Issue issue : dossier.getAllIssues(onlyPublishable)) {
112  addIssue(issue, gd);
113  }
114  for(Issue issue : dossier.getAllIssues(onlyPublishable)) {
115  solvePredecessors(issue, gd);
116  }
117  gd.initData();
118  return gd;
119  }
120 
121  private void addIssue(Issue issue, GanttData gd) {
122  if (onlyPublishable && !issue.isPublishable()) {
123  return;
124  }
125  GanttItem gi = gd.addGanttItem(issue.getDossier().getId(), "" + issue.getId(),
126  issue.getDescription(),
127  issue.getHours() == 0.0 ? 1.0 : issue.getHours(),
128  issue.getSumHours());
129  gi.setMilestone(issue.isMilestone());
130  gi.setFinished(issue.getStatus().isFinished());
131  }
132 
133  private void solvePredecessors(Issue issue, GanttData gd) {
134  for(IssuePredecessor predecessor : issue.getSources()) {
135  Issue source = predecessor.getSource();
136  boolean sameSpace = Objects.equals(source.getDossier().getId(), dossier.getId());
137  GanttPredecessor gp = new GanttPredecessor(
138  predecessor.getType().equals(IssuePredecessorType.START_WHEN_STARTS) ?
139  GanttPredecessor.GANTT_START_TO_START :
140  GanttPredecessor.GANTT_END_TO_START,
141  "" + source.getId(),
142  0, sameSpace);
143  if(!sameSpace) {
144  addIssue(source, gd);
145  }
146  gd.getItem("" + issue.getId()).getPredecessors().add(gp);
147  }
148  }
149 
150 }
Collection< Issue > getAllIssues()
Definition: Dossier.java:281
void setSelectItem(String selectItem)
void setOnlyPublishable(boolean onlyPublishable)
void setData(GanttData data)
Definition: Gantt.java:44
void startComposing(String onUserEvent, String width, String height, double scale)
Definition: Gantt.java:61
void generateContent(Map args)
Definition: Svg.java:73