BrightSide Workbench Full Report + Source Code
DocumentWorkflowGrid.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.DocumentWorkflow;
27 import org.turro.financials.entity.LineType;
28 import org.turro.financials.linetype.LineTypeListbox;
29 import org.turro.i18n.I_;
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 DocumentWorkflowGrid extends CollectionGrid<DocumentWorkflow> implements AfterCompose {
41 
42  private ContractDefinition contractDefinition;
43 
45  super();
46  addColumns();
47  }
48 
49  public DocumentWorkflowGrid(ContractDefinition contractDefinition) {
50  super(contractDefinition.getDocumentWorkflows());
51  addColumns();
52  }
53 
55  return contractDefinition;
56  }
57 
58  public void setContractDefinition(ContractDefinition documentDefinition) {
59  this.contractDefinition = documentDefinition;
60  setCollection(documentDefinition.getDocumentWorkflows());
61  }
62 
63  @Override
64  protected boolean isValid(DocumentWorkflow v) {
65  return v.getAncestor() != null && v.getDescendant() != null;
66  }
67 
68  @Override
69  protected void initiateRow(Row row, DocumentWorkflow value) {
70  if(value == null) {
71  value = new DocumentWorkflow();
72  value.setContractDefinition(contractDefinition);
73  contractDefinition.getDocumentWorkflows().add(value);
74  }
75  row.setValue(value);
76  }
77 
78  @Override
79  protected boolean deleteRow(Row row) {
80  return true;
81  }
82 
83  @Override
84  protected HtmlBasedComponent createEditor(EditableCell editableCell) {
85  if(editableCell.getCellIndex() < 2) {
86  Object value = getCellValue(editableCell);
89  return cdc;
90  } else if(editableCell.getCellIndex() == 3) {
91  DocumentWorkflow dw = (DocumentWorkflow) editableCell.getRow().getValue();
92  Object value = getCellValue(editableCell);
93  LineTypeListbox ltl = new LineTypeListbox(dw == null ? null : dw.getDescendant());
94  ltl.setObjectValue((LineType) value);
95  ltl.setMold("select");
96  return ltl;
97  }
98  return super.createEditor(editableCell);
99  }
100 
101  @Override
102  protected String formatCell(EditableCell editableCell, Object value) {
103  if(editableCell.getCellIndex() < 2) {
104  if(value instanceof DocumentDefinition) {
105  return ((DocumentDefinition) value).getName();
106  }
107  return "";
108  } else if(editableCell.getCellIndex() == 3) {
109  if(value instanceof LineType) {
110  return ((LineType) value).getName();
111  }
112  return "";
113  }
114  return super.formatCell(editableCell, value);
115  }
116 
117  private void addColumns() {
118  try {
119  addColumn(I_.get("Ancestor"), org.turro.financials.entity.DocumentDefinition.class,
120  "ancestor", null, 0, false, false).setWidth("30%");
121  addColumn(I_.get("Descendant"), org.turro.financials.entity.DocumentDefinition.class,
122  "descendant", null, 0, false, false).setWidth("30%");
123  addColumn(I_.get("Expiries"), "boolean",
124  "allowNewDescendants", null, 0, false, false).setWidth("10%");
125  addColumn(I_.get("Line type"), org.turro.financials.entity.LineType.class,
126  "lineType", null, 0, false, false).setWidth("30%");
127  } catch (ClassNotFoundException ex) {
128  Logger.getLogger(DocumentWorkflowGrid.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
129  }
130  }
131 
132 }
133 
void initiateRow(Row row, DocumentWorkflow value)
String formatCell(EditableCell editableCell, Object value)
HtmlBasedComponent createEditor(EditableCell editableCell)
DocumentWorkflowGrid(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)
Object getCellValue(EditableCell editableCell)