BrightSide Workbench Full Report + Source Code
MajorAccountDetailGrid.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.entity.BookDefinition;
23 import org.turro.financials.entity.MajorAccount;
24 import org.turro.i18n.I_;
25 import org.turro.zkoss.grid.CollectionGrid;
26 import org.turro.zkoss.grid.EditableCell;
27 import org.zkoss.zk.ui.HtmlBasedComponent;
28 import org.zkoss.zk.ui.ext.AfterCompose;
29 import org.zkoss.zul.Row;
30 
35 public class MajorAccountDetailGrid extends CollectionGrid<MajorAccount> implements AfterCompose {
36 
37  private static final int MAX_LEVELS = 2;
38 
39  private int level;
40 
41  public MajorAccountDetailGrid(MajorAccount major, int level) {
42  super(major.getDescendants());
43  this.level = level;
44  addColumns();
45  }
46 
47  @Override
48  protected void initiateRow(Row row, MajorAccount value) {
49  if(value == null) {
50  MajorAccount c = (MajorAccount) getDependingRow().getValue();
51  value = new MajorAccount();
52  c.getDescendants().add(value);
53  }
54  row.setValue(value);
55  addDetail(row);
56  }
57 
58  @Override
59  protected boolean deleteRow(Row row) {
60  return true;
61  }
62 
63  @Override
64  protected boolean isValid(MajorAccount v) {
65  return !Strings.isBlank(v.getAccount()) &&
66  !Strings.isBlank(v.getDescription());
67  }
68 
69  @Override
70  protected HtmlBasedComponent createEditor(EditableCell editableCell) {
71  int cellIndex = editableCell.getCellIndex();
72  boolean bookEdit = level < MAX_LEVELS ? cellIndex == 3 : cellIndex == 2;
73  if(bookEdit) {
74  BookListbox blb = new BookListbox();
75  blb.setMold("select");
76  blb.setObjectValue((BookDefinition) getCellValue(editableCell));
77  blb.setAllowNull(true);
78  return blb;
79  }
80  return super.createEditor(editableCell);
81  }
82 
83  @Override
84  protected String formatCell(EditableCell editableCell, Object value) {
85  int cellIndex = editableCell.getCellIndex();
86  boolean bookEdit = level < MAX_LEVELS ? cellIndex == 3 : cellIndex == 2;
87  if(bookEdit && value != null) {
88  return ((BookDefinition) value).getDescription();
89  }
90  return super.formatCell(editableCell, value);
91  }
92 
93  private void addColumns() {
94  if(level < MAX_LEVELS) addDetailColumn();
95  addColumn(I_.get("Account"), String.class,
96  "account", null, 0, false, false).setWidth("200px");
97  addColumn(I_.get("Description"), String.class,
98  "description", null, 0, false, false);
99  addColumn(I_.get("Book"), org.turro.financials.entity.BookDefinition.class,
100  "bookDefinition", null, 0, false, false).setWidth("300px");
101  }
102 
103  private void addDetail(Row row) {
104  if(level < MAX_LEVELS) {
105  row.getChildren().clear();
106  MajorDetail detail = new MajorDetail(row, this, level + 1);
107  row.appendChild(detail);
108  }
109  }
110 
111 }
HtmlBasedComponent createEditor(EditableCell editableCell)
String formatCell(EditableCell editableCell, Object value)
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)