BrightSide Workbench Full Report + Source Code
AptitudeGrid.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.aptitude;
19 
20 import java.util.Collection;
21 import org.turro.elephant.context.Application;
22 import org.turro.erp.db.ErpPU;
23 import org.turro.erp.menu.ErpMenu;
24 import org.turro.erp.entity.Aptitude;
25 import org.turro.erp.entity.AptitudeDegree;
26 import org.turro.zkoss.grid.PagingGrid;
27 import org.turro.zkoss.label.LabelTypes;
28 import org.turro.elephant.zkoss.ElLabel;
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.zk.ui.ext.AfterCompose;
33 import org.zkoss.zul.A;
34 import org.zkoss.zul.Column;
35 import org.zkoss.zul.Columns;
36 import org.zkoss.zul.Label;
37 import org.zkoss.zul.Row;
38 import org.zkoss.zul.Rows;
39 import org.zkoss.zul.Vlayout;
40 
45 public class AptitudeGrid extends PagingGrid implements AfterCompose {
46 
47  public void newAptitude() {
48  ErpMenu.showAptitude(null);
49  }
50 
51  @Override
52  public void afterCompose() {
53  addColumns();
54  addRows();
55  }
56 
57  private void addRows() {
59 
60  Collection<Aptitude> list = new ErpPU().getResultList(
61  "select aptitude from Aptitude as aptitude " +
62  "order by aptitude.name");
63 
64  Rows rows = new Rows();
65  appendChild(rows);
66 
67  for(final Aptitude o : list) {
68  Row row = new Row();
69  rows.appendChild(row);
70  row.appendChild(new Label(o.getId() + ""));
71 
72  Vlayout vbox = new Vlayout();
73  row.appendChild(vbox);
74 
75  A b = new A(o.getName());
76  if(app.isInRole("erp-config:edit")) {
77  b.addEventListener(Events.ON_CLICK, new EventListener() {
78  @Override
79  public void onEvent(Event event) throws Exception {
80  ErpMenu.showAptitude(o.getId());
81  }
82  });
83  }
84  vbox.appendChild(b);
85 
86  if(!o.getAptitudeDegrees().isEmpty()) {
87  for(AptitudeDegree od : o.getAptitudeDegrees()) {
88  vbox.appendChild(LabelTypes.getSoftLabel(od.getFullDescription()));
89  }
90  }
91  }
92 
93  setRowCount(list.size());
94  }
95 
96  private void addColumns() {
97  Columns cols = new Columns();
98  appendChild(cols);
99 
100  Column col = new Column("#", null, "50px");
101  cols.appendChild(col);
102 
103  col = new Column(Application.getString("lName"));
104  cols.appendChild(col);
105  }
106 
107 }
108 
static void showAptitude(Long id)
Definition: ErpMenu.java:170