19 package org.turro.zkoss.text;
22 import java.io.FileFilter;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import org.turro.command.Command;
26 import org.turro.elephant.context.ElephantContext;
27 import org.turro.file.Folder;
28 import org.turro.upload.Medias;
29 import org.zkoss.util.media.Media;
30 import org.zkoss.zk.ui.HtmlBasedComponent;
31 import org.zkoss.zk.ui.event.Event;
32 import org.zkoss.zk.ui.event.EventListener;
33 import org.zkoss.zk.ui.event.Events;
34 import org.zkoss.zk.ui.event.UploadEvent;
35 import org.zkoss.zul.Div;
36 import org.zkoss.zul.Fileupload;
37 import org.zkoss.zul.Image;
38 import org.zkoss.zul.Label;
46 public static final String
48 FILE_FILTER =
".*(\\.pdf|\\.doc|\\.xls|\\.ppt|\\.od[a-z]|\\.txt|\\.json)";
51 private String matchFilter =
".*";
59 Folder.from(folder).ensure();
67 this.matchFilter = matchFilter;
71 if(folder !=
null && folder.exists()) {
72 getChildren().clear();
73 for(File file : folder.listFiles(
new FileFilter() {
75 public boolean accept(File pathname) {
76 return pathname.isFile() && !pathname.isHidden() && pathname.getName().matches(matchFilter);
79 appendChild(createBox(file));
84 public void upload(
final Command command) {
85 if(!folder.exists()) {
88 Fileupload.get(100,
new EventListener<UploadEvent>() {
90 public void onEvent(UploadEvent event) {
94 command.execute(
null);
95 }
catch (Exception ex) {
105 if(medias ==
null || medias.length == 0)
return;
106 for(Media media : medias) {
111 private HtmlBasedComponent createBox(
final File file) {
115 box.setSclass(
"rc_image");
116 box.appendChild(img);
118 Label label =
new Label(file.getName());
119 box.setSclass(
"rc_file");
120 box.appendChild(label);
122 box.addEventListener(Events.ON_DOUBLE_CLICK,
new EventListener<Event>() {
124 public void onEvent(Event event) throws Exception {
125 Events.postEvent(new Event(Events.ON_SELECT, RepositoryContent.this, file));
static String getRelativePath(String path)
static String logMsg(String msg)
void upload(final Command command)
void setMatchFilter(String matchFilter)
static final String IMAGE_FILTER
void setFolder(File folder)
void addMedias(Media[] medias)