BrightSide Workbench Full Report + Source Code
LineTypeAccountGrid.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.linetype;
19 
20 import java.util.logging.Level;
21 import java.util.logging.Logger;
22 import org.turro.string.Strings;
23 import org.turro.elephant.context.ElephantContext;
24 import org.turro.financials.contract.OperatingModifierListbox;
25 import org.turro.financials.entity.AccountPosition;
26 import org.turro.financials.entity.LineType;
27 import org.turro.financials.entity.LineTypeAccount;
28 import org.turro.financials.entity.LineTypeAccountType;
29 import org.turro.financials.entity.OperatingModifier;
30 import org.turro.financials.entity.RegisterView;
31 import org.turro.financials.view.ViewListbox;
32 import org.turro.i18n.I_;
33 import org.turro.zkoss.grid.CollectionGrid;
34 import org.turro.zkoss.grid.EditableCell;
35 import org.zkoss.zk.ui.HtmlBasedComponent;
36 import org.zkoss.zk.ui.ext.AfterCompose;
37 import org.zkoss.zul.Row;
38 
43 public class LineTypeAccountGrid extends CollectionGrid<LineTypeAccount> implements AfterCompose {
44 
45  public LineTypeAccountGrid(LineType lineType) {
46  super(lineType.getLineTypeAccounts());
47  addColumns();
48  setDefaultBehavior(false);
49  }
50 
51  @Override
52  protected void initiateRow(Row row, LineTypeAccount value) {
53  if(value == null) {
54  LineType lt = (LineType) getDependingRow().getValue();
55  value = new LineTypeAccount();
56  value.setCoefficient(1);
57  value.setLineType(lt);
58  lt.getLineTypeAccounts().add(value);
59  }
60  row.setValue(value);
61  }
62 
63  @Override
64  protected boolean deleteRow(Row row) {
65  return true;
66  }
67 
68  @Override
69  protected boolean isValid(LineTypeAccount v) {
70  return !Strings.isBlank(v.getPattern()) &&
71  v.getLineType() != null &&
72  v.getPosition() != null &&
73  v.getType() != null &&
74  v.getView() != null;
75  }
76 
77  @Override
78  protected HtmlBasedComponent createEditor(EditableCell editableCell) {
79  if(editableCell.getCellIndex() == 0) {
80  Object value = getCellValue(editableCell);
82  ltatl.setMold("select");
83  ltatl.setObjectValue((LineTypeAccountType) value);
84  return ltatl;
85  } if(editableCell.getCellIndex() == 3) {
86  Object value = getCellValue(editableCell);
88  apl.setMold("select");
89  apl.setObjectValue((AccountPosition) value);
90  return apl;
91  } if(editableCell.getCellIndex() == 5) {
92  Object value = getCellValue(editableCell);
93  ViewListbox vl = new ViewListbox();
94  vl.setMold("select");
95  vl.setObjectValue((RegisterView) value);
96  return vl;
97  } if(editableCell.getCellIndex() == 6) {
98  Object value = getCellValue(editableCell);
100  oml.setAllowNull(true);
101  oml.setMold("select");
102  oml.setObjectValue((OperatingModifier) value);
103  return oml;
104  }
105  return super.createEditor(editableCell);
106  }
107 
108  @Override
109  protected String formatCell(EditableCell editableCell, Object value) {
110  if(editableCell.getCellIndex() == 0) {
111  if(value instanceof LineTypeAccountType) {
112  return I_.byKey(((LineTypeAccountType) value).toString());
113  }
114  return "";
115  } else if(editableCell.getCellIndex() == 3) {
116  if(value instanceof AccountPosition) {
117  return I_.byKey(((AccountPosition) value).toString());
118  }
119  return "";
120  } else if(editableCell.getCellIndex() == 5) {
121  if(value instanceof RegisterView) {
122  return ((RegisterView) value).getName();
123  }
124  return "";
125  } else if(editableCell.getCellIndex() == 6) {
126  if(value instanceof OperatingModifier) {
127  return I_.byKey(((OperatingModifier) value).toString());
128  }
129  return "";
130  }
131  return super.formatCell(editableCell, value);
132  }
133 
134  private void addColumns() {
135  try {
136  addColumn(I_.get("Type"), org.turro.financials.entity.LineTypeAccountType.class,
137  "type", null, 0, false, false).setWidth("150px");
138  addColumn(I_.get("Value"), "double",
139  "typeValue", "0.00", 2, false, false).setWidth("100px");
140  addColumn(I_.get("Pattern"), String.class,
141  "pattern", null, 0, false, false);
142  addColumn(I_.get("Position"), org.turro.financials.entity.AccountPosition.class,
143  "position", null, 0, false, false).setWidth("150px");
144  addColumn(I_.get("Coefficient"), "double",
145  "coefficient", "0.00", 2, false, false).setWidth("100px");
146  addColumn(I_.get("View"), org.turro.financials.entity.RegisterView.class,
147  "view", null, 0, false, false).setWidth("250px");
148  addColumn("", org.turro.financials.entity.OperatingModifier.class,
149  "operatingModifier", null, 0, false, false).setWidth("250px");
150  } catch (ClassNotFoundException ex) {
151  Logger.getLogger(LineTypeAccountGrid.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
152  }
153  }
154 
155 }
Set< LineTypeAccount > getLineTypeAccounts()
Definition: LineType.java:92
void initiateRow(Row row, LineTypeAccount value)
HtmlBasedComponent createEditor(EditableCell editableCell)
String formatCell(EditableCell editableCell, Object value)
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)
void setDefaultBehavior(boolean defaultBehavior)