BrightSide Workbench Full Report + Source Code
ContractPreferencesGrid.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 org.turro.string.Strings;
21 import org.turro.financials.entity.ContractDefinition;
22 import org.turro.financials.entity.ContractPreference;
23 import org.turro.i18n.I_;
24 import org.turro.zkoss.grid.CollectionGrid;
25 import org.zkoss.zk.ui.ext.AfterCompose;
26 import org.zkoss.zul.Row;
27 
32 public class ContractPreferencesGrid extends CollectionGrid<ContractPreference> implements AfterCompose {
33 
34  private ContractDefinition contractDefinition;
35 
37  super();
38  addColumns();
39  }
40 
41  public ContractPreferencesGrid(ContractDefinition contractDefinition) {
42  super(contractDefinition.getContractPreferences());
43  addColumns();
44  }
45 
47  return contractDefinition;
48  }
49 
50  public void setContractDefinition(ContractDefinition documentDefinition) {
51  this.contractDefinition = documentDefinition;
52  setCollection(documentDefinition.getContractPreferences());
53  }
54 
55  @Override
56  protected boolean isValid(ContractPreference v) {
57  return !Strings.isBlank(v.getName()) &&
58  (!Strings.isBlank(v.getAsOperating()) || !Strings.isBlank(v.getAsRetention()) ||
59  !Strings.isBlank(v.getAsTax()));
60  }
61 
62  @Override
63  protected void initiateRow(Row row, ContractPreference value) {
64  if(value == null) {
65  value = new ContractPreference();
66  value.setContractDefinition(contractDefinition);
67  contractDefinition.getContractPreferences().add(value);
68  }
69  row.setValue(value);
70  }
71 
72  @Override
73  protected boolean deleteRow(Row row) {
74  return true;
75  }
76 
77  private void addColumns() {
78  addColumn(I_.get("Name"), String.class,
79  "name", null, 0, false, false).setWidth("40%");
80  addColumn(I_.get("As operating store"), String.class,
81  "asOperating", null, 0, false, false).setWidth("20%");
82  addColumn(I_.get("As Tax major"), String.class,
83  "asTax", null, 0, false, false).setWidth("20%");
84  addColumn(I_.get("As Retention major"), String.class,
85  "asRetention", null, 0, false, false).setWidth("20%");
86 // addColumn(I_.get("As operating store"), String.class,
87 // "asContact", null, 0, false, false).setWidth("20%");
88 // addColumn(I_.get("As operating store"), String.class,
89 // "asCash", null, 0, false, false).setWidth("20%");
90  }
91 
92 }
93 
ContractPreferencesGrid(ContractDefinition contractDefinition)
void setContractDefinition(ContractDefinition documentDefinition)
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)