19 package org.turro.zkoss.input;
21 import java.lang.reflect.ParameterizedType;
22 import java.util.LinkedList;
23 import org.turro.reflection.Reflections;
24 import org.turro.util.CompareUtil;
25 import org.zkoss.zul.Combobox;
26 import org.zkoss.zul.Comboitem;
27 import org.zkoss.zul.ComboitemRenderer;
28 import org.zkoss.zul.Constraint;
35 public abstract class GenericCombobox<V>
extends Combobox implements ComboitemRenderer<Object> {
37 private boolean allowNotInModelValues =
true;
38 private V currentValue;
45 Class<V> genericClass = (Class<V>) ((ParameterizedType) getClass()
46 .getGenericSuperclass()).getActualTypeArguments()[0];
48 if(Reflections.of(genericClass).canCast(String.class) && allowNotInModelValues) {
50 value = (V) getText();
52 Comboitem ci = getSelectedItem();
54 value = ci.getValue();
56 if(value ==
null && allowNotInModelValues && currentValue !=
null) {
65 Constraint c = getConstraint();
66 setConstraint((Constraint)
null);
68 if(!selectObjectItem(value)) {
75 return allowNotInModelValues;
79 this.allowNotInModelValues = allowNotInModelValues;
83 Constraint c = getConstraint();
84 setConstraint((Constraint)
null);
89 private void createModel() {
92 public void populateList(String value, LinkedList list,
int nRows) {
99 public abstract void populateList(String value, LinkedList list,
int nRows);
102 private void initComponent() {
103 setItemRenderer(
this);
107 private boolean selectObjectItem(V value) {
110 for(Comboitem item : getItems()) {
112 setSelectedItem(item);
122 private Object relatedEntity;
125 return relatedEntity;
129 this.relatedEntity = relatedEntity;
135 public void render(Comboitem item, Object data,
int index)
throws Exception {