18 package org.turro.attach.zul.tree;
20 import java.util.EnumSet;
22 import org.turro.attach.entity.Attachment;
23 import org.turro.attach.search.AttachResults;
24 import org.turro.elephant.context.Application;
25 import org.turro.i18n.I_;
26 import org.zkoss.zk.ui.event.Event;
27 import org.zkoss.zk.ui.event.EventListener;
28 import org.zkoss.zk.ui.event.Events;
29 import org.zkoss.zul.Checkbox;
30 import org.zkoss.zul.Separator;
31 import org.zkoss.zul.Space;
32 import org.zkoss.zul.Textbox;
33 import org.zkoss.zul.Toolbar;
34 import org.zkoss.zul.Toolbarbutton;
35 import org.zkoss.zul.Tree;
36 import org.zkoss.zul.Treechildren;
37 import org.zkoss.zul.Treecol;
38 import org.zkoss.zul.Treecols;
47 private Treechildren children;
48 private Set<AttachColumn> columns;
49 private Toolbar toolbar;
50 private Toolbarbutton addFolderButton, uploadButton, downloadButton,
51 editButton, deleteButton;
55 private boolean onlyDownload =
false, publicOnly =
false;
65 public AttachTree(String title, Set<AttachColumn> columns,
boolean publicOnly) {
68 this.columns = columns;
78 return attachListener;
82 this.attachListener = listener;
87 toolbar =
new Toolbar();
88 getParent().insertBefore(toolbar,
AttachTree.this);
90 addSearchbarButtons();
91 toolbar.appendChild(
new Space());
95 addEventListener(Events.ON_SELECT,
new EventListener() {
97 public void onEvent(Event event)
throws Exception {
101 }
else if(onlyDownload && getSelectedItem() instanceof
AttachFile) {
102 ((
AttachFile) getSelectedItem()).doDownload();
113 this.onlyDownload = onlyDownload;
118 children.appendChild(af);
129 return ((
AttachFile) getSelectedItem()).getAttachment();
138 private void addColumns() {
139 Treecols cols =
new Treecols();
140 cols.setSizable(
true);
143 Treecol col =
new Treecol();
144 col.setLabel(title ==
null ?
"" : title);
145 cols.appendChild(col);
149 col.setLabel(
I_.
get(
"Size"));
150 col.setWidth(
"70px");
151 cols.appendChild(col);
153 if(columns.contains(AttachColumn.ATTACH_DATE)) {
155 col.setLabel(
I_.
get(
"Date"));
156 col.setWidth(
"90px");
157 cols.appendChild(col);
159 if(columns.contains(AttachColumn.ATTACH_VALIDATED)) {
161 col.setLabel(I_.get(
"Validated"));
162 col.setWidth(
"25px");
163 cols.appendChild(col);
165 if(columns.contains(AttachColumn.ATTACH_OWNER)) {
167 col.setLabel(I_.get(
"Owner"));
168 col.setWidth(
"200px");
169 cols.appendChild(col);
173 private void addChildrenSpace() {
174 children =
new Treechildren();
175 appendChild(children);
178 private void addToolbarButtons() {
180 addFolderButton =
new Toolbarbutton(
181 I_.get(
"Add folder"),
182 "/_zul/images/new.png"
184 toolbar.appendChild(addFolderButton);
185 addFolderButton.addEventListener(Events.ON_CLICK,
new EventListener() {
187 public void onEvent(Event event)
throws Exception {
188 if(
AttachTree.this.getSelectedItem() instanceof AttachFolder) {
189 ((AttachFolder)
AttachTree.this.getSelectedItem()).doAddFolder();
196 uploadButton =
new Toolbarbutton(
198 "/_zul/images/upload.png"
200 toolbar.appendChild(uploadButton);
201 uploadButton.addEventListener(Events.ON_CLICK,
new EventListener() {
203 public void onEvent(Event event)
throws Exception {
204 if(
AttachTree.this.getSelectedItem() instanceof AttachFolder) {
205 ((AttachFolder)
AttachTree.this.getSelectedItem()).doUpload();
213 downloadButton =
new Toolbarbutton(
215 "/_zul/images/download.png"
217 toolbar.appendChild(downloadButton);
218 downloadButton.addEventListener(Events.ON_CLICK,
new EventListener() {
221 public void onEvent(Event event)
throws Exception {
222 if(
AttachTree.this.getSelectedItem() instanceof AttachFile) {
223 ((AttachFile)
AttachTree.this.getSelectedItem()).doDownload();
232 editButton =
new Toolbarbutton(
234 "/_zul/images/edit.png"
236 toolbar.appendChild(editButton);
237 editButton.addEventListener(Events.ON_CLICK,
new EventListener() {
240 public void onEvent(Event event)
throws Exception {
241 if(
AttachTree.this.getSelectedItem() instanceof AttachFile) {
242 ((AttachFile)
AttachTree.this.getSelectedItem()).doEdit();
267 deleteButton =
new Toolbarbutton(
269 "/_zul/images/edit-delete.png"
271 toolbar.appendChild(deleteButton);
272 deleteButton.addEventListener(Events.ON_CLICK,
new EventListener() {
275 public void onEvent(Event event)
throws Exception {
276 if(
AttachTree.this.getSelectedItem() instanceof AttachFile) {
277 ((AttachFile)
AttachTree.this.getSelectedItem()).doDelete();
290 if(toolbar !=
null) {
291 boolean isFolder = getSelectedItem() instanceof
AttachFolder,
292 isFile = getSelectedItem() instanceof
AttachFile;
294 if(addFolderButton !=
null) addFolderButton.setVisible(isFolder);
295 if(uploadButton !=
null) uploadButton.setVisible(isFolder);
297 downloadButton.setVisible(isFile);
299 if(editButton !=
null) editButton.setVisible(isFile);
301 if(deleteButton !=
null) deleteButton.setVisible(isFile);
306 private void addSearchbarButtons() {
308 if(results !=
null) {
311 final Checkbox showAll =
new Checkbox(
I_.
get(
"Others"));
313 showAll.setStyle(
"font-size:11px");
314 showAll.addEventListener(Events.ON_CHECK,
new EventListener() {
316 public void onEvent(Event event)
throws Exception {
320 toolbar.appendChild(showAll);
323 toolbar.appendChild(
new Separator(
"vertical"));
325 final Checkbox showNonValidated =
new Checkbox(I_.get(
"Non validated"));
327 showNonValidated.setStyle(
"font-size:11px");
328 showNonValidated.addEventListener(Events.ON_CHECK,
new EventListener() {
330 public void onEvent(Event event)
throws Exception {
334 toolbar.appendChild(showNonValidated);
336 toolbar.appendChild(
new Separator(
"vertical"));
338 final Textbox attachValue =
new Textbox(results.
getAttachValue());
339 attachValue.setStyle(
"font-size:11px");
340 attachValue.addEventListener(Events.ON_CHANGE,
new EventListener() {
342 public void onEvent(Event event)
throws Exception {
346 attachValue.addEventListener(Events.ON_OK,
new EventListener() {
348 public void onEvent(Event event)
throws Exception {
349 for(Object o : children.getChildren()) {
350 if(o instanceof AttachFolder) {
351 ((AttachFolder) o).reloadContents();
356 toolbar.appendChild(attachValue);
358 Toolbarbutton searchButton =
new Toolbarbutton(
360 "/_zul/images/search.png"
362 searchButton.addEventListener(Events.ON_CLICK,
new EventListener() {
364 public void onEvent(Event event)
throws Exception {
365 for(Object o : children.getChildren()) {
366 if(o instanceof AttachFolder) {
367 ((AttachFolder) o).reloadContents();
372 toolbar.appendChild(searchButton);
void setPublicOnly(boolean publicOnly)
void setAttachValue(String attachValue)
void setCkOthers(boolean ckOthers)
void setCkNonValidated(boolean ckNonValidated)
boolean isCkNonValidated()
AttachListener getAttachListener()
Attachment getSelectedAttachment()
AttachTree(String title, Set< AttachColumn > columns, boolean publicOnly)
AttachFolder addFolder(String label, String path, boolean loadOnDemand)
void setOnlyDownload(boolean onlyDownload)
AttachResults getResults()
Set< AttachColumn > getColumns()
void setAddToolbar(boolean addToolbar)
void setAttachListener(AttachListener listener)
boolean isInRole(String role)
static Application getApplication()
static String get(String msg)