19 package org.turro.file.zul.control;
22 import java.io.IOException;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import org.turro.string.Strings;
26 import org.apache.commons.io.FileUtils;
27 import org.turro.action.IEntityHolder;
28 import org.turro.elephant.context.Application;
29 import org.turro.elephant.context.ElephantContext;
30 import org.turro.elephant.util.Messages;
31 import org.turro.entities.Entities;
32 import org.turro.entities.IElephantEntity;
33 import org.turro.file.util.FileAttach;
34 import org.turro.file.zul.FileClipboard;
35 import org.turro.file.zul.navigator.FileFolder;
36 import org.turro.file.zul.navigator.FileNavigatorGrid;
37 import org.turro.file.zul.navigator.FileTree;
38 import org.turro.i18n.I_;
39 import org.turro.util.Chars;
40 import org.turro.mail.recipients.SendAttachments;
41 import org.turro.zip.Compress;
42 import org.zkoss.zk.ui.Executions;
43 import org.zkoss.zk.ui.IdSpace;
44 import org.zkoss.zk.ui.event.UploadEvent;
45 import org.zkoss.zk.ui.ext.AfterCompose;
46 import org.zkoss.zk.ui.select.Selectors;
47 import org.zkoss.zk.ui.select.annotation.Listen;
48 import org.zkoss.zk.ui.select.annotation.Wire;
49 import org.zkoss.zul.Filedownload;
50 import org.zkoss.zul.Menuitem;
51 import org.zkoss.zul.Panel;
52 import org.zkoss.zul.Textbox;
53 import org.zkoss.zul.Toolbarbutton;
54 import org.zkoss.zul.West;
62 private static final String SECURED =
"/#secure#/#forbidden#";
64 private boolean publicOnly, readOnly, treeCollapsed, entity;
66 private String label, path;
70 private West panelFolder;
73 private Textbox searchValue;
76 private Menuitem regexp;
79 private Menuitem fullpath;
82 private Menuitem partial;
85 private Toolbarbutton levelUp;
88 private Toolbarbutton newFolder;
91 private Toolbarbutton upload;
94 private Toolbarbutton send;
97 private Toolbarbutton download;
100 private Toolbarbutton copy;
103 private Toolbarbutton cut;
106 private Toolbarbutton paste;
109 private Toolbarbutton
delete;
117 @Listen(
"onChange = #treeFolder")
120 if(currentFolder ==
null) {
131 @Listen(
"onSelect = #treeFolder")
138 @Listen(
"onChange = #searchValue")
143 @Listen(
"onCheck = #regexp")
148 @Listen(
"onCheck = #fullpath")
150 results.
setPath(fullpath.isChecked());
153 @Listen(
"onCheck = #partial")
158 @Listen(
"onClick = #search; onOK = #searchValue")
164 @Listen(
"onClick = #levelUp")
166 if(currentFolder !=
null && currentFolder.getParentItem() !=
null) {
167 currentFolder = (
FileFolder) currentFolder.getParentItem();
168 treeFolder.setSelectedItem(currentFolder);
174 @Listen(
"onClick = #newFolder")
176 if(currentFolder !=
null) {
183 @Listen(
"onUpload = #upload")
184 public
void onUpload(UploadEvent event) throws Exception {
185 if(currentFolder !=
null) {
186 currentFolder.
addMedias(event.getMedias());
191 @Listen(
"onClick = #send")
195 protected void fillAttachment(File attachment, Object entity) {
197 FileUtils.copyFile((File) entity, attachment);
198 }
catch (IOException ex) {
212 @Listen(
"onClick = #download")
216 File targetZip = File.createTempFile(
"attach_",
"_folder.zip");
217 Compress.zip(af.
getRealFolder().toPath(), targetZip.toPath());
218 Filedownload.save(targetZip,
"application/zip");
222 @Listen(
"onClick = #copy")
227 @Listen(
"onClick = #cut")
228 public
void onCut() throws Exception {
232 @Listen(
"onClick = #paste")
235 treeFolder.setSelectedItem(currentFolder);
238 paste.setDisabled(
true);
241 @Listen(
"onClick = #delete")
245 for(File f : currentFolder.
getFiles()) {
247 if(treeFolder.getFileListener() != null) {
248 treeFolder.getFileListener().deleteDone(f);
251 treeFolder.setSelectedItem(currentFolder);
257 @Listen(
"onUpload = #dropUpload")
258 public
void onEvent(UploadEvent event) throws Exception {
259 if(currentFolder !=
null) {
260 currentFolder.addMedias(event.getMedias());
261 fileGrid.setCurrentFolder(currentFolder);
266 Executions.createComponents(
"/WEB-INF/_zul/bs/comps/attachment/fileControl.zul",
this,
null);
267 Selectors.wireComponents(
this,
this,
false);
268 Selectors.wireEventListeners(
this,
this);
277 this.publicOnly = publicOnly;
285 this.readOnly = readOnly;
289 return treeCollapsed;
293 this.treeCollapsed = treeCollapsed;
310 treeFolder.resetTree();
318 if(Strings.isBlank(path)) {
323 treeFolder.setDoProcessors(
false);
324 treeFolder.resetTree();
325 fileGrid.setCurrentFolder(
null);
341 panelFolder.setOpen(!treeCollapsed);
342 if(!SECURED.equals(path)) {
345 Chars.forward().spaced().toString() + label,
new FileAttach(path).getPublishable(),
true);
346 panelFolder.setTitle(label);
350 panelFolder.setTitle(label);
354 if(!Strings.isBlank(path)) {
355 String[] paths = path.split(
"\\|");
356 String[] labels = label.split(
"\\|");
357 for(
int i = 0; i < paths.length; i++) {
359 panelFolder.setTitle(labels[i]);
367 panelFolder.setTitle(
"");
368 treeFolder.resetTree();
369 fileGrid.setCurrentFolder(
null);
370 newFolder.setDisabled(
true);
371 upload.setDisabled(
true);
372 send.setDisabled(
true);
373 levelUp.setDisabled(
true);
374 copy.setDisabled(
true);
375 cut.setDisabled(
true);
376 paste.setDisabled(
true);
377 delete.setDisabled(
true);
381 private void initResults() {
385 private void initComponents() {
386 treeFolder.setResults(results);
387 searchValue.setValue(results.getSearchValue());
388 regexp.setChecked(results.isRegexp());
389 fullpath.setChecked(results.isPath());
390 partial.setChecked(results.isPartial());
391 fileGrid.setReadOnly(readOnly);
396 currentFolder = treeFolder.selectFirst();
398 fileGrid.setCurrentFolder(currentFolder);
401 private void updateButtons() {
402 newFolder.setDisabled(currentFolder ==
null || readOnly);
403 upload.setDisabled(currentFolder ==
null || readOnly);
406 levelUp.setDisabled(currentFolder ==
null || currentFolder.getParentItem() ==
null);
407 copy.setDisabled(currentFolder ==
null);
408 cut.setDisabled(currentFolder ==
null || readOnly);
411 delete.setDisabled(currentFolder ==
null || currentFolder.getParentFolder() ==
null || readOnly);
boolean isInRole(String role)
static Application getApplication()
static String logMsg(String msg)
static Messages confirmDeletion()
static IElephantEntity getController(String path)
static void copyFolder(File value)
static void paste(File folder)
static boolean hasClipboard()
static void cutFolder(String name, final File value)
void setEntity(Object entity)
void setTreeCollapsed(boolean treeCollapsed)
void setLabel(String label)
void setPublicOnly(Boolean publicOnly)
void onUpload(UploadEvent event)
void setReadOnly(boolean readOnly)
void setPath(String path)
boolean isTreeCollapsed()
void setPath(boolean path)
void setSearchValue(String searchValue)
void setPartial(boolean partial)
void setRegexp(boolean regexp)
void addMedias(Media[] medias)
FileFolder addFolder(String label, String path)
Collection< File > getFiles()
IAttachFolder getParentFolder()
void setCurrentFolder(FileFolder currentFolder)
FileFolder getCurrentFolder()
FileFolder getSelectedFolder()
static String get(String msg)
void addAttachment(Object entity, String path, String name)
void sendAttachments(Collection< IContact > contacts)