18 package org.turro.attach.zul.navigator;
20 import org.turro.attach.zul.AttachmentUtil;
21 import org.turro.elephant.context.Application;
22 import org.turro.elephant.context.ElephantContext;
23 import org.turro.elephant.util.Messages;
24 import org.turro.i18n.I_;
25 import org.turro.util.CompareUtil;
26 import org.turro.zkoss.label.LabelTypes;
27 import org.zkoss.zk.ui.Component;
28 import org.zkoss.zk.ui.event.Event;
29 import org.zkoss.zk.ui.event.EventListener;
30 import org.zkoss.zk.ui.event.Events;
31 import org.zkoss.zul.*;
44 setStyle(
"cursor:pointer");
46 A a =
new A(folder.getLabel(),
"/_zul/images/folder.png");
47 a.addEventListener(Events.ON_CLICK,
new EventListener() {
49 public void onEvent(Event event)
throws Exception {
50 folder.
getTree().setSelectedItem(folder);
51 Events.postEvent(
new Event(Events.ON_SELECT, folder.
getTree()));
55 appendChild(getSizeComponent());
56 appendChild(
new Label(
""));
59 private boolean _listenerAttached =
false;
60 private boolean _onOpenTriggered =
false;
62 private void addDetail() {
63 final Detail detail =
new Detail();
66 detail.addEventListener(Events.ON_OPEN,
new EventListener() {
68 public void onEvent(Event event)
throws Exception {
69 _onOpenTriggered =
true;
74 if(!_listenerAttached) {
75 addEventListener(Events.ON_CLICK,
new EventListener<Event>() {
77 public void onEvent(Event event) throws Exception {
78 if(_onOpenTriggered) {
79 _onOpenTriggered = false;
82 folder.getTree().setSelectedItem(folder);
83 Events.postEvent(new Event(Events.ON_SELECT, folder.getTree()));
86 _listenerAttached =
true;
90 private void fillDetail(Detail detail) {
91 if(detail.getChildren().isEmpty()) {
92 Application app = Application.getApplication();
94 Vbox vbox =
new Vbox();
95 vbox.setSclass(
"detailBox");
96 vbox.setStyle(
"background-image:url('" +
97 ElephantContext.getCurrent().getContextPath() +
98 "/_zul/images/bg/sunken.png')");
99 detail.appendChild(vbox);
101 Hlayout buttons =
new Hlayout();
102 vbox.appendChild(buttons);
103 Toolbarbutton copy =
new Toolbarbutton(I_.get(
"Copy"),
"/_zul/images/edit-copy.png");
104 copy.addEventListener(Events.ON_CLICK,
new EventListener() {
106 public void onEvent(Event event)
throws Exception {
107 AttachmentUtil.copyFolder(folder.
getPath());
110 buttons.appendChild(copy);
111 Toolbarbutton cut =
new Toolbarbutton(I_.get(
"Cut"),
"/_zul/images/edit-cut.png");
112 cut.addEventListener(Events.ON_CLICK,
new EventListener() {
114 public void onEvent(Event event)
throws Exception {
115 AttachmentUtil.cutFolder(folder.getLabel(), folder.
getPath());
118 buttons.appendChild(cut);
119 final Toolbarbutton paste =
new Toolbarbutton(I_.get(
"Paste"),
"/_zul/images/edit-paste.png");
120 paste.setDisabled(!AttachmentUtil.hasClipboard());
121 paste.addEventListener(Events.ON_CLICK,
new EventListener() {
123 public void onEvent(Event event)
throws Exception {
124 AttachmentUtil.paste(folder.
getPath());
125 paste.setDisabled(
true);
128 buttons.appendChild(paste);
129 if(app.isInRole(
"attach:delete")) {
130 Toolbarbutton
delete =
new Toolbarbutton(I_.get(
"Delete"),
"/_zul/images/edit-delete.png");
131 delete.addEventListener(Events.ON_CLICK,
new EventListener() {
133 public void onEvent(Event event)
throws Exception {
134 Messages.confirmDeletion().show(() -> {
135 AttachmentUtil.delete(folder.
getPath());
136 FolderRow.this.detach();
140 buttons.appendChild(
delete);
145 private Component getSizeComponent() {
146 FolderData fd =
new FolderData(folder.
getPath());
147 Vlayout vbox =
new Vlayout();
148 vbox.setSpacing(
"0px");
149 vbox.setStyle(
"text-align:right");
150 String size =
new org.turro.formatter.BytesFormatter(fd.getSize()).toString(),
151 versioned =
new org.turro.formatter.BytesFormatter(fd.getVersionedSize()).toString();
152 vbox.appendChild(
new Label(size));
153 if(CompareUtil.compare(size, versioned) != 0) {
154 vbox.appendChild(LabelTypes.getTinyLabel(versioned));
FolderRow(final AttachFolder folder)