BrightSide Workbench Full Report + Source Code
RelatedColumnGrid.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.DocumentColumn;
24 import org.turro.financials.entity.DocumentDefinition;
25 import org.turro.financials.entity.RelatedColumn;
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.ext.AfterCompose;
31 import org.zkoss.zul.Row;
32 
37 public class RelatedColumnGrid extends CollectionGrid<RelatedColumn> implements AfterCompose {
38 
39  private DocumentDefinition documentDefinition;
40 
41  public RelatedColumnGrid() {
42  super();
43  addColumns();
44  }
45 
46  public RelatedColumnGrid(DocumentDefinition documentDefinition) {
47  super(documentDefinition.getDocumentColumns());
48  addColumns();
49  }
50 
52  return documentDefinition;
53  }
54 
55  public void setDocumentDefinition(DocumentDefinition documentDefinition) {
56  this.documentDefinition = documentDefinition;
57  setCollection(documentDefinition.getDocumentColumns());
58  }
59 
60  @Override
61  protected boolean isValid(RelatedColumn v) {
62  return v.getDocumentColumn() != null;
63  }
64 
65  @Override
66  protected void initiateRow(Row row, RelatedColumn value) {
67  if(value == null) {
68  value = new RelatedColumn();
69  value.setDocumentDefinition(documentDefinition);
70  documentDefinition.getDocumentColumns().add(value);
71  }
72  row.setValue(value);
73  }
74 
75  @Override
76  protected boolean deleteRow(Row row) {
77  return true;
78  }
79 
80  @Override
81  protected HtmlBasedComponent createEditor(EditableCell editableCell) {
82  if(editableCell.getCellIndex() == 0) {
83  Object value = getCellValue(editableCell);
85  dcl.setMold("select");
86  dcl.setObjectValue((DocumentColumn) value);
87  return dcl;
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 DocumentColumn) {
96  return I_.get(((DocumentColumn) value).toString());
97  }
98  return "";
99  }
100  return super.formatCell(editableCell, value);
101  }
102 
103  private void addColumns() {
104  try {
105  addColumn(I_.get("Column"), org.turro.financials.entity.DocumentColumn.class,
106  "documentColumn", null, 0, false, false).setWidth("70%");
107  addColumn(I_.get("Ordering"), "int",
108  "columnOrder", null, 0, false, false).setWidth("30%");
109  } catch (ClassNotFoundException ex) {
110  Logger.getLogger(RelatedColumnGrid.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
111  }
112  }
113 
114 }
void setDocumentDefinition(DocumentDefinition documentDefinition)
RelatedColumnGrid(DocumentDefinition documentDefinition)
HtmlBasedComponent createEditor(EditableCell editableCell)
void initiateRow(Row row, RelatedColumn value)
String formatCell(EditableCell editableCell, Object value)
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)