BrightSide Workbench Full Report + Source Code
DocumentRegisterView.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.Date;
21 import java.util.HashSet;
22 import java.util.logging.Level;
23 import java.util.logging.Logger;
24 import org.turro.elephant.context.ElephantContext;
25 import org.turro.financials.entity.Document;
26 import org.turro.financials.entity.Register;
27 import org.turro.financials.entity.RegisterView;
28 import org.turro.financials.model.register.RegisterWrapper;
29 import org.turro.financials.register.EntriesGrid;
30 import org.turro.i18n.I_;
31 import org.turro.zkoss.grid.CollectionGrid;
32 import org.turro.zkoss.grid.EditableCell;
33 import org.zkoss.zul.Detail;
34 import org.zkoss.zul.Row;
35 import org.zkoss.zul.Vbox;
36 
41 public class DocumentRegisterView extends CollectionGrid<Register> {
42 
43  private Document document;
44 
45  public DocumentRegisterView(Document document) {
46  super();
47  setDocument(document);
48  setReadOnly(true);
49  setAllowDeletions(false);
50  setAllowInsertions(false);
51  }
52 
53  public Document getDocument() {
54  return document;
55  }
56 
57  public void setDocument(Document document) {
58  this.document = document;
59  if(getCollection() == null) {
60  setCollection(new HashSet<Register>());
61  }
62  if(document != null && document.getContract() != null) {
63  getCollection().addAll(document.getRegisters());
64  }
65  }
66 
67  @Override
68  protected void initiateRow(Row row, Register value) {
69  row.setValue(value);
70  addDetail(row);
71  }
72 
73  @Override
74  protected boolean deleteRow(Row row) {
75  throw new UnsupportedOperationException("Not supported yet.");
76  }
77 
78  @Override
79  protected boolean isValid(Register v) {
80  return true;
81  }
82 
83  @Override
84  protected String formatCell(EditableCell editableCell, Object value) {
85  if(editableCell.getCellIndex() == 1) {
86  if(value instanceof Long) {
87  if(((Long) value) == 0) {
88  return "<auto>";
89  }
90  }
91  } else if(editableCell.getCellIndex() == 3) {
92  if(value instanceof RegisterView) {
93  return ((RegisterView) value).getName();
94  }
95  return "";
96  }
97  return super.formatCell(editableCell, value);
98  }
99 
100  @Override
101  public void afterCompose() {
102  setReadOnly(true);
103  if(document != null && document.getDocumentDefinition() != null) {
104  try {
105  addColumns();
106  } catch (ClassNotFoundException ex) {
107  Logger.getLogger(DocumentRegisterView.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
108  }
109  }
110  super.afterCompose();
111  }
112 
113  private void addColumns() throws ClassNotFoundException {
114  //int fractionDigits = document.getCurrency().getDefaultFractionDigits();
115  addDetailColumn();
116  addColumn(I_.get("Register"), "long",
117  "idRegister", null, 0, false, false).setWidth("120px");
118  addColumn(I_.get("Date"), Date.class,
119  "registerDate", null, 0, true, false).setWidth("120px");
120  addColumn(I_.get("View"), RegisterView.class,
121  "view", null, 0, false, false).setWidth("200px");
122  addColumn(I_.get("Books"), String.class,
123  "bookString", null, 0, false, false);
124  }
125 
126  private void addDetail(Row row) {
127  row.getChildren().clear();
128  Detail detail = new Detail();
129  row.appendChild(detail);
130  Vbox vbox = new Vbox();
131  vbox.setWidth("100%");
132  vbox.setStyle("padding:5px");
133  detail.appendChild(vbox);
134  EntriesGrid eg = new EntriesGrid(new RegisterWrapper((Register) row.getValue(), false));
135  eg.setDependingRow(row);
136  eg.setReadOnly(isReadOnly());
137  eg.setAllowDeletions(isAllowDeletions());
138  eg.setAllowInsertions(isAllowInsertions());
139  vbox.appendChild(eg);
140  eg.afterCompose();
141  detail.setVisible(!eg.getCollection().isEmpty());
142  detail.setOpen(detail.isVisible());
143  row.setVisible(detail.isVisible());
144  }
145 
146 }
String formatCell(EditableCell editableCell, Object value)
DocumentDefinition getDocumentDefinition()
Definition: Document.java:167
static String get(String msg)
Definition: I_.java:41
void setCollection(Collection< V > collection)
void setAllowDeletions(boolean allowDeletions)
EditableColumn addColumn(String label, Class javaClass, String property, String format, int scale, boolean onlyDate, boolean readOnly)
void setAllowInsertions(boolean allowInsertions)
void setReadOnly(boolean readOnly)