01: /* ListitemCollectionItem.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Jul 31, 2007 3:13:52 PM , Created by jumperchen
10: }}IS_NOTE
11:
12: Copyright (C) 2007 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.zkplus.databind;
20:
21: import org.zkoss.zk.ui.Component;
22: import org.zkoss.zk.ui.UiException;
23: import org.zkoss.zul.ListModel;
24: import org.zkoss.zul.Listbox;
25: import org.zkoss.zul.Listitem;
26:
27: /* package */class ListitemCollectionItem implements CollectionItem {
28:
29: public Component getComponentCollectionOwner(Component comp) {
30: if (comp instanceof Listitem) {
31: final Listitem item = (Listitem) comp;
32: return item.getListbox();
33: } else {
34: throw new UiException(
35: "Unsupported type for ListitemCollectionItem: "
36: + comp);
37: }
38: }
39:
40: public ListModel getModelByOwner(Component comp) {
41: if (comp instanceof Listbox) {
42: final Listbox listbox = (Listbox) comp;
43: return listbox.getModel();
44: } else {
45: throw new UiException(
46: "Unsupported type for ListitemCollectionItem: "
47: + comp);
48: }
49: }
50:
51: public Component getComponentAtIndexByOwner(Component comp,
52: int index) {
53: if (comp instanceof Listbox) {
54: final Listbox listbox = (Listbox) comp;
55: return listbox.getItemAtIndex(index);
56: } else {
57: throw new UiException(
58: "Unsupported type for ListitemCollectionItem: "
59: + comp);
60: }
61: }
62:
63: public void setupBindingRenderer(Component comp, DataBinder binder) {
64: if (comp instanceof Listitem) {
65: final Listitem li = (Listitem) comp;
66: final Listbox lbx = li.getListbox();
67: if (lbx.getItemRenderer() == null) {
68: lbx.setItemRenderer(new BindingListitemRenderer(li,
69: binder));
70: }
71: }
72: }
73:
74: }
|