BrightSide Workbench Full Report + Source Code
DepreciationsGrid.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.assets;
19 
20 import java.util.Date;
21 import java.util.logging.Level;
22 import java.util.logging.Logger;
23 import org.turro.elephant.context.ElephantContext;
24 import org.turro.financials.entity.FixedAsset;
25 import org.turro.financials.entity.FixedAssetDepreciation;
26 import org.turro.i18n.I_;
27 import org.turro.zkoss.grid.CollectionGrid;
28 import org.zkoss.zk.ui.ext.AfterCompose;
29 import org.zkoss.zul.Row;
30 
35 public class DepreciationsGrid extends CollectionGrid<FixedAssetDepreciation> implements AfterCompose {
36 
37  private FixedAsset fixedAsset;
38 
39  public DepreciationsGrid() {
40  super();
41  addColumns();
42  }
43 
44  public DepreciationsGrid(FixedAsset fixedAsset) {
45  super(fixedAsset.getDepreciations());
46  addColumns();
47  }
48 
50  return fixedAsset;
51  }
52 
53  public void setFixedAsset(FixedAsset fixedAsset) {
54  this.fixedAsset = fixedAsset;
55  setCollection(fixedAsset.getDepreciations());
56  }
57 
58  @Override
59  protected boolean isValid(FixedAssetDepreciation v) {
60  return v.isValid();
61  }
62 
63  @Override
64  protected void initiateRow(Row row, FixedAssetDepreciation value) {
65  if(value == null) {
66  value = new FixedAssetDepreciation();
67  value.setFixedAsset(fixedAsset);
68  fixedAsset.getDepreciations().add(value);
69  }
70  row.setValue(value);
71  }
72 
73  @Override
74  protected boolean deleteRow(Row row) {
75  FixedAssetDepreciation fad = (FixedAssetDepreciation) row.getValue();
76  if(fad != null) {
77  fixedAsset.getDepreciations().remove(fad);
78  fad.setFixedAsset(null);
79  }
80  return true;
81  }
82 
83  private void addColumns() {
84  try {
85  addColumn(I_.get("Date"), Date.class,
86  "depreciationDate", null, 0, true, false).setWidth("150px");
87  addColumn(I_.get("Percent"), "double",
88  "perCent", null, 2, false, false).setWidth("100px");
89  addColumn(I_.get("Comment"), String.class,
90  "comment", null, 0, false, false).setWidth("400px");
91  } catch (ClassNotFoundException ex) {
92  Logger.getLogger(DepreciationsGrid.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
93  }
94  }
95 
96 }
void initiateRow(Row row, FixedAssetDepreciation value)
boolean isValid(FixedAssetDepreciation v)
Set< FixedAssetDepreciation > getDepreciations()
Definition: FixedAsset.java:88
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)