BrightSide Workbench Full Report + Source Code
zul/navigator/AttachTree.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.attach.zul.navigator;
19 
20 import org.turro.attach.search.AttachResults;
21 import org.turro.elephant.context.Application;
22 import org.zkoss.zk.ui.ext.AfterCompose;
23 import org.zkoss.zul.Tree;
24 import org.zkoss.zul.Treechildren;
25 
30 public class AttachTree extends Tree implements AfterCompose {
31 
32  private Treechildren children;
33  private AttachNavigatorListener attachListener;
34  private AttachResults results;
35  private boolean doProcessors = true;
36 
37  public AttachTree() {
38  super();
39  addChildrenSpace();
40  }
41 
43  return attachListener;
44  }
45 
47  this.attachListener = listener;
48  }
49 
50  public void setDoProcessors(boolean doProcessors) {
51  this.doProcessors = doProcessors;
52  }
53 
54 
55  public AttachFolder addFolder(String label, String path, boolean loadOnDemand) {
56  AttachFolder af = new AttachFolder(label, path, loadOnDemand);
57  children.appendChild(af);
58  af.afterCompose();
59  if(doProcessors) af.doProcessors();
60  return af;
61  }
62 
64  if(getSelectedItem() instanceof AttachFolder) {
65  return (AttachFolder) getSelectedItem();
66  }
67  return null;
68  }
69 
70  public void setSelectedFolder(AttachFolder folder) {
71  for(Object o : getItems()) {
72  if(o instanceof AttachFolder) {
73  AttachFolder af = (AttachFolder) o;
74  if(af.getPath().equals(folder.getPath())) {
75  setSelectedItem(af);
76  break;
77  }
78  }
79  }
80  }
81 
83  for(Object o : getItems()) {
84  if(o instanceof AttachFolder) {
85  AttachFolder af = (AttachFolder) o;
86  setSelectedItem(af);
87  return af;
88  }
89  }
90  return null;
91  }
92 
94  return results;
95  }
96 
97  public void setResults(AttachResults results) {
98  this.results = results;
99  }
100 
101  public void resetTree() {
102  children.getChildren().clear();
103  }
104 
105  private void addChildrenSpace() {
106  children = new Treechildren();
107  appendChild(children);
108  }
109 
110  public void reloadContents() {
111  for(Object o : children.getChildren()) {
112  if(o instanceof AttachFolder) {
113  ((AttachFolder) o).reloadContents();
114  }
115  }
116  }
117 
118  public boolean getCanDelete() {
119  return Application.getApplication().isInRole("attach:delete");
120  }
121 
122  public boolean getCanNew() {
123  return Application.getApplication().isInRole("attach:new");
124  }
125 
126  public boolean getCanEdit() {
127  return Application.getApplication().isInRole("attach:edit");
128  }
129 
130  @Override
131  public void afterCompose() {
132  }
133 
134 }
void setAttachListener(AttachNavigatorListener listener)
AttachFolder addFolder(String label, String path, boolean loadOnDemand)