BrightSide Workbench Full Report + Source Code
contacts/src/main/java/org/turro/activity/ParticipationGrid.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.activity;
19 
20 import org.turro.command.CommandUtil;
21 import org.turro.contacts.Contact;
22 import org.turro.contacts.db.ContactsPU;
23 import org.turro.zkoss.grid.GroupExtended;
24 import org.turro.zkoss.grid.PagingGrid;
25 import org.zkoss.zk.ui.Component;
26 import org.zkoss.zul.Group;
27 import org.zkoss.zul.Label;
28 import org.zkoss.zul.Row;
29 import org.zkoss.zul.Rows;
30 
35 public class ParticipationGrid extends PagingGrid {
36 
37  private Rows rows;
38  private boolean canDelete = true, onlyEntities = false;
39 
40  public ParticipationGrid() {
41  addColumns();
42  }
43 
44  public void setContact(Contact contact) {
45  addRows(contact);
46  }
47 
48  public boolean isOnlyEntities() {
49  return onlyEntities;
50  }
51 
52  public void setOnlyEntities(boolean onlyEntities) {
53  this.onlyEntities = onlyEntities;
54  }
55 
56  public boolean isCanDelete() {
57  return canDelete;
58  }
59 
60  public boolean doDelete() {
61  if(canDelete) {
62  for(Object o : rows.getChildren()) {
63  if(o instanceof Row) {
64  IParticipation ia = (IParticipation) ((Row) o).getValue();
65  if(ia != null) ia.doDelete();
66  }
67  }
68  }
69  return canDelete;
70  }
71 
72  private void addColumns() {
73  }
74 
75  private void addRows(Contact contact) {
76 
77  if(rows != null) removeChild(rows);
78 
79  rows = new Rows();
80  appendChild(rows);
81 
82  int count = 0;
83  String groupName = null;
84 
85  for(IParticipation ia : ParticipationCatchers.getParticipations(ContactsPU.getObjectPath(contact))) {
86  Row row = new Row();
87  if(onlyEntities) {
88  Component comp = CommandUtil.getLink(ia.getEntity());
89  if(comp != null) {
90  row.appendChild(comp);
91  row.setValue(ia);
92  if(!ia.getCatcher().getDescription().equals(groupName)) {
93  Group group = new GroupExtended(ia.getCatcher().getDescription());
94  rows.appendChild(group);
95  groupName = ia.getCatcher().getDescription();
96  }
97  rows.appendChild(row);
98  count++;
99  }
100  } else {
101  Label l = new Label(ia.getDescription());
102  if(ia.isCanDelete()) {
103  l.setSclass("canDel");
104  } else {
105  l.setSclass("cannotDel");
106  }
107  row.appendChild(l);
108  row.setValue(ia);
109  if(!ia.getCatcher().getDescription().equals(groupName)) {
110  Group group = new GroupExtended(ia.getCatcher().getDescription());
111  rows.appendChild(group);
112  groupName = ia.getCatcher().getDescription();
113  }
114  rows.appendChild(row);
115  count++;
116  }
117  if(canDelete) {
118  canDelete = ia.isCanDelete();
119  }
120  }
121 
122  setRowCount(count);
123 
124  }
125 
126 }
127