BrightSide Workbench Full Report + Source Code
WorkOrderGantt.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.erp.workorder;
19 
20 import org.turro.erp.entity.*;
21 import org.turro.zkoss.svg.Gantt;
22 import org.turro.zkoss.svg.GanttData;
23 import org.turro.zkoss.svg.GanttItem;
24 import org.turro.zkoss.svg.GanttPredecessor;
25 import org.zkoss.zk.ui.ext.AfterCompose;
26 
31 public class WorkOrderGantt extends Gantt implements AfterCompose {
32 
33  private String selectItem;
34  private WorkOrder workOrder;
35  private double scale = 1.0;
36 
37  public WorkOrderGantt() {
38  }
39 
40  public String getSelectItem() {
41  return selectItem;
42  }
43 
44  public void setSelectItem(String selectItem) {
45  this.selectItem = selectItem;
46  }
47 
49  return workOrder;
50  }
51 
52  public void setWorkOrder(WorkOrder workOrder) {
53  this.workOrder = workOrder;
54  }
55 
56  public double getScale() {
57  return scale;
58  }
59 
60  public void setScale(double scale) {
61  this.scale = scale;
62  }
63 
64  public void reload() {
65  loadData();
66  repaint();
67  }
68 
69  @Override
70  public void afterCompose() {
71  loadData();
72  repaint();
73  }
74 
75  public void repaint() {
76  setVisible(false);
77  getChildren().clear();
78  clear();
79  startComposing(selectItem, null, null, scale);
80  generateContent(null);
81  setVisible(true);
82  }
83 
84  private void loadData() {
85  setData(getGanttData());
86  }
87 
88  private GanttData getGanttData() {
89  GanttData gd = new GanttData();
90  for(OrderReference or : workOrder.getOrderReferences()) {
91  if(or.isEmpty()) continue;
92  GanttItem gir = gd.addGanttItem(or.getOrderRef(), null, or.getSomeDescription(), 0, 0);
93  gir.setMilestone(false);
94  gir.setFinished(false);
95  for(Task t : or.getUpdatedTasks()) {
96  GanttItem gi = gd.addGanttItem(or.getOrderRef(), "" + t.getId(), t.getName(), t.getEstimatedDuration(), t.getRealDuration());
97  gi.setMilestone(t.isMilestone());
98  gi.setFinished(t.getStatus().equals(TaskStatus.TASK_FINISHED));
99  for(Predecessor p : t.getPredecessors()) {
100  GanttPredecessor gp = new GanttPredecessor(
101  p.getType().equals(PredecessorType.START_WHEN_STARTS) ?
102  GanttPredecessor.GANTT_START_TO_START :
103  GanttPredecessor.GANTT_END_TO_START,
104  "" + p.getPredecessor().getId(),
105  p.getLag(), true);
106  gi.getPredecessors().add(gp);
107  }
108  }
109  }
110  gd.initData();
111  return gd;
112  }
113 
114 }
Set< OrderReference > getOrderReferences()
Definition: WorkOrder.java:124
void setWorkOrder(WorkOrder workOrder)
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