18 package org.turro.zkoss.input;
20 import java.util.Arrays;
21 import java.util.Comparator;
22 import java.util.LinkedList;
23 import java.util.List;
24 import org.zkoss.zul.AbstractListModel;
25 import org.zkoss.zul.ListModel;
26 import org.zkoss.zul.ListSubModel;
27 import org.zkoss.zul.event.ListDataEvent;
28 import org.zkoss.zul.ext.Sortable;
34 public abstract class GenericComboModel extends AbstractListModel implements Sortable<Object>, ListSubModel, java.io.Serializable {
36 private static final long serialVersionUID = 20090814L;
38 private Object[] data;
39 private Object lastValue;
46 this.data = data.toArray(
new Object[data.size()]);
51 return data !=
null && index >= 0 && index < data.length ? data[index] :
null;
60 public void sort(Comparator cmpr,
boolean ascending) {
61 Arrays.sort(data, cmpr);
62 fireEvent(ListDataEvent.CONTENTS_CHANGED, -1, -1);
71 public synchronized ListModel
getSubModel(Object value,
int nRows) {
72 if(value !=
null && value.equals(lastValue))
return this;
74 LinkedList list =
new LinkedList();
75 if(nRows < 1) nRows = 20;
79 public void populateList(String value, LinkedList list,
int nRows) {
80 throw new UnsupportedOperationException(
"Submodel does not populate items");
85 public abstract void populateList(String value, LinkedList list,
int nRows);