19 package org.turro.file.zul.navigator;
22 import java.io.IOException;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.logging.Level;
26 import java.util.logging.Logger;
27 import org.apache.commons.io.FileUtils;
28 import org.turro.attach.zul.FolderNameCombobox;
29 import org.turro.collections.CollectionUtil;
30 import org.turro.command.Command;
31 import org.turro.command.Context;
32 import org.turro.elephant.context.Application;
33 import org.turro.elephant.context.ElephantContext;
34 import org.turro.elephant.impl.util.StringParser;
35 import org.turro.elephant.util.Messages;
36 import org.turro.entities.Entities;
37 import org.turro.file.zul.control.FileResults;
38 import org.turro.i18n.I_;
39 import org.turro.plugin.attach.IAttachFolder;
40 import org.turro.upload.Medias;
41 import org.turro.zkoss.dialog.InputDialog;
42 import org.turro.zkoss.dialog.InputField;
43 import org.zkoss.lang.Strings;
44 import org.zkoss.util.media.Media;
45 import org.zkoss.zk.ui.HtmlBasedComponent;
46 import org.zkoss.zk.ui.event.DropEvent;
47 import org.zkoss.zk.ui.event.Event;
48 import org.zkoss.zk.ui.event.EventListener;
49 import org.zkoss.zk.ui.event.Events;
50 import org.zkoss.zk.ui.ext.AfterCompose;
51 import org.zkoss.zul.Treecell;
52 import org.zkoss.zul.Treechildren;
53 import org.zkoss.zul.Treeitem;
54 import org.zkoss.zul.Treerow;
64 private Treechildren children;
65 private String label, realLabel;
67 private boolean loadOnDemand;
69 public FileFolder(String label, String path,
boolean loadOnDemand) {
72 this.realLabel = label;
74 this.loadOnDemand = loadOnDemand;
75 this.setTooltiptext(label);
79 throw new UnsupportedOperationException(
"Do not use");
83 throw new UnsupportedOperationException(
"Do not use");
87 throw new UnsupportedOperationException(
"Do not use");
95 public void addMedias(Media[] medias)
throws InterruptedException, IOException {
96 if(medias ==
null || medias.length == 0)
return;
99 for(Media media : medias) {
110 new InputField(
"Name",
"", null, 0) {
112 protected HtmlBasedComponent createEditor() {
113 return new FolderNameCombobox(FileFolder.this);
118 public Object execute(Context context) {
120 if(fields.length > 0) {
122 if(
"Name".equals(f.getLabel())) {
125 for(String s : ((String) f.getValue()).split(
"\\/")) {
126 if(!Strings.isBlank(s)) {
141 if(children ==
null) {
142 children =
new Treechildren();
143 appendChild(children);
145 children.appendChild(af);
157 if(children !=
null) {
158 children.getChildren().clear();
163 private void addCells() {
164 Treerow row =
new Treerow();
165 row.setDroppable(
"true");
166 row.addEventListener(Events.ON_DROP,
new EventListener() {
168 public void onEvent(Event event)
throws Exception {
169 final DropEvent dp = (DropEvent) event;
170 if(dp.getDragged() instanceof
FileRow) {
175 FileUtils.moveFileToDirectory(row.
getFile(), getRealFolder(
true),
false);
177 }
catch (IOException ex) {
185 Treecell cell =
new Treecell(label);
186 cell.setImage(
"/_zul/images/folder.png");
187 row.appendChild(cell);
190 private void addChildrenSpace() {
192 children =
new Treechildren();
193 appendChild(children);
206 this.loadOnDemand = loadOnDemand;
217 private void initLoadOnDemand() {
218 if(!loadOnDemand)
return;
222 addEventListener(Events.ON_OPEN,
new EventListener() {
224 public void onEvent(Event event)
throws Exception {
233 private void fillFolder() {
234 if(children !=
null && children.getChildren().isEmpty()) {
235 for(String s : getFolders()) {
236 addFolder(s, path +
"/" + s);
262 String shortPath = getPath();
263 if(shortPath.startsWith(
"/_internal/files")) {
264 shortPath = shortPath.substring(16);
265 }
else if(shortPath.startsWith(
"/WEB-INF/files")) {
266 shortPath = shortPath.substring(14);
276 return getFolders().isEmpty();
280 File folder = getRealFolder(
true);
287 return children !=
null ? CollectionUtil.from(children.getChildren()).<Collection<FileFolder>>cast() :
new ArrayList<>();
291 File folder = getRealFolder(
true);
309 return getRealFolder(
false);
314 if(!folder.exists()) {
static Application getApplication()
static String getRealPath(String path)
static String logMsg(String msg)
static String cutString(String value, int maxChars)
static Messages confirmMove()
static IElephantEntity getController(String path)
Collection< String > getFolders(File folder)
Collection< File > getFiles(File folder)
Collection< File > getFileList(File folder)
FileFolder(String label, Object value)
FileFolder(String label, String path, boolean loadOnDemand)
Collection< FileFolder > getFileFolders()
void setPath(String path)
void addMedias(Media[] medias)
Collection< String > getFolders()
FileFolder addFolder(String label, String path)
Collection< File > getFiles()
void setLoadOnDemand(boolean loadOnDemand)
Collection< File > getFilesFrom(File folder)
File getRealFolder(boolean create)
IAttachFolder getParentFolder()
void setFolderLabel(String label)
static String get(String msg)