BrightSide Workbench Full Report + Source Code
GroupedGrid.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2014 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.zul.groupit;
20 
21 import org.turro.contacts.GroupIt;
22 import org.turro.contacts.Grouped;
23 import org.turro.contacts.db.ContactsPU;
24 import org.turro.entities.Entities;
25 import org.turro.i18n.I_;
26 import org.turro.zkoss.grid.CollectionGrid;
27 import org.turro.zkoss.grid.EditableCell;
28 import org.zkoss.zk.ui.HtmlBasedComponent;
29 import org.zkoss.zul.Row;
30 
35 public class GroupedGrid extends CollectionGrid<Grouped> {
36 
37  private String entityPath;
38 
39  public GroupedGrid() {
40  addColumns();
41  }
42 
43  public String getEntityPath() {
44  return entityPath;
45  }
46 
47  public void setEntityPath(String entityPath) {
48  this.entityPath = entityPath;
49  setCollection(Grouped.groups(entityPath));
50  }
51 
52  public void setEntity(Object entity) {
54  }
55 
56  @Override
57  protected void initiateRow(Row row, Grouped value) {
58  if(value == null) {
59  value = new Grouped();
60  value.setPath(entityPath);
61  }
62  row.setValue(value);
63  }
64 
65  @Override
66  protected boolean deleteRow(Row row) {
67  new ContactsPU().deleteObject(row.getValue());
68  return true;
69  }
70 
71  @Override
72  protected boolean isValid(Grouped v) {
73  return v.isValid();
74  }
75 
76  @Override
77  protected HtmlBasedComponent createEditor(EditableCell editableCell) {
78  if(editableCell.getCellIndex() == 0) {
79  Grouped g = editableCell.getRow().getValue();
81  if(g != null) {
82  if(g.getParent() != null) {
84  } else {
86  }
87  }
88  return cc;
89  } else if(editableCell.getCellIndex() == 1) {
90  Grouped g = editableCell.getRow().getValue();
91  GroupItBandbox gb = new GroupItBandbox();
92  if(g != null) {
93  if(g.getParent() != null) {
95  } else {
96  gb.setCategory(g.getCategory());
97  }
98  gb.setObjectValue(g.getParent());
99  }
100  return gb;
101  }
102  return super.createEditor(editableCell);
103  }
104 
105  @Override
106  protected Object getEditorValue(EditableCell editableCell) {
107  if(editableCell.getCellIndex() == 0) {
108  CategoryCombobox cc = (CategoryCombobox) editableCell.getEditor();
109  return cc.getObjectValue();
110  } else if(editableCell.getCellIndex() == 1) {
111  GroupItBandbox gb = (GroupItBandbox) editableCell.getEditor();
112  return gb.getObjectValue();
113  }
114  return super.getEditorValue(editableCell);
115  }
116 
117  @Override
118  protected String formatCell(EditableCell editableCell, Object value) {
119  if(editableCell.getCellIndex() == 1) {
120  if(value != null) {
121  return ((GroupIt) value).getPathName();
122  }
123  }
124  return super.formatCell(editableCell, value);
125  }
126 
127  private void addColumns() {
128  addColumn(I_.get("Category"), String.class,
129  "category", null, 0, false, false).setWidth("30%");
130  addColumn(I_.get("Group"), GroupIt.class,
131  "parent", null, 0, false, false).setWidth("70%");
132  }
133 
134 }
void setPath(String path)
Definition: Grouped.java:74
static Collection< Grouped > groups(Object entity, String category)
Definition: Grouped.java:98
static IElephantEntity getController(String path)
Definition: Entities.java:78
static String get(String msg)
Definition: I_.java:41
void deleteObject(Object obj)
Definition: Dao.java:162
void setCollection(Collection< V > collection)
EditableColumn addColumn(String label, Class javaClass, String property, String format, int scale, boolean onlyDate, boolean readOnly)
void initiateRow(Row row, Grouped value)
String formatCell(EditableCell editableCell, Object value)
Object getEditorValue(EditableCell editableCell)
void setEntityPath(String entityPath)
HtmlBasedComponent createEditor(EditableCell editableCell)