BrightSide Workbench Full Report + Source Code
TagEntityGrid.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.tags;
20 
21 import java.util.List;
22 import java.util.Set;
23 import org.turro.elephant.context.Application;
24 import org.turro.entities.IElephantEntity;
25 import org.turro.jpa.grid.RenderPathOnDemand;
26 import org.turro.zkoss.grid.PagingGrid;
27 import org.zkoss.zk.ui.Component;
28 import org.zkoss.zk.ui.ext.AfterCompose;
29 import org.zkoss.zul.ListModelList;
30 import org.zkoss.zul.Row;
31 import org.zkoss.zul.Space;
32 import org.zkoss.zul.Vlayout;
33 
38 public class TagEntityGrid extends PagingGrid {
39 
40  private Set<TagItem> selected;
41 
42  public void setSelected(Set<TagItem> selected) {
43  this.selected = selected;
44  reload();
45  }
46 
47  public void reload() {
48  if(getRows() != null) {
49  getRows().detach();
50  }
51  addRows();
52  }
53 
54  public void afterCompose() {
55  reload();
56  }
57 
58  private void addRows() {
59  List<String> entityPaths = Tags.getEntityPaths(null, selected);
60 
61  setRowRenderer(new RenderPathOnDemand() {
62  @Override
63  protected void renderRow(Row row, IElephantEntity entity) {
64  fillRow(row, entity);
65  }
66  });
67 
68  setModel(new ListModelList<Object>(entityPaths));
69 
70  setRowCount(entityPaths.size());
71  }
72 
73  private void fillRow(Row row, IElephantEntity entity) {
74  if(Application.getApplication().isInRole(entity.getRoot() + "-tagit:list")) {
75  Vlayout vbox = new Vlayout();
76  row.appendChild(vbox);
77  Object obj = entity.getLabelCtrl();
78  if(obj instanceof Component) {
79  vbox.appendChild((Component) obj);
80  if(obj instanceof AfterCompose) {
81  ((AfterCompose) obj).afterCompose();
82  }
83  } else {
84  vbox.appendChild(new Space());
85  }
86  vbox.appendChild((Component) Tags.getControl(entity.getEntity()));
87  }
88  }
89 
90 }
void setSelected(Set< TagItem > selected)
static List< String > getEntityPaths(String root, Set< TagItem > set)
Definition: Tags.java:242
Rows getRows(boolean create)