BrightSide Workbench Full Report + Source Code
zul/contact/ConnectorGrid.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.contacts.zul.contact;
19 
20 import org.turro.string.Strings;
21 import org.turro.contacts.Connector;
22 import org.turro.contacts.Contact;
23 import org.turro.i18n.I_;
24 import org.turro.zkoss.grid.CollectionGrid;
25 import org.turro.zkoss.grid.EditableCell;
26 import org.zkoss.zk.ui.HtmlBasedComponent;
27 import org.zkoss.zk.ui.ext.AfterCompose;
28 import org.zkoss.zul.Row;
29 
34 public class ConnectorGrid extends CollectionGrid<Connector> implements AfterCompose {
35 
36  private Contact contact;
37 
38  public ConnectorGrid(Contact contact) {
39  super(contact.getConnectors());
40  this.contact = contact;
41  setDefaultBehavior(false);
42  addColumns();
43  }
44 
45  @Override
46  protected boolean isValid(Connector v) {
47  return !Strings.isBlank(v.getDescription()) &&
48  !Strings.isBlank(v.getValue());
49  }
50 
51  @Override
52  protected void initiateRow(Row row, Connector value) {
53  if(value == null) {
54  value = new Connector();
55  value.setContact(contact);
56  contact.getConnectors().add(value);
57  }
58  row.setValue(value);
59  }
60 
61  @Override
62  protected boolean deleteRow(Row row) {
63  contact.getConnectors().remove((Connector) row.getValue());
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.setConnectorName((String) value);
73  return cdc;
74  }
75  return super.createEditor(editableCell);
76  }
77 
78  private void addColumns() {
79  addColumn(I_.get("Connector"), String.class,
80  "description", null, 0, false, false).setWidth("300px");
81  addColumn(I_.get("Value"), String.class,
82  "value", null, 0, false, false);
83  }
84 
85 }
void setContact(org.turro.contacts.Contact contact)
Definition: Connector.java:103
Set< Connector > getConnectors()
Definition: Contact.java:367
HtmlBasedComponent createEditor(EditableCell editableCell)
static String get(String msg)
Definition: I_.java:41
EditableColumn addColumn(String label, Class javaClass, String property, String format, int scale, boolean onlyDate, boolean readOnly)
Object getCellValue(EditableCell editableCell)
void setDefaultBehavior(boolean defaultBehavior)