19 package org.turro.elephant.configuration;
22 import java.util.Arrays;
23 import java.util.Comparator;
24 import org.amic.util.file.FileUtil;
25 import org.turro.string.Strings;
26 import org.turro.elephant.context.ElephantContext;
27 import org.turro.util.CompareUtil;
28 import org.zkoss.zul.Treecell;
29 import org.zkoss.zul.Treechildren;
30 import org.zkoss.zul.Treeitem;
31 import org.zkoss.zul.Treerow;
39 private final String label, pattern;
40 private boolean dynamicLoad;
42 public FilesItem(File file, String label, String pattern) {
43 this(file, label, pattern,
false);
46 public FilesItem(File file, String label, String pattern,
boolean dynamicLoad) {
47 this.label = Strings.isBlank(label) ? file.getName() : label;
48 this.pattern = pattern;
49 this.dynamicLoad = dynamicLoad;
60 appendChild(
new Treechildren());
62 getTreechildren().appendChild(file);
75 getTreechildren().getChildren().clear();
79 private void initiate() {
92 private void fillChildren() {
94 File[] sortedFiles = file.listFiles();
95 Arrays.sort(sortedFiles,
new Comparator<File>() {
97 public int compare(File o1, File o2) {
98 return CompareUtil.compare(o1.getName(), o2.getName());
101 if(getTreechildren() ==
null) {
102 Treechildren children =
new Treechildren();
103 appendChild(children);
105 for(File f : sortedFiles) {
106 if(pattern ==
null || (f.isFile() && f.getName().matches(pattern))) {
107 getTreechildren().appendChild(
new FilesItem(f,
null, pattern, f.getAbsolutePath().contains(
"templates")));
112 private void addCells() {
113 Treerow row =
new Treerow();
115 Treecell cell =
new Treecell(label);
116 row.appendChild(cell);
117 setImage(getMimeImage());
120 private String getMimeImage() {
121 if(getValue() ==
null || !
new File(ElephantContext.getRealPath(
"/_internal/system/mime/" + FileUtil.getExtension((File) getValue()) +
".png")).exists()) {
122 return "/_internal/system/mime/empty.png";
124 return "/_internal/system/mime/" + FileUtil.getExtension((File) getValue()) +
".png";
FilesItem(File file, String label, String pattern)
void addFile(FilesItem file)
FilesItem(File file, String label, String pattern, boolean dynamicLoad)