BrightSide Workbench Full Report + Source Code
AptitudeDegreeGrid.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.logging.Level;
21 import java.util.logging.Logger;
22 import org.turro.elephant.context.Application;
23 import org.turro.erp.entity.Aptitude;
24 import org.turro.erp.entity.AptitudeDegree;
25 import org.turro.jpa.entity.EntityCollectionUtil;
26 import org.turro.zkoss.grid.CollectionGrid;
27 import org.zkoss.zul.Row;
28 
33 public class AptitudeDegreeGrid extends CollectionGrid<AptitudeDegree> {
34 
35  private Aptitude aptitude;
36 
37  public Aptitude getAptitude() {
38  return aptitude;
39  }
40 
41  public void setAptitude(Aptitude aptitude) {
42  this.aptitude = aptitude;
44  addColumns();
45  }
46 
47  @Override
48  protected void initiateRow(Row row, AptitudeDegree value) {
49  if(value == null) {
50  value = new AptitudeDegree();
51  value.setAptitude(aptitude);
52  aptitude.getAptitudeDegrees().add(value);
53  }
54  row.setValue(value);
55  }
56 
57  @Override
58  protected boolean deleteRow(Row row) {
59  AptitudeDegree t = (AptitudeDegree) row.getValue();
60  EntityCollectionUtil.remove(aptitude.getAptitudeDegrees(), t);
61  t.setAptitude(null);
62  return true;
63  }
64 
65  @Override
66  protected boolean isValid(AptitudeDegree v) {
67  return !v.isEmpty();
68  }
69 
70  private void addColumns() {
71  try {
72  addColumn(Application.getString("lOrdering"), "int", "ordering", null, 0, false, false).setWidth("60px");
73  addColumn(Application.getString("lName"), String.class, "name", null, 0, false, false).setWidth("400px");
74  addColumn(Application.getString("lCost"), "double", "cost", null, 2, false, false).setWidth("120px");
75  addColumn(Application.getString("lPrice"), "double", "price", null, 2, false, false).setWidth("120px");
76  } catch (ClassNotFoundException ex) {
77  Logger.getLogger(AptitudeDegreeGrid.class.getName()).log(Level.SEVERE, null, ex);
78  }
79  }
80 
81 }
static String getString(String key)
void initiateRow(Row row, AptitudeDegree value)
void setAptitude(Aptitude aptitude)
List< AptitudeDegree > getAptitudeDegrees()
Definition: Aptitude.java:60
void setCollection(Collection< V > collection)
EditableColumn addColumn(String label, Class javaClass, String property, String format, int scale, boolean onlyDate, boolean readOnly)