BrightSide Workbench Full Report + Source Code
ResourceGrid.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.resource;
19 
20 import java.util.Collection;
21 import org.turro.elephant.context.Application;
22 import org.turro.elephant.util.DecimalFormats;
23 import org.turro.erp.db.ErpPU;
24 import org.turro.erp.entity.AptitudeDegree;
25 import org.turro.erp.menu.ErpMenu;
26 import org.turro.erp.entity.Resource;
27 import org.turro.zkoss.grid.PagingGrid;
28 import org.turro.zkoss.label.LabelTypes;
29 import org.turro.elephant.zkoss.ElLabel;
30 import org.zkoss.zk.ui.event.Event;
31 import org.zkoss.zk.ui.event.EventListener;
32 import org.zkoss.zk.ui.event.Events;
33 import org.zkoss.zk.ui.ext.AfterCompose;
34 import org.zkoss.zul.A;
35 import org.zkoss.zul.Column;
36 import org.zkoss.zul.Columns;
37 import org.zkoss.zul.Hlayout;
38 import org.zkoss.zul.Image;
39 import org.zkoss.zul.Label;
40 import org.zkoss.zul.Row;
41 import org.zkoss.zul.Rows;
42 import org.zkoss.zul.Vlayout;
43 
48 public class ResourceGrid extends PagingGrid implements AfterCompose {
49 
50  public void newResource() {
51  ErpMenu.showResource(null);
52  }
53 
54  @Override
55  public void afterCompose() {
56  addColumns();
57  addRows();
58  }
59 
60  private void addRows() {
62 
63  Collection<Resource> list = new ErpPU().getResultList(
64  "select res from Resource res " +
65  "order by res.name");
66 
67  Rows rows = new Rows();
68  appendChild(rows);
69 
70  for(final Resource res : list) {
71  Row row = new Row();
72  rows.appendChild(row);
73  if(!res.isActive()) {
74  row.setSclass("draft");
75  }
76  row.appendChild(new Label(res.getId() + ""));
77  Vlayout vbox = new Vlayout();
78  row.appendChild(vbox);
79  A b = new A(res.getName());
80  if(app.isInRole("erp-config:edit")) {
81  b.addEventListener(Events.ON_CLICK, new EventListener() {
82  @Override
83  public void onEvent(Event event) throws Exception {
84  ErpMenu.showResource(res.getId());
85  }
86  });
87  }
88  vbox.appendChild(b);
89 
90  if(!res.getAptitudeDegrees().isEmpty()) {
91  Hlayout hbox = new Hlayout();
92  vbox.appendChild(hbox);
93  hbox.appendChild(new Image("/_zul/images/aptitude.png"));
94  for(AptitudeDegree od : res.getAptitudeDegrees()) {
95  hbox.appendChild(LabelTypes.getSoftLabel(od.getFullDescription()));
96  }
97  }
98 
99  row.appendChild(new Label(DecimalFormats.format(res.getCostHour())));
100  row.appendChild(new Label(DecimalFormats.format(res.getPriceHour())));
101  }
102 
103  setRowCount(list.size());
104  }
105 
106  private void addColumns() {
107  Columns cols = new Columns();
108  appendChild(cols);
109 
110  Column col = new Column("#", null, "50px");
111  cols.appendChild(col);
112 
113  col = new Column(Application.getString("lName"));
114  cols.appendChild(col);
115 
116  col = new Column(Application.getString("lCost"), null, "120px");
117  col.setAlign("right");
118  cols.appendChild(col);
119 
120  col = new Column(Application.getString("lPrice"), null, "120px");
121  col.setAlign("right");
122  cols.appendChild(col);
123  }
124 
125 }
126 
static void showResource(Long id)
Definition: ErpMenu.java:174