18 package org.turro.attach.zul;
21 import org.turro.attach.db.AttachPU;
22 import org.turro.elephant.db.WhereClause;
23 import org.turro.jpa.Dao;
24 import org.turro.plugin.attach.IAttachFolder;
25 import org.zkoss.lang.Strings;
26 import org.zkoss.zul.AbstractListModel;
27 import org.zkoss.zul.ListModel;
28 import org.zkoss.zul.ListSubModel;
29 import org.zkoss.zul.event.ListDataEvent;
30 import org.zkoss.zul.ext.Sortable;
38 public class FolderNameComboModel extends AbstractListModel implements Sortable<IAttachFolder>, ListSubModel, java.io.Serializable {
40 private static final long serialVersionUID = 20081029L;
42 private Object[] data;
47 this.parentFolder = parentFolder;
51 this.data = data.toArray(
new Object[data.size()]);
52 this.parentFolder = parentFolder;
57 if(data ==
null || data.length <= index)
return null;
67 public void sort(Comparator cmpr,
boolean ascending) {
68 Arrays.sort(data, cmpr);
69 fireEvent(ListDataEvent.CONTENTS_CHANGED, -1, -1);
81 wc.
addClause(
"select distinct attachment.path from Attachment as attachment");
85 if(nRows < 1) nRows = 10;
86 return new FolderNameComboModel(cookList(dao.getResultList(wc, nRows), (String)value), parentFolder);
89 private List<String> cookList(List<String> list, String value) {
90 ArrayList<String> result =
new ArrayList<String>();
92 String pn[] = fp.split(
"\\/");
94 for(String s : list) {
95 String spn =
null, cp[] = s.split(
"\\/");
97 for(
int i = 0; i < pn.length; i++) {
102 if(i != 2 && !Strings.isBlank(pn[i]) && !pn[i].equals(cp[i])) {
108 for(
int i = pn.length; i < cp.length; i++) {
109 spn = (spn !=
null ? spn +
"/" :
"") + cp[i];
111 if(!result.contains(spn) && spn !=
null) result.add(spn);
115 Collections.sort(result, String.CASE_INSENSITIVE_ORDER);
119 private String rootName() {
121 return (s.length > 1 ?
"/" + s[1] :
"") +
"/%";
ListModel getSubModel(Object value, int nRows)
FolderNameComboModel(List data, IAttachFolder parentFolder)
void sort(Comparator cmpr, boolean ascending)
FolderNameComboModel(Object[] data, IAttachFolder parentFolder)
String getSortDirection(Comparator cmpr)
Object getElementAt(int index)
void addClause(String clause)
void addNamedValue(String name, Object value)