19 package org.turro.zkoss.input;
21 import java.util.Collection;
22 import org.turro.i18n.I_;
23 import org.zkoss.zk.ui.Component;
24 import org.zkoss.zk.ui.event.Event;
25 import org.zkoss.zk.ui.event.EventListener;
26 import org.zkoss.zk.ui.event.Events;
27 import org.zkoss.zk.ui.ext.AfterCompose;
28 import org.zkoss.zul.Div;
29 import org.zkoss.zul.Hlayout;
30 import org.zkoss.zul.Layout;
31 import org.zkoss.zul.Radio;
32 import org.zkoss.zul.Radiogroup;
33 import org.zkoss.zul.Vlayout;
39 public abstract class GenericRadiogroup<E>
extends Div implements AfterCompose, EventListener<Event> {
41 private String orient =
"horizontal";
42 private Collection<E> collection;
44 private boolean disabled =
false, populated =
false, allowNone =
false;
45 private Layout layout;
46 private Radiogroup radioGroup =
new Radiogroup();
55 for(Radio r : radioGroup.getItems()) {
59 clear.setDisabled(value);
68 this.allowNone = allowNone;
77 this.collection = collection;
82 Radio r = radioGroup.getSelectedItem();
84 for(E e : collection) {
98 if(populated && _internal !=
null) {
99 for(Component c : layout.getChildren()) {
100 if(c instanceof Radio) {
109 radioGroup.setSelectedItem(
null);
117 this.orient = orient;
122 if(!collection.isEmpty()) {
123 if(
"vertical".equals(orient)) {
124 layout =
new Vlayout();
126 layout =
new Hlayout();
128 appendChild(radioGroup);
130 for(E e : collection) {
132 r.setRadiogroup(radioGroup);
133 layout.appendChild(r);
139 radioGroup.addEventListener(Events.ON_CHECK,
this);
143 public void onEvent(Event event)
throws Exception {
144 Events.postEvent(
this, event);
149 private void clearImage() {
150 if(populated && allowNone && clear ==
null) {
151 clear =
new Radio(
I_.
get(
"Clear"));
152 clear.addEventListener(Events.ON_CHECK,
new EventListener<Event>() {
154 public void onEvent(Event event) throws Exception {
156 radioGroup.setSelectedItem(null);
158 clear.setSelected(false);
159 Events.postEvent(GenericRadiogroup.this, event);
162 layout.appendChild(clear);
static String get(String msg)