BrightSide Workbench Full Report + Source Code
RelatedContractStoreGrid.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.DocumentDefinitionListbox;
24 import org.turro.financials.entity.Contract;
25 import org.turro.financials.entity.DocumentDefinition;
26 import org.turro.financials.entity.RelatedContractStore;
27 import org.turro.financials.model.document.DocumentDefinitionWrapper;
28 import org.turro.i18n.I_;
29 import org.turro.jpa.entity.EntityCollections;
30 import org.turro.zkoss.grid.CollectionGrid;
31 import org.turro.zkoss.grid.EditableCell;
32 import org.zkoss.zk.ui.HtmlBasedComponent;
33 import org.zkoss.zk.ui.ext.AfterCompose;
34 import org.zkoss.zul.Row;
35 
40 public class RelatedContractStoreGrid extends CollectionGrid<RelatedContractStore> implements AfterCompose {
41 
42  private Contract contract;
43 
45  super();
46  addColumns();
47  }
48 
50  super(contract.getRelatedContractStores());
51  addColumns();
52  }
53 
54  public Contract getContract() {
55  return contract;
56  }
57 
58  public void setContract(Contract contract) {
59  this.contract = contract;
61  }
62 
63  @Override
64  protected boolean isValid(RelatedContractStore v) {
65  return v.getStore() != null &&
66  v.getDocumentDefinition() != null;
67  }
68 
69  @Override
70  protected void initiateRow(Row row, RelatedContractStore value) {
71  if(value == null) {
72  value = new RelatedContractStore();
73  value.setContract(contract);
74  contract.getRelatedContractStores().add(value);
75  }
76  row.setValue(value);
77  }
78 
79  @Override
80  protected boolean deleteRow(Row row) {
81  RelatedContractStore rcs = (RelatedContractStore) row.getValue();
82  EntityCollections.entities(contract.getRelatedContractStores()).remove(rcs);
83  rcs.setContract(null);
84  return true;
85  }
86 
87  @Override
88  protected HtmlBasedComponent createEditor(EditableCell editableCell) {
89  if(editableCell.getCellIndex() == 0) {
90  Object value = getCellValue(editableCell);
93  rd.setMold("select");
94  return rd;
95  } else if(editableCell.getCellIndex() == 1) {
96  RelatedContractStore rcs = (RelatedContractStore) editableCell.getRow().getValue();
97  Object value = getCellValue(editableCell);
100  sl.setObjectValue((Contract) value);
101  sl.setMold("select");
102  return sl;
103  }
104  return super.createEditor(editableCell);
105  }
106 
107  @Override
108  protected String formatCell(EditableCell editableCell, Object value) {
109  if(editableCell.getCellIndex() == 0) {
110  if(value instanceof DocumentDefinition) {
111  return ((DocumentDefinition) value).getName();
112  }
113  return "";
114  } else if(editableCell.getCellIndex() == 1) {
115  if(value instanceof Contract) {
116  return ((Contract) value).getName();
117  }
118  return "";
119  }
120  return super.formatCell(editableCell, value);
121  }
122 
123  private void addColumns() {
124  try {
125  addColumn(I_.get("Document model"), org.turro.financials.entity.DocumentDefinition.class,
126  "documentDefinition", null, 0, false, false).setWidth("40%");
127  addColumn(I_.get("Store"), org.turro.financials.entity.Contract.class,
128  "store", null, 0, false, false).setWidth("40%");
129  addColumn(I_.get("Allowed"), "boolean",
130  "allowed", null, 0, false, false).setWidth("20%");
131  } catch (ClassNotFoundException ex) {
132  Logger.getLogger(RelatedContractStoreGrid.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
133  }
134  }
135 
136 }
String formatCell(EditableCell editableCell, Object value)
HtmlBasedComponent createEditor(EditableCell editableCell)
ContractDefinition getContractDefinition()
Definition: Contract.java:125
Set< RelatedContractStore > getRelatedContractStores()
Definition: Contract.java:268
static String get(String msg)
Definition: I_.java:41
static EntityCollections entities(Collection values)
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)