BrightSide Workbench Full Report + Source Code
XMLHumanResourceSelector.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 org.turro.elephant.context.Application;
22 import org.turro.util.CompareUtil;
23 import org.zkoss.lang.Strings;
24 import org.turro.elephant.zkoss.ElLabel;
25 import org.zkoss.zk.ui.event.Event;
26 import org.zkoss.zk.ui.event.EventListener;
27 import org.zkoss.zk.ui.event.Events;
28 import org.zkoss.zk.ui.ext.AfterCompose;
29 import org.zkoss.zul.Button;
30 import org.zkoss.zul.Grid;
31 import org.zkoss.zul.Label;
32 import org.zkoss.zul.Row;
33 import org.zkoss.zul.Rows;
34 
39 public class XMLHumanResourceSelector extends Grid implements AfterCompose {
40 
41  public String startsWith;
42 
43  public void setStartsWith(String startsWith) {
44  if(CompareUtil.compare(startsWith, this.startsWith) == 0) {
45  this.startsWith = null;
46  } else {
47  this.startsWith = startsWith;
48  }
49  afterCompose();
50  }
51 
52  @Override
53  public void afterCompose() {
54  Rows rows = getRows();
55  if(rows != null) {
56  rows.getChildren().clear();
57  } else {
58  rows = new Rows();
59  appendChild(rows);
60  }
61 
64 
65  for(XMLHumanResource hr : xhrs) {
66  if(!Strings.isBlank(startsWith) && !hr.getName().toLowerCase().startsWith(startsWith.toLowerCase())) {
67  continue;
68  }
69  final Row row = new Row();
70  row.setValue(hr);
71  rows.appendChild(row);
72 
73  xtcu.setHumanResource(hr);
74  if(xtcu.getPendingControl().isEmpty()) {
75  row.setSclass("not-in");
76  }
77  row.appendChild(new Label(hr.getName()));
78 
79  Button select = new Button(Application.getString("lSelect"));
80  select.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
81  @Override
82  public void onEvent(Event event) throws Exception {
83  Events.postEvent(new Event(Events.ON_CHANGE, XMLHumanResourceSelector.this, row.getValue()));
84  }
85  });
86  row.appendChild(select);
87  }
88  }
89 
90 }
static String getString(String key)
List< XMLTimeControl > getPendingControl()
void setHumanResource(XMLHumanResource humanResource)