18 package org.turro.attach.zul.tree;
20 import java.io.ByteArrayOutputStream;
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.util.Date;
25 import org.apache.commons.io.input.ReaderInputStream;
26 import org.turro.attach.db.AttachPU;
27 import org.turro.attach.entity.AttachContent;
28 import org.turro.attach.entity.Attachment;
29 import org.turro.attach.search.AttachResults;
30 import org.turro.attach.zul.FolderNameCombobox;
31 import org.turro.command.Command;
32 import org.turro.command.Context;
33 import org.turro.elephant.context.Application;
34 import org.turro.elephant.impl.util.StringParser;
35 import org.turro.elephant.util.ZkossUtils;
36 import org.turro.entities.Entities;
37 import org.turro.i18n.I_;
38 import org.turro.log.SystemLogType;
39 import org.turro.log.SystemLogger;
40 import org.turro.plugin.attach.IAttachFolder;
41 import org.turro.zkoss.dialog.InputDialog;
42 import org.turro.zkoss.dialog.InputField;
43 import org.zkoss.lang.Strings;
44 import org.zkoss.util.media.Media;
45 import org.zkoss.zk.ui.HtmlBasedComponent;
46 import org.zkoss.zk.ui.event.DropEvent;
47 import org.zkoss.zk.ui.event.Event;
48 import org.zkoss.zk.ui.event.EventListener;
49 import org.zkoss.zk.ui.event.Events;
50 import org.zkoss.zul.*;
61 private Treechildren children;
62 private String label, realLabel;
64 private boolean loadOnDemand;
65 private Set<AttachColumn> columns;
67 public AttachFolder(String label, String path,
boolean loadOnDemand, Set<AttachColumn> columns) {
70 this.realLabel = label;
72 this.loadOnDemand = loadOnDemand;
73 this.columns = columns;
80 throw new UnsupportedOperationException(
"Do not use");
84 throw new UnsupportedOperationException(
"Do not use");
88 throw new UnsupportedOperationException(
"Do not use");
96 public void doUpload() throws InterruptedException, IOException {
97 Media[] medias = Fileupload.get(-1,
true);
98 if(medias ==
null || medias.length == 0)
return;
101 for(Media media : medias) {
110 if(media.inMemory()) {
111 ac.
setFileContent(media.isBinary() ? media.getByteData() : media.getStringData().getBytes());
113 byte[] buffer =
new byte[102400];
114 InputStream is = media.isBinary() ? media.getStreamData() :
new ReaderInputStream(media.getReaderData());
115 ByteArrayOutputStream baos =
new ByteArrayOutputStream();
117 while((r = is.read(buffer)) != -1) {
118 baos.write(buffer, 0, r);
128 attachment =
new AttachPU().saveObject(attachment);
131 if(
getTree().getAttachListener() !=
null) {
142 new InputField(
"Name",
"", null, 0) {
144 protected HtmlBasedComponent createEditor() {
145 return new FolderNameCombobox(AttachFolder.this);
150 public Object execute(Context context) {
152 if(fields.length > 0) {
154 if(
"Name".equals(f.getLabel())) {
157 for(String s : ((String) f.getValue()).split(
"\\/")) {
158 if(!Strings.isBlank(s)) {
173 children.appendChild(af);
180 children.appendChild(af);
191 children.getChildren().clear();
193 getTree().updateButtons();
196 private void addCells() {
197 Treerow row =
new Treerow();
198 row.setDroppable(
"true");
199 row.addEventListener(Events.ON_DROP,
new EventListener() {
201 public void onEvent(Event event)
throws Exception {
202 final DropEvent dp = (DropEvent) event;
203 if(dp.getDragged().getParent() instanceof
AttachFile) {
206 public Object execute(Context context) {
210 a.
setPath(Strings.isEmpty(getPath()) ?
"/" : getPath());
212 children.insertBefore(af, children.getFirstChild());
220 Treecell cell =
new Treecell(label);
221 row.appendChild(cell);
222 if(columns.contains(AttachColumn.ATTACH_SIZE)) {
223 row.appendChild(
new Treecell(
""));
225 if(columns.contains(AttachColumn.ATTACH_DATE)) {
226 row.appendChild(
new Treecell(
""));
228 if(columns.contains(AttachColumn.ATTACH_VALIDATED)) {
229 row.appendChild(
new Treecell(
""));
231 if(columns.contains(AttachColumn.ATTACH_OWNER)) {
232 row.appendChild(
new Treecell(
""));
236 private void addChildrenSpace() {
237 children =
new Treechildren();
238 appendChild(children);
250 this.loadOnDemand = loadOnDemand;
261 private void initLoadOnDemand() {
262 if(!loadOnDemand)
return;
266 addEventListener(Events.ON_OPEN,
new EventListener() {
268 public void onEvent(Event event)
throws Exception {
277 private void fillFolder() {
278 if(children.getChildren().isEmpty()) {
279 AttachResults results = getTree().getResults();
280 results.setAttachPath(Strings.isEmpty(path) ?
"/" : path);
281 results.setCkExactPath(
true);
282 for(Object o : results.getVersionedAttachmentList()) {
283 addFile((Attachment) o);
285 results.setAttachPath(path +
"/_%");
286 results.setCkExactPath(
false);
287 for(String s : results.getPathList(path)) {
288 addFolder(s, path +
"/" + s);
void setFileContent(byte[] fileContent)
void setOwner(String owner)
void setShowKey(String showKey)
void setOnlyOwner(boolean onlyOwner)
void setModification(Date modification)
void setFileSize(long fileSize)
void setFileContentType(String fileContentType)
void setValidated(boolean validated)
void setComment(String comment)
void setFileName(String fileName)
void setPath(String path)
void setAttachContent(AttachContent attachContent)
Attachment getAttachment()
void setPath(String path)
AttachFolder(String label, String path, boolean loadOnDemand, Set< AttachColumn > columns)
void setLoadOnDemand(boolean loadOnDemand)
AttachFile addFile(Attachment attachment)
AttachFolder addFolder(String label, String path)
AttachFolder(String label, Object value)
IAttachFolder getParentFolder()
AttachFolder(String label)
void setFolderLabel(String label)
AttachListener getAttachListener()
IConstructor getConstructor()
boolean isInRole(String role)
static Application getApplication()
static String cutString(String value, int maxChars)
static void confirmMove(String message, Command command)
static IElephantEntity getController(String path)
static String get(String msg)
static ISystemLogger getInstance()
void uploadDone(AttachFile file)
void doLog(SystemLogType type, Object entity, String comment, Serializable data)