BrightSide Workbench Full Report + Source Code
MajorAccountGrid.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.financials.account;
19 
20 import org.turro.string.Strings;
21 import org.turro.financials.book.BookListbox;
22 import org.turro.financials.db.FinancialsPU;
23 import org.turro.financials.entity.BookDefinition;
24 import org.turro.financials.entity.MajorAccount;
25 import org.turro.financials.entity.MajorAccountType;
26 import org.turro.i18n.I_;
27 import org.turro.jpa.grid.JpaGrid;
28 import org.turro.zkoss.grid.EditableCell;
29 import org.turro.zkoss.input.EnumListbox;
30 import org.zkoss.zk.ui.HtmlBasedComponent;
31 import org.zkoss.zul.Row;
32 
37 public class MajorAccountGrid extends JpaGrid<MajorAccount> {
38 
39  public MajorAccountGrid() {
40  super(new FinancialsPU(),
41  "select major from MajorAccount as major " +
42  "order by major.account", true);
43  addColumns();
44  }
45 
46  @Override
47  protected void initiateRow(Row row, MajorAccount value) {
48  if(value == null) value = new MajorAccount();
49  row.setValue(value);
50  //addDetail(row);
51  }
52 
53  @Override
54  protected boolean isValid(MajorAccount v) {
55  return !Strings.isBlank(v.getAccount()) &&
56  !Strings.isBlank(v.getDescription());
57  }
58 
59 // @Override
60 // protected void rowChanged(Row row) {
61 // MajorDetail cd = (MajorDetail) row.getDetailChild();
62 // cd.rowChanged(row);
63 // super.rowChanged(row);
64 // }
65 
66  @Override
67  protected HtmlBasedComponent createEditor(EditableCell editableCell) {
68  if(editableCell.getCellIndex() == 2) {
69  EnumListbox<MajorAccountType> mat = new EnumListbox<MajorAccountType>(MajorAccountType.values());
70  mat.setMold("select");
71  mat.setObjectValue((MajorAccountType) getCellValue(editableCell));
72  mat.setAllowNull(true);
73  return mat;
74  } else if(editableCell.getCellIndex() == 3) {
75  BookListbox blb = new BookListbox();
76  blb.setMold("select");
77  blb.setObjectValue((BookDefinition) getCellValue(editableCell));
78  blb.setAllowNull(true);
79  return blb;
80  }
81  return super.createEditor(editableCell);
82  }
83 
84  @Override
85  protected String formatCell(EditableCell editableCell, Object value) {
86  if(editableCell.getCellIndex() == 2 && value != null) {
87  return I_.byKey(((MajorAccountType) value).toString());
88  } else if(editableCell.getCellIndex() == 3 && value != null) {
89  return ((BookDefinition) value).getDescription();
90  }
91  return super.formatCell(editableCell, value);
92  }
93 
94  private void addColumns() {
95  //addDetailColumn();
96  addColumn(I_.get("Account"), String.class,
97  "account", null, 0, false, false).setWidth("100px");
98  addColumn(I_.get("Description"), String.class,
99  "description", null, 0, false, false);
100  addColumn(I_.get("Type"), MajorAccountType.class,
101  "type", null, 0, false, false).setWidth("160px");
102  addColumn(I_.get("Book"), org.turro.financials.entity.BookDefinition.class,
103  "bookDefinition", null, 0, false, false).setWidth("300px");
104  }
105 
106 // private void addDetail(Row row) {
107 // row.getChildren().clear();
108 // MajorDetail detail = new MajorDetail(row, this, 0);
109 // row.appendChild(detail);
110 // }
111 
112 }
void initiateRow(Row row, MajorAccount value)
String formatCell(EditableCell editableCell, Object value)
HtmlBasedComponent createEditor(EditableCell editableCell)
static String byKey(String key)
Definition: I_.java:83
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)