BrightSide Workbench Full Report + Source Code
RelatedDocumentGrid.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.contract;
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.document.DocumentDefinitionCombobox;
24 import org.turro.financials.entity.ContractDefinition;
25 import org.turro.financials.entity.DocumentDefinition;
26 import org.turro.financials.entity.RelatedDocument;
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 RelatedDocumentGrid extends CollectionGrid<RelatedDocument> implements AfterCompose {
39 
40  private ContractDefinition contractDefinition;
41 
43  super();
44  addColumns();
45  }
46 
47  public RelatedDocumentGrid(ContractDefinition contractDefinition) {
48  super(contractDefinition.getRelatedDocuments());
49  addColumns();
50  }
51 
53  return contractDefinition;
54  }
55 
56  public void setContractDefinition(ContractDefinition contractDefinition) {
57  this.contractDefinition = contractDefinition;
58  setCollection(contractDefinition.getRelatedDocuments());
59  }
60 
61  @Override
62  protected boolean isValid(RelatedDocument v) {
63  return v.getDocumentDefinition() != null;
64  }
65 
66  @Override
67  protected void initiateRow(Row row, RelatedDocument value) {
68  if(value == null) {
69  value = new RelatedDocument();
70  value.setContractDefinition(contractDefinition);
71  contractDefinition.getRelatedDocuments().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);
87  return cdc;
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 DocumentDefinition) {
96  return ((DocumentDefinition) value).getName();
97  }
98  return "";
99  }
100  return super.formatCell(editableCell, value);
101  }
102 
103  private void addColumns() {
104  try {
105  addColumn(I_.get("Document model"), org.turro.financials.entity.DocumentDefinition.class,
106  "documentDefinition", null, 0, false, false).setWidth("70%");
107  addColumn(I_.get("Allowed"), "boolean",
108  "allowed", null, 0, false, false).setWidth("30%");
109  } catch (ClassNotFoundException ex) {
110  Logger.getLogger(RelatedDocumentGrid.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
111  }
112  }
113 
114 }
RelatedDocumentGrid(ContractDefinition contractDefinition)
HtmlBasedComponent createEditor(EditableCell editableCell)
void setContractDefinition(ContractDefinition contractDefinition)
void initiateRow(Row row, RelatedDocument value)
String formatCell(EditableCell editableCell, Object value)
void setContractDefinition(ContractDefinition contractDefinition)
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)