BrightSide Workbench Full Report + Source Code
form/ConnectorGrid.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2015 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 
19 package org.turro.contacts.form;
20 
21 import org.turro.contacts.Connector;
22 import org.turro.contacts.Contact;
23 import org.turro.i18n.I_;
24 import org.turro.jpa.entity.EntityCollections;
25 import org.turro.zkoss.grid.CollectionGrid;
26 import org.turro.zkoss.grid.EditableCell;
27 import org.zkoss.zk.ui.HtmlBasedComponent;
28 import org.zkoss.zk.ui.ext.AfterCompose;
29 import org.zkoss.zul.Row;
30 
35 public class ConnectorGrid extends CollectionGrid<Connector> implements AfterCompose {
36 
37  private Contact contact;
38 
39  public void setContact(Contact contact) {
40  this.contact = contact;
41  setCollection(contact.getConnectors());
42  }
43 
44  @Override
45  protected boolean isValid(Connector v) {
46  return !v.isEmpty();
47  }
48 
49  @Override
50  protected void initiateRow(Row row, Connector value) {
51  if(value == null) {
52  value = new Connector();
53  value.setContact(contact);
54  contact.getConnectors().add(value);
55  }
56  row.setValue(value);
57  }
58 
59  @Override
60  protected boolean deleteRow(Row row) {
61  Connector a = (Connector) row.getValue();
62  EntityCollections.entities(contact.getConnectors()).remove(a);
63  a.setContact(contact);
64  return true;
65  }
66 
67  @Override
68  protected HtmlBasedComponent createEditor(EditableCell editableCell) {
69  if(editableCell.getCellIndex() == 0) {
70  Object value = getCellValue(editableCell);
72  cdc.setObjectValue((String) value);
73  return cdc;
74  }
75  return super.createEditor(editableCell);
76  }
77 
78  @Override
79  public void afterCompose() {
80  addColumns();
81  super.afterCompose();
82  }
83 
84  private void addColumns() {
85  addColumn(I_.get("Connector"), String.class,
86  "description", null, 0, false, false).setWidth("200px");
87  addColumn(I_.get("Value"), String.class,
88  "value", null, 0, false, false).setHflex("1");
89  }
90 
91 }
92 
void setContact(org.turro.contacts.Contact contact)
Definition: Connector.java:103
Set< Connector > getConnectors()
Definition: Contact.java:367
void initiateRow(Row row, Connector 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)
Object getCellValue(EditableCell editableCell)