BrightSide Workbench Full Report + Source Code
RepositoryTree.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2018 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.repository;
20 
21 import java.io.File;
22 import org.turro.string.Strings;
23 import org.turro.elephant.context.Application;
24 import org.turro.elephant.context.ElephantContext;
25 import org.turro.file.zul.control.FileResults;
26 import org.turro.file.zul.navigator.FileNavigatorListener;
27 import org.turro.i18n.I_;
28 import org.zkoss.zk.ui.ext.AfterCompose;
29 import org.zkoss.zul.Tree;
30 import org.zkoss.zul.Treechildren;
31 
36 public class RepositoryTree extends Tree implements AfterCompose {
37 
38  public static final String
39  REPOSITORY_DIR = "/_internal/repository",
40  REPOSITORY_PUBLICATION = "/_internal/UserFiles",
41  REPOSITORY_PUBLISHABLE = "/_internal/files";
42 
43  private Treechildren children;
44  private FileNavigatorListener fileListener;
45  private FileResults results;
46 
47  public RepositoryTree() {
48  super();
49  }
50 
52  return results;
53  }
54 
55  public void setResults(FileResults results) {
56  this.results = results;
57  }
58 
60  return fileListener;
61  }
62 
63  public void setFileListener(FileNavigatorListener listener) {
64  this.fileListener = listener;
65  }
66 
67  public void setPath(String path) {
68  if(Strings.isBlank(path)) return;
69  if("*".equals(path)) {
70  addFolder(I_.get("Root"), new File(ElephantContext.getRealPath("/")), REPOSITORY_DIR);
71  addFolder(I_.get("Publication"), new File(ElephantContext.getRealPath(REPOSITORY_PUBLICATION)), "");
72  addFolder(I_.get("Publishable"), new File(ElephantContext.getRealPath(REPOSITORY_PUBLISHABLE)), "");
73  } else {
74  addFolder(path, new File(ElephantContext.getRealPath(path)), REPOSITORY_DIR);
75  }
76  }
77 
78  private void addFolder(String name, File file, String path) {
79  children = getTreechildren();
80  if(children == null) {
81  children = new Treechildren();
82  appendChild(children);
83  }
84  children.appendChild(new RepositoryItem(file, name, path));
85  }
86 
88  if(getSelectedItem() instanceof RepositoryItem) {
89  return (RepositoryItem) getSelectedItem();
90  }
91  return null;
92  }
93 
94  public void setSelectedFolder(RepositoryItem folder) {
95  for(Object o : getItems()) {
96  if(o instanceof RepositoryItem) {
98  if(af.getRepositoryFile().getPath().equals(folder.getRepositoryFile().getPath())) {
99  setSelectedItem(af);
100  break;
101  }
102  }
103  }
104  }
105 
107  for(Object o : getItems()) {
108  if(o instanceof RepositoryItem) {
110  setSelectedItem(af);
111  return af;
112  }
113  }
114  return null;
115  }
116 
117  public void resetTree() {
118  if(children != null) children.getChildren().clear();
119  }
120 
121  public void reloadContents() {
122  for(Object o : children.getChildren()) {
123  if(o instanceof RepositoryItem) {
124  ((RepositoryItem) o).reloadContents();
125  }
126  }
127  }
128 
129  public boolean getCanDelete() {
130  return Application.getApplication().isInRole("file-attach:delete");
131  }
132 
133  public boolean getCanNew() {
134  return Application.getApplication().isInRole("file-attach:new");
135  }
136 
137  public boolean getCanEdit() {
138  return Application.getApplication().isInRole("file-attach:edit");
139  }
140 
141  @Override
142  public void afterCompose() {
143  }
144 
145 }
void setSelectedFolder(RepositoryItem folder)
void setFileListener(FileNavigatorListener listener)
static String get(String msg)
Definition: I_.java:41