BrightSide Workbench Full Report + Source Code
GroupItTree.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2014 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 org.turro.contacts.GroupIt;
22 import org.zkoss.zk.ui.ext.AfterCompose;
23 import org.zkoss.zul.Tree;
24 import org.zkoss.zul.Treechildren;
25 import org.zkoss.zul.Treeitem;
26 
31 public class GroupItTree extends Tree implements AfterCompose {
32 
33  private Treechildren children;
34  private String category, entityPath;
35 
36  public GroupItTree() {
37  super();
38  addChildrenSpace();
39  }
40 
41  public String getCategory() {
42  return category;
43  }
44 
45  public void setCategory(String category) {
46  this.category = category;
47  children.getChildren().clear();
48  addGroup(null, false);
49  }
50 
51  public String getEntityPath() {
52  return entityPath;
53  }
54 
55  public void setEntityPath(String entityPath) {
56  this.entityPath = entityPath;
57  }
58 
59  public GroupItItem addGroup(GroupIt group, boolean loadOnDemand) {
60  GroupItItem grp = new GroupItItem(group, loadOnDemand, entityPath);
61  children.appendChild(grp);
62  grp.afterCompose();
63  return grp;
64  }
65 
67  if(getSelectedItem() instanceof GroupItItem ) {
68  return (GroupIt) ((GroupItItem) getSelectedItem()).getGroup();
69  }
70  return null;
71  }
72 
73  public void setSelectedGroup(GroupIt group) {
74  if(group == null) {
75  setSelectedItem(null);
76  } else {
77  for(Treeitem ti : getItems()) {
78  if(ti.getValue() instanceof GroupIt) {
79  if(((GroupIt) ti.getValue()).getId().equals(group.getId())) {
80  setSelectedItem(ti);
81  return;
82  }
83  }
84  }
85  setSelectedItem(null);
86  }
87  }
88 
89  public void changeSelectedGroup(GroupIt group) {
90  if(getSelectedItem() instanceof GroupItItem ) {
91  GroupItItem gi = (GroupItItem) getSelectedItem();
92  gi.setValue(group);
93  gi.setLabel(group.getName());
94  }
95  }
96 
97  private void addChildrenSpace() {
98  children = new Treechildren();
99  appendChild(children);
100  }
101 
102  public void reloadContents() {
103  for(Object o : children.getChildren()) {
104  if(o instanceof GroupItItem) {
105  ((GroupItItem) o).reloadContents();
106  }
107  }
108  }
109 
110  @Override
111  public void afterCompose() {
112  GroupItItem gpr = addGroup(null, false);
113  gpr.showContents();
114  }
115 
116 }
void setCategory(String category)
void setEntityPath(String entityPath)
GroupItItem addGroup(GroupIt group, boolean loadOnDemand)
void changeSelectedGroup(GroupIt group)
void setSelectedGroup(GroupIt group)