18 package org.turro.attach.zul.navigator;
21 import java.util.Collection;
22 import org.turro.attach.db.AttachPU;
23 import org.turro.attach.entity.Attachment;
24 import org.turro.attach.search.AttachResults;
25 import org.turro.attach.zul.AttachmentUtil;
26 import org.turro.elephant.context.Application;
27 import org.turro.elephant.context.ElephantContext;
28 import org.turro.elephant.util.Images;
29 import org.turro.elephant.util.Messages;
30 import org.turro.i18n.I_;
31 import org.turro.wd.entities.AttachWd;
32 import org.turro.mail.recipients.SendAttachments;
33 import org.zkoss.zk.ui.event.Event;
34 import org.zkoss.zk.ui.event.EventListener;
35 import org.zkoss.zk.ui.event.Events;
36 import org.zkoss.zk.ui.event.UploadEvent;
37 import org.zkoss.zk.ui.ext.AfterCompose;
38 import org.zkoss.zkmax.zul.Dropupload;
39 import org.zkoss.zul.*;
49 private Borderlayout layout;
50 private Center center;
53 private Panel centerPanel, navPanel;
56 private Toolbar toolbar, searchbar;
57 private Toolbarbutton addFolderButton, uploadButton, sendButton, upButton,
58 copyButton, cutButton, pasteButton, deleteButton;
60 private Dropupload dropupload;
63 private boolean vertical =
false, workingDirOption =
true, publicOnly =
false;
73 this.vertical = vertical;
77 return workingDirOption;
81 this.workingDirOption = workingDirOption;
89 this.publicOnly = publicOnly;
96 private void addComponents() {
97 if(getPanelchildren() ==
null) {
98 appendChild(
new Panelchildren());
100 getPanelchildren().getChildren().clear();
103 layout =
new Borderlayout();
104 getPanelchildren().appendChild(layout);
108 north.setBorder(
"none");
109 north.setSplittable(
true);
110 north.setSize(
"150px");
111 layout.appendChild(north);
114 west.setBorder(
"none");
115 west.setSplittable(
true);
116 west.setSize(
"280px");
117 layout.appendChild(west);
119 center =
new Center();
120 center.setBorder(
"none");
121 layout.appendChild(center);
123 centerPanel =
new Panel();
124 centerPanel.setVflex(
"true");
125 centerPanel.appendChild(
new Panelchildren());
127 center.appendChild(centerPanel);
129 navPanel =
new Panel();
130 navPanel.setVflex(
"true");
131 navPanel.appendChild(
new Panelchildren());
134 north.appendChild(navPanel);
136 west.appendChild(navPanel);
139 attachTree =
new AttachTree();
140 attachTree.setSclass(
"treeMenu");
141 attachTree.setVflex(
true);
143 attachTree.addEventListener(Events.ON_SELECT,
new EventListener() {
145 public void onEvent(Event event)
throws Exception {
152 navPanel.getPanelchildren().appendChild(attachTree);
155 searchbar =
new Toolbar();
156 navPanel.addToolbar(
"tbar", searchbar);
158 final Textbox attachValue =
new Textbox(results.
getAttachValue());
159 attachValue.setStyle(
"font-size:11px");
160 attachValue.addEventListener(Events.ON_CHANGE,
new EventListener() {
162 public void onEvent(Event event)
throws Exception {
166 attachValue.addEventListener(Events.ON_OK,
new EventListener() {
168 public void onEvent(Event event)
throws Exception {
173 searchbar.appendChild(attachValue);
175 Toolbarbutton searchButton =
new Toolbarbutton();
176 searchButton.setImage(
"/_zul/images/search.png");
177 searchButton.setTooltiptext(I_.get(
"Search"));
178 searchButton.addEventListener(Events.ON_CLICK,
new EventListener() {
180 public void onEvent(Event event)
throws Exception {
185 searchbar.appendChild(searchButton);
187 final Checkbox showNonValidated =
new Checkbox(I_.get(
"Non validated"));
189 showNonValidated.setStyle(
"font-size:11px");
190 showNonValidated.addEventListener(Events.ON_CHECK,
new EventListener() {
192 public void onEvent(Event event)
throws Exception {
196 searchbar.appendChild(showNonValidated);
198 if(workingDirOption) {
199 searchbar.appendChild(
new Space());
201 wdButton =
new A(I_.get(
"Create on Working directory"),
"/_zul/images/working-dir-move.png");
202 wdButton.setTarget(
"_new");
203 searchbar.appendChild(wdButton);
217 toolbar =
new Toolbar();
218 centerPanel.addToolbar(
"tbar", toolbar);
220 upButton =
new Toolbarbutton();
221 upButton.setImage(
"/_zul/images/arrow-up.png");
222 upButton.setDisabled(
true);
223 toolbar.appendChild(upButton);
224 upButton.addEventListener(Events.ON_CLICK,
new EventListener() {
226 public void onEvent(Event event)
throws Exception {
227 if(currentFolder !=
null && currentFolder.getParentItem() !=
null) {
228 currentFolder = (AttachFolder) currentFolder.getParentItem();
229 attachTree.setSelectedItem(currentFolder);
236 toolbar.appendChild(
new Space());
238 addFolderButton =
new Toolbarbutton(I_.get(
"Add folder"),
"/_zul/images/folder-new.png");
239 addFolderButton.setDisabled(
true);
240 toolbar.appendChild(addFolderButton);
241 addFolderButton.addEventListener(Events.ON_CLICK,
new EventListener() {
243 public void onEvent(Event event)
throws Exception {
244 if(currentFolder !=
null) {
251 uploadButton =
new Toolbarbutton(I_.get(
"Upload"),
"/_zul/images/upload.png");
252 uploadButton.setDisabled(
true);
253 toolbar.appendChild(uploadButton);
254 uploadButton.addEventListener(Events.ON_CLICK,
new EventListener() {
256 public void onEvent(Event event)
throws Exception {
257 if(currentFolder !=
null) {
265 sendButton =
new Toolbarbutton(I_.get(
"Send notification"),
"/_zul/images/mail_send.png");
266 sendButton.setDisabled(
true);
267 toolbar.appendChild(sendButton);
268 sendButton.addEventListener(Events.ON_CLICK,
new EventListener() {
270 public void onEvent(Event event)
throws Exception {
271 SendAttachments sa =
new SendAttachments(I_.get(
"Attachment")) {
273 protected void fillAttachment(File attachment, Object entity) {
274 AttachWd.writeToFile((Attachment) entity, attachment);
279 for(Attachment a : af.getAttachments()) {
280 sa.addAttachment(a, AttachPU.getObjectPath(a), a.getFileName());
283 sa.sendAttachments(
null);
287 toolbar.appendChild(
new Space());
289 copyButton =
new Toolbarbutton(I_.get(
"Copy"),
"/_zul/images/edit-copy.png");
290 copyButton.setDisabled(
true);
291 copyButton.addEventListener(Events.ON_CLICK,
new EventListener() {
293 public void onEvent(Event event)
throws Exception {
294 AttachmentUtil.copyFolder(currentFolder.
getPath());
297 toolbar.appendChild(copyButton);
299 cutButton =
new Toolbarbutton(I_.get(
"Cut"),
"/_zul/images/edit-cut.png");
300 cutButton.setDisabled(
true);
301 cutButton.addEventListener(Events.ON_CLICK,
new EventListener() {
303 public void onEvent(Event event)
throws Exception {
304 AttachmentUtil.cutFolder(currentFolder.getLabel(), currentFolder.
getPath());
307 toolbar.appendChild(cutButton);
309 pasteButton =
new Toolbarbutton(I_.get(
"Paste"),
"/_zul/images/edit-paste.png");
310 pasteButton.setDisabled(
true);
311 toolbar.appendChild(pasteButton);
312 pasteButton.addEventListener(Events.ON_CLICK,
new EventListener() {
314 public void onEvent(Event event)
throws Exception {
315 AttachmentUtil.paste(currentFolder.
getPath());
316 attachTree.setSelectedItem(currentFolder);
319 pasteButton.setDisabled(
true);
323 if(Application.getApplication().isInRole(
"attach:delete")) {
324 deleteButton =
new Toolbarbutton(I_.get(
"Delete"),
"/_zul/images/edit-delete.png");
325 deleteButton.setDisabled(
true);
326 deleteButton.addEventListener(Events.ON_CLICK,
new EventListener() {
328 public void onEvent(Event event)
throws Exception {
329 Messages.confirmDeletion().show(() -> {
330 Collection<Attachment> deleted = AttachmentUtil.delete(currentFolder.
getPath());
332 for(Attachment a : deleted) {
333 attachTree.getAttachListener().deleteDone(a);
336 attachTree.setSelectedItem(currentFolder);
341 toolbar.appendChild(deleteButton);
344 dropupload =
new Dropupload();
345 dropupload.setDetection(
"browser");
346 dropupload.setNative(
true);
347 dropupload.setContent(
348 "<table border='0' cellpadding='10' style='width:100%;background-color:#e1e1e1;'><tr><td style='width:84px;border:none;'><img border='0' src='" +
349 ElephantContext.getRootWebPath() + Images.getImage(
"64/downloads") +
350 "'/></td><td style='border:none;' class='textShadow textCaption1'>" + I_.get(
"Drop files") +
"</td></tr></table>");
351 dropupload.setMaxsize(-1);
352 dropupload.setHeight(
"84px");
353 dropupload.setWidth(
"100%");
354 dropupload.addEventListener(Events.ON_UPLOAD,
new EventListener<UploadEvent>() {
356 public void onEvent(UploadEvent event) throws Exception {
357 if(currentFolder != null) {
358 currentFolder.addMedias(event.getMedias());
359 attachGrid.setCurrentFolder(currentFolder);
363 centerPanel.getPanelchildren().appendChild(dropupload);
365 attachGrid =
new AttachNavigatorGrid();
366 attachGrid.setVflex(
true);
368 centerPanel.getPanelchildren().appendChild(attachGrid);
372 private void initResults() {
373 results =
new AttachResults();
379 private void updateButtons() {
380 addFolderButton.setDisabled(currentFolder ==
null);
381 uploadButton.setDisabled(currentFolder ==
null);
382 sendButton.setDisabled(currentFolder ==
null);
383 upButton.setDisabled(currentFolder ==
null || currentFolder.getParentItem() ==
null);
384 copyButton.setDisabled(currentFolder ==
null);
385 cutButton.setDisabled(currentFolder ==
null);
386 pasteButton.setDisabled(!AttachmentUtil.hasClipboard());
387 if(deleteButton !=
null) {
388 deleteButton.setDisabled(currentFolder ==
null || currentFolder.
getParentFolder() ==
null);
405 if(wdButton !=
null) {
void setPublicOnly(boolean publicOnly)
void setAttachValue(String attachValue)
void setCkOthers(boolean ckOthers)
void setCkNonValidated(boolean ckNonValidated)
boolean isCkNonValidated()
IAttachFolder getParentFolder()
AttachFolder getCurrentFolder()
void setCurrentFolder(AttachFolder currentFolder)
void setVertical(boolean vertical)
boolean isWorkingDirOption()
void setPublicOnly(boolean publicOnly)
AttachTree getAttachTree()
void setWorkingDirOption(boolean workingDirOption)
AttachFolder selectFirst()
AttachFolder getSelectedFolder()
void setResults(AttachResults results)
AttachNavigatorListener getAttachListener()