BrightSide Workbench Full Report + Source Code
DossierVersionGrid.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.dossier.zul.dossier;
19 
20 import java.util.Date;
21 import java.util.logging.Level;
22 import java.util.logging.Logger;
23 import org.turro.dossier.entity.Dossier;
24 import org.turro.dossier.entity.DossierVersion;
25 import org.turro.elephant.context.ElephantContext;
26 import org.turro.i18n.I_;
27 import org.turro.jpa.entity.EntityCollections;
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.zul.Row;
32 
37 public class DossierVersionGrid extends CollectionGrid<DossierVersion> {
38 
39  private Dossier dossier;
40 
41  public DossierVersionGrid() {
42  }
43 
44  public DossierVersionGrid(Dossier dossier) {
45  super(dossier.getVersions());
46  this.dossier = dossier;
47  addColumns();
48  }
49 
50  public void setDossier(Dossier dossier) {
51  this.dossier = dossier;
52  setCollection(dossier.getVersions());
53  addColumns();
54  }
55 
56  @Override
57  protected void initiateRow(Row row, DossierVersion value) {
58  if(value == null) {
59  value = new DossierVersion();
60  value.setDossier(dossier);
61  dossier.getVersions().add(value);
62  }
63  row.setValue(value);
64  }
65 
66  @Override
67  protected boolean deleteRow(Row row) {
68  DossierVersion dv = (DossierVersion) row.getValue();
69  EntityCollections.entities(dossier.getVersions()).remove(dv);
70  dv.setDossier(null);
71  return true;
72  }
73 
74  @Override
75  protected boolean isValid(DossierVersion v) {
76  return !v.isEmpty();
77  }
78 
79  @Override
80  protected HtmlBasedComponent createEditor(EditableCell editableCell) {
81  return super.createEditor(editableCell);
82  }
83 
84  private void addColumns() {
85  try {
86  addColumn(I_.get("Version"), String.class, "versionId", null, 0, false, false).setHflex("2");
87  addColumn(I_.get("Release date"), Date.class, "releaseDate", null, 0, true, false).setHflex("2");
88  addColumn(I_.get("Active"), "boolean", "active", null, 0, true, false).setHflex("1");
89  } catch (ClassNotFoundException ex) {
90  Logger.getLogger(DossierVersionGrid.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
91  }
92  }
93 
94 }
Set< DossierVersion > getVersions()
Definition: Dossier.java:215
void initiateRow(Row row, DossierVersion value)
HtmlBasedComponent createEditor(EditableCell editableCell)
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)