BrightSide Workbench Full Report + Source Code
RootSkillsGrid.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2020 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.skills;
20 
21 import org.turro.elephant.db.ElephantPU;
22 import org.turro.elephant.entities.db.Skill;
23 import org.turro.elephant.entities.db.SkillType;
24 import org.turro.entities.EntityRootCombobox;
25 import org.turro.i18n.I_;
26 import org.turro.jpa.grid.JpaGrid;
27 import org.turro.zkoss.grid.EditableCell;
28 import org.zkoss.zk.ui.HtmlBasedComponent;
29 import org.zkoss.zul.Row;
30 
35 public class RootSkillsGrid extends JpaGrid<Skill> {
36 
37  public RootSkillsGrid() {
38  super(new ElephantPU(), "select s from Skill s where s.entityPath not like '/%'", true);
39  addColumns();
40  }
41 
42  @Override
43  protected void initiateRow(Row row, Skill value) {
44  if(value == null) value = new Skill();
45  row.setValue(value);
46  }
47 
48  @Override
49  protected boolean isValid(Skill v) {
50  return !v.isEmpty();
51  }
52 
53  @Override
54  protected HtmlBasedComponent createEditor(EditableCell editableCell) {
55  if(editableCell.getCellIndex() == 1) {
56  Object value = getCellValue(editableCell);
58  erc.setObjectValue((String) (value != null ? value : "*"));
59  return erc;
60  } else if(editableCell.getCellIndex() == 2) {
61  Object value = getCellValue(editableCell);
63  stl.setMold("select");
64  stl.setObjectValue((SkillType) value);
65  return stl;
66  }
67  return super.createEditor(editableCell);
68  }
69 
70  private void addColumns() {
71  addColumn(I_.get("Skill"), String.class, "skill", null, 0, false, false).setHflex("3");
72  addColumn(I_.get("Root"), String.class, "entityPath", null, 0, false, false).setHflex("1");
73  addColumn(I_.get("Type"), SkillType.class, "type", null, 0, false, false).setHflex("1");
74  }
75 
76 }
static String get(String msg)
Definition: I_.java:41
void initiateRow(Row row, Skill value)
HtmlBasedComponent createEditor(EditableCell editableCell)
EditableColumn addColumn(String label, Class javaClass, String property, String format, int scale, boolean onlyDate, boolean readOnly)
Object getCellValue(EditableCell editableCell)