18 package org.turro.zkoss.tree;
20 import java.util.Collection;
21 import org.zkoss.zk.ui.event.Event;
22 import org.zkoss.zk.ui.event.Events;
23 import org.zkoss.zk.ui.ext.AfterCompose;
24 import org.zkoss.zul.Tree;
25 import org.zkoss.zul.Treechildren;
26 import org.zkoss.zul.Treeitem;
32 public abstract class GenericTree<V>
extends Tree implements AfterCompose {
34 private boolean selectFirst =
true;
35 private V internalValue;
43 if(internalValue !=
null) {
61 internalValue = value;
63 if(value ==
null && selectFirst && getItemCount() > 0) {
64 setSelectedFirstItem();
66 for(Object item : getItems()) {
67 if(item instanceof Treeitem) {
68 if(
equals((V) ((Treeitem) item).getValue(), (V) value)) {
69 setSelectedItem((Treeitem) item);
92 Treeitem li = getSelectedItem();
93 if(li !=
null && li.getValue() !=
null) {
94 return (V) li.getValue();
107 if(text !=
null && text.length() > 3) {
108 for(Object item : getItems()) {
109 if(item instanceof Treeitem) {
110 String l = ((Treeitem) item).getLabel();
111 if(l.toLowerCase().contains(text.toLowerCase())) {
112 setSelectedItem((Treeitem) item);
114 Events.postEvent(
new Event(Events.ON_SELECT,
GenericTree.this));
122 while(item !=
null) {
124 item = item.getParentItem();
128 protected boolean equals(V value, V obj) {
129 return (value ==
null && obj ==
null) ||
130 (value !=
null && value.equals(obj));
134 if(parent.getTreechildren() ==
null) {
135 parent.appendChild(
new Treechildren());
137 parent.getTreechildren().appendChild(child);
142 private void setSelectedFirstItem() {
143 for(Treeitem ti : (Collection<Treeitem>) getItems()) {
144 if(ti.getValue() !=
null) {
void showItem(Treeitem item)
void addTreeitem(Treeitem parent, Treeitem child)
void setObjectValue(V value)
abstract void populateList()
void selectItemByText(String text)
boolean equals(V value, V obj)