BrightSide Workbench Full Report + Source Code
TaskSelector.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2012 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.erp.time;
20 
21 import java.util.List;
22 import org.turro.elephant.context.Application;
23 import org.turro.erp.entity.HumanResource;
24 import org.turro.erp.entity.TimeControl;
25 import org.turro.erp.task.Workload;
26 import org.turro.erp.task.WorkloadSet;
27 import org.turro.zkoss.label.LabelExtended;
28 import org.turro.zkoss.label.LabelTypes;
29 import org.zkoss.zk.ui.event.Event;
30 import org.zkoss.zk.ui.event.EventListener;
31 import org.zkoss.zk.ui.event.Events;
32 import org.zkoss.zul.Button;
33 import org.zkoss.zul.Grid;
34 import org.zkoss.zul.Label;
35 import org.zkoss.zul.Row;
36 import org.zkoss.zul.Rows;
37 import org.zkoss.zul.Space;
38 import org.zkoss.zul.Vlayout;
39 
44 public class TaskSelector extends Grid {
45 
46  public void setHumanResource(HumanResource humanResource) {
47  boolean canGetIn = true;
48 
49  Rows rows = getRows();
50  if(rows != null) {
51  rows.getChildren().clear();
52  } else {
53  rows = new Rows();
54  appendChild(rows);
55  }
56 
57  TimeControlUtil tcu = new TimeControlUtil();
58  tcu.setHumanResource(humanResource);
59  List<TimeControl> pending = tcu.getPendingControl();
60 
61  for(TimeControl tc : pending) {
62  final Row row = new Row();
63  row.setValue(tc);
64  rows.appendChild(row);
65 
66  row.appendChild(new LabelExtended().setDateTime(tc.getStartTime()));
67 
68  if(tc.getTask() != null) {
69  row.appendChild(new Label(tc.getTask().getFullDescription()));
70  } else {
71  row.appendChild(new Space());
72  canGetIn = false;
73  }
74 
75  Button select = new Button(tc.getTask() == null ? Application.getString("lGetOut") : Application.getString("lFinalize") + " " +Application.getString("lTask"));
76  select.setHflex("true");
77  select.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
78  @Override
79  public void onEvent(Event event) throws Exception {
80  Events.postEvent(new Event(Events.ON_CHANGE, TaskSelector.this, row.getValue()));
81  }
82  });
83  row.appendChild(select);
84  }
85 
86  if(canGetIn) {
87  final Row rowStart = new Row();
88  rows.appendChild(rowStart);
89 
90  rowStart.appendChild(new Label(Application.getString("lNow")));
91 
92  rowStart.appendChild(new Space());
93 
94  Button butStart = new Button(Application.getString("lGetIn"));
95  butStart.setHflex("true");
96  butStart.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
97  @Override
98  public void onEvent(Event event) throws Exception {
99  Events.postEvent(new Event(Events.ON_USER, TaskSelector.this, null));
100  }
101  });
102  rowStart.appendChild(butStart);
103  }
104 
105  final Row rowCancel = new Row();
106  rows.appendChild(rowCancel);
107 
108  rowCancel.appendChild(new Space());
109  rowCancel.appendChild(new Space());
110 
111  Button butCancel = new Button(Application.getString("lCancel"));
112  butCancel.setHflex("true");
113  butCancel.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
114  @Override
115  public void onEvent(Event event) throws Exception {
116  Events.postEvent(new Event(Events.ON_CANCEL, TaskSelector.this));
117  }
118  });
119  rowCancel.appendChild(butCancel);
120 
121  WorkloadSet wls = new WorkloadSet(humanResource, true);
122 
123  for(Workload wl : wls) {
124  final Row row = new Row();
125  row.setValue(wl);
126  rows.appendChild(row);
127 
128  row.appendChild(new Label(Application.getString("lNow")));
129 
130  Vlayout vbox = new Vlayout();
131  row.appendChild(vbox);
132  vbox.appendChild(new Label(wl.getTask().getName()));
133  vbox.appendChild(LabelTypes.getSoftLabel(wl.getTask().getDescription()));
134  vbox.appendChild(new Label(wl.getTask().getOrderReference().getWorkOrder().getFullDescription()));
135  vbox.appendChild(new Label(wl.getTask().getOrderReference().getWorkOrder().getContract().getName()));
136 
137  Button select = new Button(Application.getString("lStart") + " " +Application.getString("lTask"));
138  select.setHflex("true");
139  select.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
140  @Override
141  public void onEvent(Event event) throws Exception {
142  Events.postEvent(new Event(Events.ON_CHANGE, TaskSelector.this, row.getValue()));
143  }
144  });
145  row.appendChild(select);
146  }
147  }
148 
149 }
static String getString(String key)
void setHumanResource(HumanResource humanResource)
void setHumanResource(HumanResource humanResource)
List< TimeControl > getPendingControl()