BrightSide Workbench Full Report + Source Code
bsfinancials-www/src/main/java/org/turro/financials/register/EntriesGrid.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.register;
19 
20 import java.util.logging.Level;
21 import java.util.logging.Logger;
22 import org.turro.elephant.context.ElephantContext;
23 import org.turro.financials.menu.FinancialsMenu;
24 import org.turro.financials.model.register.EntryWrapper;
25 import org.turro.financials.model.register.RegisterWrapper;
26 import org.turro.i18n.I_;
27 import org.turro.zkoss.grid.CollectionGrid;
28 import org.turro.zkoss.grid.EditableCell;
29 import org.zkoss.zk.ui.HtmlBasedComponent;
30 import org.zkoss.zk.ui.event.Event;
31 import org.zkoss.zk.ui.event.EventListener;
32 import org.zkoss.zk.ui.event.Events;
33 import org.zkoss.zul.A;
34 import org.zkoss.zul.Row;
35 
40 public class EntriesGrid extends CollectionGrid<EntryWrapper> {
41 
42  private RegisterWrapper wrapper;
43 
44  public EntriesGrid() {
45  super();
46  }
47 
48  public EntriesGrid(RegisterWrapper wrapper) {
49  super();
50  setWrapper(wrapper);
51  }
52 
54  return wrapper;
55  }
56 
57  public void setWrapper(RegisterWrapper wrapper) {
58  this.wrapper = wrapper;
59  setCollection(wrapper.getEntries());
60  }
61 
62  @Override
63  protected void initiateRow(Row row, EntryWrapper value) {
64  row.setValue(value);
65  }
66 
67  @Override
68  protected boolean deleteRow(Row row) {
69  throw new UnsupportedOperationException("Not supported yet.");
70  }
71 
72  @Override
73  protected boolean isValid(EntryWrapper v) {
74  return true;
75  }
76 
77  @Override
78  protected HtmlBasedComponent createRenderer(EditableCell editableCell) {
79  if(editableCell.getCellIndex() == 1) {
80  final EntryWrapper se = (EntryWrapper) editableCell.getRow().getValue();
81  A b = new A(se.getEntry().getAccount().getDescription());
82  b.setImage("/_zul/images/statement.png");
83  b.addEventListener(Events.ON_CLICK, new EventListener() {
84  @Override
85  public void onEvent(Event event) throws Exception {
87  }
88  });
89  return b;
90  }
91  return super.createRenderer(editableCell);
92  }
93 
94  @Override
95  public void afterCompose() {
96  setReadOnly(true);
97  if(wrapper.getRegister().getDocument().getDocumentDefinition() != null) {
98  try {
99  addColumns();
100  } catch (ClassNotFoundException ex) {
101  Logger.getLogger(EntriesGrid.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
102  }
103  }
104  super.afterCompose();
105  }
106 
107  private void addColumns() throws ClassNotFoundException {
108  int fractionDigits = wrapper.getRegister().getDocument().getCurrency().getDefaultFractionDigits();
109  addColumn(I_.get("Account"), String.class,
110  "entry.account.id", null, 0, false, false).setWidth("100px");
111  addColumn(I_.get("Description"), String.class,
112  "entry.account.description", null, 0, false, false);
113  addColumn(I_.get("Concept"), String.class,
114  "entry.concept", null, 0, false, false).setWidth("200px");
115  addColumn(I_.get("Debit"), "double",
116  "entry.debit", null, fractionDigits, false, false).setWidth("120px");
117  addColumn(I_.get("Credit"), "double",
118  "entry.credit", null, fractionDigits, false, false).setWidth("120px");
119  addColumn(I_.get("Balance"), "double",
120  "balance", null, fractionDigits, false, false).setWidth("120px");
121  }
122 
123 }
DocumentDefinition getDocumentDefinition()
Definition: Document.java:167
static void showStatement(String account)
static String get(String msg)
Definition: I_.java:41
void setCollection(Collection< V > collection)
EditableColumn addColumn(String label, Class javaClass, String property, String format, int scale, boolean onlyDate, boolean readOnly)
void setReadOnly(boolean readOnly)