BrightSide Workbench Full Report + Source Code
navigator/FileTree.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.file.zul.navigator;
20 
21 import org.turro.elephant.context.Application;
22 import org.turro.file.zul.control.FileResults;
23 import org.zkoss.zk.ui.ext.AfterCompose;
24 import org.zkoss.zul.Tree;
25 import org.zkoss.zul.Treechildren;
26 
31 public class FileTree extends Tree implements AfterCompose {
32 
33  private Treechildren children;
34  private FileNavigatorListener fileListener;
35  private FileResults results;
36  private boolean doProcessors = true;
37 
38  public FileTree() {
39  super();
40  addChildrenSpace();
41  }
42 
44  return results;
45  }
46 
47  public void setResults(FileResults results) {
48  this.results = results;
49  }
50 
52  return fileListener;
53  }
54 
55  public void setFileListener(FileNavigatorListener listener) {
56  this.fileListener = listener;
57  }
58 
59  public void setDoProcessors(boolean doProcessors) {
60  this.doProcessors = doProcessors;
61  }
62 
63  public FileFolder addFolder(String label, String path, boolean loadOnDemand) {
64  FileFolder af = new FileFolder(label, path, loadOnDemand);
65  children.appendChild(af);
66  af.afterCompose();
67  if(doProcessors) af.doProcessors();
68  return af;
69  }
70 
72  if(getSelectedItem() instanceof FileFolder) {
73  return (FileFolder) getSelectedItem();
74  }
75  return null;
76  }
77 
78  public void setSelectedFolder(FileFolder folder) {
79  for(Object o : getItems()) {
80  if(o instanceof FileFolder) {
81  FileFolder af = (FileFolder) o;
82  if(af.getPath().equals(folder.getPath())) {
83  setSelectedItem(af);
84  break;
85  }
86  }
87  }
88  }
89 
91  for(Object o : getItems()) {
92  if(o instanceof FileFolder) {
93  FileFolder af = (FileFolder) o;
94  setSelectedItem(af);
95  return af;
96  }
97  }
98  return null;
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 FileFolder) {
113  ((FileFolder) o).reloadContents();
114  }
115  }
116  }
117 
118  public boolean getCanDelete() {
119  return Application.getApplication().isInRole("file-attach:delete");
120  }
121 
122  public boolean getCanNew() {
123  return Application.getApplication().isInRole("file-attach:new");
124  }
125 
126  public boolean getCanEdit() {
127  return Application.getApplication().isInRole("file-attach:edit");
128  }
129 
130  @Override
131  public void afterCompose() {
132  }
133 
134 }
135 
FileFolder addFolder(String label, String path, boolean loadOnDemand)
void setFileListener(FileNavigatorListener listener)
void setDoProcessors(boolean doProcessors)