BrightSide Workbench Full Report + Source Code
document/RelatedLineTypeGrid.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.document;
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.entity.DocumentDefinition;
24 import org.turro.financials.entity.LineType;
25 import org.turro.financials.entity.RelatedLineType;
26 import org.turro.financials.linetype.LineTypeCombobox;
27 import org.turro.i18n.I_;
28 import org.turro.zkoss.grid.CollectionGrid;
29 import org.turro.zkoss.grid.EditableCell;
30 import org.zkoss.zk.ui.HtmlBasedComponent;
31 import org.zkoss.zk.ui.ext.AfterCompose;
32 import org.zkoss.zul.Row;
33 
38 public class RelatedLineTypeGrid extends CollectionGrid<RelatedLineType> implements AfterCompose {
39 
40  private DocumentDefinition documentDefinition;
41 
43  super();
44  addColumns();
45  }
46 
47  public RelatedLineTypeGrid(DocumentDefinition documentDefinition) {
48  super(documentDefinition.getRelatedLineTypes());
49  addColumns();
50  }
51 
53  return documentDefinition;
54  }
55 
56  public void setDocumentDefinition(DocumentDefinition documentDefinition) {
57  this.documentDefinition = documentDefinition;
58  setCollection(documentDefinition.getRelatedLineTypes());
59  }
60 
61  @Override
62  protected boolean isValid(RelatedLineType v) {
63  return v.getLineType() != null;
64  }
65 
66  @Override
67  protected void initiateRow(Row row, RelatedLineType value) {
68  if(value == null) {
69  value = new RelatedLineType();
70  value.setDocumentDefinition(documentDefinition);
71  documentDefinition.getRelatedLineTypes().add(value);
72  }
73  row.setValue(value);
74  }
75 
76  @Override
77  protected boolean deleteRow(Row row) {
78  return true;
79  }
80 
81  @Override
82  protected HtmlBasedComponent createEditor(EditableCell editableCell) {
83  if(editableCell.getCellIndex() == 0) {
84  Object value = getCellValue(editableCell);
86  ltc.setObjectValue((LineType) value);
87  return ltc;
88  }
89  return super.createEditor(editableCell);
90  }
91 
92  @Override
93  protected String formatCell(EditableCell editableCell, Object value) {
94  if(editableCell.getCellIndex() == 0) {
95  if(value instanceof LineType) {
96  return ((LineType) value).getName();
97  }
98  return "";
99  }
100  return super.formatCell(editableCell, value);
101  }
102 
103  private void addColumns() {
104  try {
105  addColumn(I_.get("Line type"), org.turro.financials.entity.LineType.class,
106  "lineType", null, 0, false, false).setWidth("60%");
107  addColumn(I_.get("Default"), "boolean",
108  "defaultLineType", null, 0, false, false).setWidth("40%");
109  } catch (ClassNotFoundException ex) {
110  Logger.getLogger(RelatedLineTypeGrid.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
111  }
112  }
113 
114 }
void setDocumentDefinition(DocumentDefinition documentDefinition)
String formatCell(EditableCell editableCell, Object value)
RelatedLineTypeGrid(DocumentDefinition documentDefinition)
HtmlBasedComponent createEditor(EditableCell editableCell)
void setDocumentDefinition(DocumentDefinition documentDefinition)
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)
Object getCellValue(EditableCell editableCell)