BrightSide Workbench Full Report + Source Code
HumanResourceSelector.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.db.ErpPU;
24 import org.turro.erp.entity.HumanResource;
25 import org.turro.jpa.Dao;
26 import org.zkoss.zk.ui.event.Event;
27 import org.zkoss.zk.ui.event.EventListener;
28 import org.zkoss.zk.ui.event.Events;
29 import org.zkoss.zk.ui.ext.AfterCompose;
30 import org.zkoss.zul.Button;
31 import org.zkoss.zul.Grid;
32 import org.zkoss.zul.Label;
33 import org.zkoss.zul.Row;
34 import org.zkoss.zul.Rows;
35 
40 public class HumanResourceSelector extends Grid implements AfterCompose {
41 
42  @Override
43  public void afterCompose() {
44  Rows rows = getRows();
45  if(rows != null) {
46  rows.getChildren().clear();
47  } else {
48  rows = new Rows();
49  appendChild(rows);
50  }
51 
52  Dao dao = new ErpPU();
53  List<HumanResource> list = dao.getResultList(
54  "select hr from HumanResource as hr where hr.active = true order by hr.name");
55 
56  for(HumanResource hr : list) {
57  final Row row = new Row();
58  row.setValue(hr);
59  rows.appendChild(row);
60 
61  row.appendChild(new Label(hr.getName()));
62 
63  Button select = new Button(Application.getString("lSelect"));
64  select.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
65  @Override
66  public void onEvent(Event event) throws Exception {
67  Events.postEvent(new Event(Events.ON_CHANGE, HumanResourceSelector.this, row.getValue()));
68  }
69  });
70  row.appendChild(select);
71  }
72  }
73 
74 }
static String getString(String key)