BrightSide Workbench Full Report + Source Code
CommentsGrid.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.Comment;
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.zkoss.zk.ui.ext.AfterCompose;
27 import org.zkoss.zul.Row;
28 
33 public class CommentsGrid extends CollectionGrid<Comment> implements AfterCompose {
34 
35  private Contact contact;
36 
37  public void setContact(Contact contact) {
38  this.contact = contact;
39  setCollection(contact.getComments());
40  }
41 
42  @Override
43  protected boolean isValid(Comment v) {
44  return !v.isEmpty();
45  }
46 
47  @Override
48  protected void initiateRow(Row row, Comment value) {
49  if(value == null) {
50  value = new Comment();
51  value.setContact(contact);
52  contact.getComments().add(value);
53  }
54  row.setValue(value);
55  }
56 
57  @Override
58  protected boolean deleteRow(Row row) {
59  Comment a = (Comment) row.getValue();
60  EntityCollections.entities(contact.getComments()).remove(a);
61  a.setContact(contact);
62  return true;
63  }
64 
65  @Override
66  public void afterCompose() {
67  addColumns();
68  super.afterCompose();
69  }
70 
71  private void addColumns() {
72  addColumn(I_.get("Comment"), String.class,
73  "comment", null, 10, false, false);
74  }
75 
76 }
void setContact(Contact contact)
Definition: Comment.java:93
Set< Comment > getComments()
Definition: Contact.java:415
void initiateRow(Row row, Comment value)
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)