BrightSide Workbench Full Report + Source Code
AptitudeListbox.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.humanres;
19 
20 import org.turro.elephant.context.Application;
21 import org.turro.elephant.util.DateFormats;
22 import org.turro.elephant.util.DecimalFormats;
23 import org.turro.erp.entity.HumanResource;
24 import org.turro.erp.entity.OwnedAptitude;
25 import org.turro.zkoss.input.CollectionListbox;
26 import org.turro.zkoss.layout.ListheaderAdapter;
27 import org.turro.zkoss.layout.ListheaderRightAdapter;
28 import org.zkoss.zk.ui.event.Event;
29 import org.zkoss.zk.ui.event.EventListener;
30 import org.zkoss.zk.ui.event.Events;
31 import org.zkoss.zul.Listhead;
32 import org.zkoss.zul.Listitem;
33 
38 public class AptitudeListbox extends CollectionListbox<OwnedAptitude> {
39 
40  private HumanResource humanResource;
41 
43  return humanResource;
44  }
45 
46  public void setHumanResource(HumanResource humanResource) {
47  this.humanResource = humanResource;
48  setCollection(humanResource.getOwnedAptitudes());
49  }
50 
51  @Override
52  protected String convertToString(OwnedAptitude v) {
53  return (v.getInitialDate() != null ? DateFormats.format(v.getInitialDate(), true) : "") + ITEM_SEPARATOR +
54  (v.getFinalDate() != null ? DateFormats.format(v.getFinalDate(), true) : "") + ITEM_SEPARATOR +
58  }
59 
60  @Override
61  public void afterCompose() {
62  addHeaders();
63  super.afterCompose();
64  for(Object o : getChildren()) {
65  if(o instanceof Listitem) {
66  Listitem li = (Listitem) o;
67  OwnedAptitude oa = (OwnedAptitude) li.getValue();
68  if(oa.isDefaultDegree()) {
69  setSelectedItem(li);
70  break;
71  }
72  }
73  }
74  }
75 
76  private void addHeaders() {
77  if(getListhead() != null) return;
78  Listhead lh = new Listhead();
79  lh.setSizable(true);
80  lh.appendChild(new ListheaderAdapter(Application.getString("lFrom"), "1"));
81  lh.appendChild(new ListheaderAdapter(Application.getString("lTo"), "1"));
82  lh.appendChild(new ListheaderAdapter(Application.getString("lAptitude"), "3"));
83  lh.appendChild(new ListheaderRightAdapter(Application.getString("lCost"), "1"));
84  lh.appendChild(new ListheaderRightAdapter(Application.getString("lPrice"), "1"));
85  appendChild(lh);
86  setMultiple(false);
87  setCheckmark(true);
88  addEventListener(Events.ON_SELECT, new EventListener() {
89  @Override
90  public void onEvent(Event event) throws Exception {
91  Listitem li = getSelectedItem();
92  if(li != null) {
93  OwnedAptitude oas = (OwnedAptitude) li.getValue();
94  for(OwnedAptitude oa : humanResource.getOwnedAptitudes()) {
95  oa.setDefaultDegree(oa.getId() == oas.getId());
96  }
97  }
98  }
99  });
100  }
101 
102 }
103 
static String getString(String key)
static final String format(Date d, boolean dateOnly)
static String format(Number value, String pattern)
List< OwnedAptitude > getOwnedAptitudes()
void setDefaultDegree(boolean defaultDegree)
void setHumanResource(HumanResource humanResource)
void setCollection(Collection< V > collection)