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