18 package org.turro.zkoss.input;
20 import java.util.Collection;
21 import java.util.HashSet;
22 import java.util.List;
24 import org.zkoss.zk.ui.ext.AfterCompose;
25 import org.zkoss.zul.Listbox;
26 import org.zkoss.zul.Listhead;
27 import org.zkoss.zul.Listheader;
28 import org.zkoss.zul.Listitem;
34 public abstract class GenericListbox<V>
extends Listbox implements AfterCompose {
36 private boolean selectFirst =
true;
37 private V internalValue;
38 private Collection<V> internalValues;
46 super.setDisabled(value);
47 for(Listitem li : getItems()) {
48 li.setDisabled(value);
57 if(internalValue !=
null) {
60 }
else if (internalValues !=
null) {
62 internalValues =
null;
76 internalValue = value;
78 if(value ==
null && selectFirst && getItemCount() > 0) {
81 for(Object item : getItems()) {
82 if(item instanceof Listitem) {
83 if(
equals((V) ((Listitem) item).getValue(), (V) value)) {
84 setSelectedItem((Listitem) item);
93 internalValues = collection;
95 setSelectedItem(
null);
98 protected boolean equals(V value, V obj) {
106 return internalValue;
108 Listitem li = getSelectedItem();
110 return (V) li.getValue();
117 return internalValues;
124 return internalValues;
134 this.selectFirst = selectFirst;
138 Set
set =
new HashSet();
139 for(Listitem li : (List<Listitem>) getItems()) {
140 if(!li.isSelected()) {
148 Collection c = getHeads();
149 if(c ==
null || c.isEmpty()) {
150 Listhead lh =
new Listhead();
151 Listheader lhr =
new Listheader();
156 lh.setVisible(
false);
159 if(h instanceof Listhead) {
160 if(((Listhead) h).getFirstChild() instanceof Listheader) {
161 ((Listheader) ((Listhead) h).getFirstChild()).
sort(
true);
168 protected boolean equals(V value, V obj) {
169 return (value ==
null && obj ==
null) ||
170 (value !=
null && value.equals(obj));
177 private Object relatedEntity;
180 return relatedEntity;
184 this.relatedEntity = relatedEntity;