BrightSide Workbench Full Report + Source Code
ActivitySectorGrid.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2015 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.crm.zul.sector;
20 
21 import java.util.logging.Level;
22 import java.util.logging.Logger;
23 import org.turro.crm.db.CrmPU;
24 import org.turro.crm.entity.ActivitySector;
25 import org.turro.elephant.context.ElephantContext;
26 import org.turro.i18n.I_;
27 import org.turro.jpa.grid.JpaGrid;
28 import org.zkoss.zul.Row;
29 
34 public class ActivitySectorGrid extends JpaGrid<ActivitySector> {
35 
36  public ActivitySectorGrid() {
37  super(new CrmPU(),
38  "select actsec from ActivitySector as actsec " +
39  "order by actsec.name", true);
40  addColumns();
41  }
42 
43  @Override
44  protected void initiateRow(Row row, ActivitySector value) {
45  if(value == null) value = new ActivitySector();
46  row.setValue(value);
47  }
48 
49  @Override
50  protected boolean isValid(ActivitySector v) {
51  return v.isValid();
52  }
53 
54  @Override
55  protected boolean deleteRow(Row row) {
56  ActivitySector as = row.getValue();
57  Long count = (Long) getDao().getSingleResult(
58  "select count(c) from Customer c " +
59  "join c.activitySectors a " +
60  "where a = ?",
61  new Object[] { as });
62  if(count == 0) {
63  return super.deleteRow(row);
64  }
65  return false;
66  }
67 
68  public void addColumns() {
69  try {
70  addColumn("#", "long", "id", null, 0, false, true).setWidth("40px");
71  addColumn(I_.get("Name"), String.class, "name", null, 0, false, false);
72  } catch (ClassNotFoundException ex) {
73  Logger.getLogger(ActivitySectorGrid.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
74  }
75  }
76 
77 }
78 
void initiateRow(Row row, ActivitySector value)
static String get(String msg)
Definition: I_.java:41
Object getSingleResult(WhereClause wc)
Definition: Dao.java:380
EditableColumn addColumn(String label, Class javaClass, String property, String format, int scale, boolean onlyDate, boolean readOnly)