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.elephant.context.Application;
28 import org.turro.elephant.context.ElephantContext;
29 import org.turro.elephant.util.Messages;
30 import org.turro.file.zul.FileClipboard;
31 import org.turro.file.zul.repository.RepositoryGrid;
32 import org.turro.file.zul.repository.RepositoryItem;
33 import org.turro.file.zul.repository.RepositoryTree;
34 import org.turro.i18n.I_;
35 import org.turro.mail.recipients.SendAttachments;
36 import org.turro.zip.Compress;
37 import org.zkoss.zk.ui.Executions;
38 import org.zkoss.zk.ui.IdSpace;
39 import org.zkoss.zk.ui.event.UploadEvent;
40 import org.zkoss.zk.ui.ext.AfterCompose;
41 import org.zkoss.zk.ui.select.Selectors;
42 import org.zkoss.zk.ui.select.annotation.Listen;
43 import org.zkoss.zk.ui.select.annotation.Wire;
44 import org.zkoss.zul.Filedownload;
45 import org.zkoss.zul.Menuitem;
46 import org.zkoss.zul.Panel;
47 import org.zkoss.zul.Textbox;
48 import org.zkoss.zul.Toolbarbutton;
49 import org.zkoss.zul.West;
57 private boolean publicOnly, readOnly, treeCollapsed, entity;
59 private String label, path;
63 private West panelFolder;
66 private Textbox searchValue;
69 private Menuitem regexp;
72 private Menuitem fullpath;
75 private Menuitem partial;
78 private Toolbarbutton levelUp;
81 private Toolbarbutton newFolder;
84 private Toolbarbutton upload;
87 private Toolbarbutton send;
90 private Toolbarbutton download;
93 private Toolbarbutton copy;
96 private Toolbarbutton cut;
99 private Toolbarbutton paste;
102 private Toolbarbutton
delete;
110 @Listen(
"onChange = #treeFolder")
113 if(currentFolder ==
null) {
124 @Listen(
"onSelect = #treeFolder")
131 @Listen(
"onChange = #searchValue")
136 @Listen(
"onCheck = #regexp")
141 @Listen(
"onCheck = #fullpath")
143 results.
setPath(fullpath.isChecked());
146 @Listen(
"onCheck = #partial")
151 @Listen(
"onClick = #search; onOK = #searchValue")
157 @Listen(
"onClick = #levelUp")
159 if(currentFolder !=
null && currentFolder.getParentItem() !=
null) {
161 treeFolder.setSelectedItem(currentFolder);
167 @Listen(
"onClick = #newFolder")
169 if(currentFolder !=
null) {
176 @Listen(
"onUpload = #upload")
177 public
void onUpload(UploadEvent event) throws Exception {
178 if(currentFolder !=
null) {
179 currentFolder.
addMedias(event.getMedias());
184 @Listen(
"onClick = #send")
188 protected void fillAttachment(File attachment, Object entity) {
190 FileUtils.copyFile((File) entity, attachment);
191 }
catch (IOException ex) {
205 @Listen(
"onClick = #download")
209 File targetZip = File.createTempFile(
"attach_",
"_folder.zip");
210 Compress.zip(af.
getRealFolder().toPath(), targetZip.toPath());
211 Filedownload.save(targetZip,
"application/zip");
215 @Listen(
"onClick = #copy")
220 @Listen(
"onClick = #cut")
221 public
void onCut() throws Exception {
225 @Listen(
"onClick = #paste")
228 treeFolder.setSelectedItem(currentFolder);
231 paste.setDisabled(
true);
234 @Listen(
"onClick = #delete")
238 for(File f : currentFolder.
getFiles()) {
240 if(treeFolder.getFileListener() != null) {
241 treeFolder.getFileListener().deleteDone(f);
244 treeFolder.setSelectedItem(currentFolder);
250 @Listen(
"onUpload = #dropUpload")
251 public
void onEvent(UploadEvent event) throws Exception {
252 if(currentFolder !=
null) {
253 currentFolder.addMedias(event.getMedias());
254 fileGrid.setCurrentFolder(currentFolder);
259 Executions.createComponents(
"/WEB-INF/_zul/bs/comps/attachment/repositoryControl.zul",
this,
null);
260 Selectors.wireComponents(
this,
this,
false);
261 Selectors.wireEventListeners(
this,
this);
269 this.publicOnly = publicOnly;
277 this.readOnly = readOnly;
281 return treeCollapsed;
285 this.treeCollapsed = treeCollapsed;
302 treeFolder.resetTree();
303 treeFolder.setPath(Strings.isBlank(path,
"/"));
314 panelFolder.setOpen(!treeCollapsed);
317 private void initResults() {
321 private void initComponents() {
322 treeFolder.setResults(results);
323 searchValue.setValue(results.getSearchValue());
324 regexp.setChecked(results.isRegexp());
325 fullpath.setChecked(results.isPath());
326 partial.setChecked(results.isPartial());
327 fileGrid.setReadOnly(readOnly);
332 currentFolder = treeFolder.selectFirst();
334 fileGrid.setCurrentFolder(currentFolder);
337 private void updateButtons() {
338 newFolder.setDisabled(currentFolder ==
null || readOnly);
339 upload.setDisabled(currentFolder ==
null || readOnly);
340 send.setDisabled(currentFolder ==
null);
342 levelUp.setDisabled(currentFolder ==
null || currentFolder.getParentItem() ==
null);
343 copy.setDisabled(currentFolder ==
null);
344 cut.setDisabled(currentFolder ==
null || readOnly);
347 delete.setDisabled(currentFolder ==
null || currentFolder.getParentFolder() ==
null || readOnly);
boolean isInRole(String role)
static Application getApplication()
static String logMsg(String msg)
static Messages confirmDeletion()
static void copyFolder(File value)
static void paste(File folder)
static boolean hasClipboard()
static void cutFolder(String name, final File value)
void setPath(boolean path)
void setSearchValue(String searchValue)
void setPartial(boolean partial)
void setRegexp(boolean regexp)
void setTreeCollapsed(boolean treeCollapsed)
RepositoryTree getTreeFolder()
boolean isTreeCollapsed()
void setReadOnly(boolean readOnly)
void onUpload(UploadEvent event)
void setPath(String path)
void setPublicOnly(Boolean publicOnly)
void setLabel(String label)
RepositoryItem getCurrentFolder()
void setCurrentFolder(RepositoryItem currentFolder)
Collection< File > getFiles()
void addMedias(Media[] medias)
RepositoryItem getParentFolder()
RepositoryItem selectFirst()
RepositoryItem getSelectedFolder()
static String get(String msg)
void addAttachment(Object entity, String path, String name)
void sendAttachments(Collection< IContact > contacts)