BrightSide Workbench Full Report + Source Code
FormulaGrid.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.vendor;
20 
21 import org.turro.crm.db.CrmPU;
22 import org.turro.crm.entity.Formula;
23 import org.turro.crm.entity.FormulaType;
24 import org.turro.i18n.I_;
25 import org.turro.jpa.grid.JpaGrid;
26 import org.turro.zkoss.grid.EditableCell;
27 import org.turro.zkoss.label.LabelExtended;
28 import org.zkoss.zk.ui.HtmlBasedComponent;
29 import org.zkoss.zul.Row;
30 
35 public class FormulaGrid extends JpaGrid<Formula> {
36 
37  public FormulaGrid() {
38  super(new CrmPU(),
39  "select formula from Formula as formula " +
40  "order by formula.name", true);
41  addColumns();
42  }
43 
44  @Override
45  protected void initiateRow(Row row, Formula value) {
46  if(value == null) value = new Formula();
47  row.setValue(value);
48  }
49 
50  @Override
51  protected boolean isValid(Formula v) {
52  return v.isValid();
53  }
54 
55  @Override
56  protected HtmlBasedComponent createEditor(EditableCell editableCell) {
57  if(editableCell.getCellIndex() == 2) {
58  Object value = getCellValue(editableCell);
60  cdc.setMold("select");
61  if(value != null) cdc.setObjectValue((FormulaType) value);
62  return cdc;
63  }
64  return super.createEditor(editableCell);
65  }
66 
67  @Override
68  protected HtmlBasedComponent createRenderer(EditableCell editableCell) {
69  if(editableCell.getCellIndex() == 2) {
70  Object value = getCellValue(editableCell);
71  return new LabelExtended().setEnum((FormulaType) value);
72  }
73  return super.createRenderer(editableCell);
74  }
75 
76  public void addColumns() {
77  addColumn(I_.get("Name"), String.class, "name", null, 0, false, false);
78  addColumn(I_.get("Formula"), String.class, "formula", null, 0, false, false);
79  addColumn(I_.get("Type"), FormulaType.class, "type", null, 0, false, false).setWidth("150px");
80  }
81 
82 }
83 
HtmlBasedComponent createEditor(EditableCell editableCell)
void initiateRow(Row row, Formula value)
HtmlBasedComponent createRenderer(EditableCell editableCell)
static String get(String msg)
Definition: I_.java:41
EditableColumn addColumn(String label, Class javaClass, String property, String format, int scale, boolean onlyDate, boolean readOnly)
Object getCellValue(EditableCell editableCell)