BrightSide Workbench Full Report + Source Code
elephant-www/src/main/java/org/turro/participation/ParticipationGrid.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 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.participation;
20 
21 import java.util.List;
22 import org.turro.assistant.ParticipationInfo;
23 import org.turro.zkoss.grid.PagingGrid;
24 import org.turro.zkoss.label.LabelExtended;
25 import org.zkoss.zk.ui.Component;
26 import org.zkoss.zk.ui.ext.AfterCompose;
27 import org.zkoss.zul.Label;
28 import org.zkoss.zul.ListModelList;
29 import org.zkoss.zul.Row;
30 import org.zkoss.zul.Space;
31 
36 public class ParticipationGrid extends PagingGrid {
37 
38  private String entityPath;
39 
40  public String getEntityPath() {
41  return entityPath;
42  }
43 
44  public void setEntityPath(String entityPath) {
45  this.entityPath = entityPath;
46  }
47 
48  public void reload() {
49  if(getRows() != null) {
50  getRows().detach();
51  }
52  addRows();
53  }
54 
55  public void afterCompose() {
56  reload();
57  }
58 
59  private void addRows() {
60 
61  List<IEntityParticipation> participations = new ParticipationInfo(entityPath, null).getParticipations();
62 
63  setRowRenderer(new RenderParticipationOnDemand() {
64  @Override
65  protected void renderRow(Row row, IEntityParticipation participation) {
66  fillRow(row, participation);
67  }
68  });
69 
70  setModel(new ListModelList<Object>(participations));
71 
72  setRowCount(participations.size());
73  }
74 
75  private void fillRow(Row row, IEntityParticipation participation) {
76  row.appendChild(new LabelExtended().setDateTime(participation.getParticipationDate()));
77  row.appendChild(new Label(participation.getReason().toString()));
78  Object obj = participation.getParticipator().getLabelCtrl();
79  if(obj instanceof Component) {
80  row.appendChild((Component) obj);
81  if(obj instanceof AfterCompose) {
82  ((AfterCompose) obj).afterCompose();
83  }
84  } else {
85  row.appendChild(new Space());
86  }
87  }
88 
89 }
List< IEntityParticipation > getParticipations()
Rows getRows(boolean create)