BrightSide Workbench Full Report + Source Code
CategoryDossierTree.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.dossier.dossier;
20 
21 import org.turro.dossier.entity.Category;
22 import org.zkoss.zk.ui.ext.AfterCompose;
23 import org.zkoss.zul.Tree;
24 import org.zkoss.zul.Treechildren;
25 
30 public class CategoryDossierTree extends Tree implements AfterCompose {
31 
32  private Treechildren children;
33  private boolean loadOnDemand = true, knowledgeBase = false;
34 
36  super();
37  addChildrenSpace();
38  }
39 
40  public void setLoadOnDemand(boolean loadOnDemand) {
41  this.loadOnDemand = loadOnDemand;
42  }
43 
44  public void setKnowledgeBase(boolean knowledgeBase) {
45  this.knowledgeBase = knowledgeBase;
46  }
47 
48  public CategoryDossierItem addEntity(Category category, boolean loadOnDemand, boolean knowledgeBase) {
49  CategoryDossierItem cat = new CategoryDossierItem(category, loadOnDemand, knowledgeBase);
50  children.appendChild(cat);
51  cat.afterCompose();
52  return cat;
53  }
54 
55  public Object getSelectedEntity() {
56  if(getSelectedItem() instanceof CategoryDossierItem ) {
57  return ((CategoryDossierItem) getSelectedItem()).getEntity();
58  }
59  return null;
60  }
61 
62  private void addChildrenSpace() {
63  children = new Treechildren();
64  appendChild(children);
65  }
66 
67  public void reloadContents() {
68  for(Object o : children.getChildren()) {
69  if(o instanceof CategoryItem) {
70  ((CategoryItem) o).reloadContents();
71  }
72  }
73  }
74 
75  @Override
76  public void afterCompose() {
77  CategoryDossierItem cat = addEntity(null, loadOnDemand, knowledgeBase);
78  cat.showContents();
79  }
80 
81 }
CategoryDossierItem addEntity(Category category, boolean loadOnDemand, boolean knowledgeBase)