BrightSide Workbench Full Report + Source Code
GroupEntityGrid.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.zul.groupit;
20 
21 import java.util.Collection;
22 import org.turro.command.CommandUtil;
23 import org.turro.contacts.GroupIt;
24 import org.turro.groupit.GroupItUtil;
25 import org.turro.zkoss.grid.PagingGrid;
26 import org.zkoss.zk.ui.Component;
27 import org.zkoss.zul.ListModelList;
28 import org.zkoss.zul.Row;
29 import org.zkoss.zul.RowRenderer;
30 import org.zkoss.zul.Space;
31 
36 public class GroupEntityGrid extends PagingGrid {
37 
38  private GroupIt groupIt;
39  private String category;
40  private boolean exact;
41 
42  public GroupEntityGrid() {
43  }
44 
45  public void setGroupIt(GroupIt groupIt) {
46  this.groupIt = groupIt;
47  this.category = groupIt != null ? groupIt.getCategory() : null;
48  }
49 
50  public void setCategory(String category) {
51  this.category = category;
52  }
53 
54  public void setExact(boolean exact) {
55  this.exact = exact;
56  }
57 
58  public void reload() {
59  if(getRows() != null) {
60  getRows().detach();
61  }
62  addRows();
63  }
64 
65  public void afterCompose() {
66  reload();
67  }
68 
69  private void addRows() {
70  Collection<String> list = GroupItUtil.getPathsFromGroup("",
71  (groupIt != null ? groupIt.getPathName() : ""), category, exact);
72 
73  setRowRenderer(new RowRenderer<Object>() {
74  @Override
75  public void render(Row row, Object data, int index) throws Exception {
76  if(data instanceof String) {
77  Component comp = CommandUtil.getLink((String) data);
78  row.appendChild(comp == null ? new Space() : comp);
79  }
80  }
81  });
82 
83  setModel(new ListModelList<Object>(list));
84 
85  setRowCount(list.size());
86  }
87 
88 }
static HtmlBasedComponent getLink(Object entity)
static Collection< String > getPathsFromGroup(String path, String selectedGroup, String selectedCategory)
Rows getRows(boolean create)