19 package org.turro.zul.fieldit;
21 import java.util.Collection;
22 import java.util.Date;
23 import org.turro.contacts.FieldIt;
24 import org.turro.contacts.ValueIt;
25 import org.turro.fieldit.AutoFillList;
26 import org.turro.fieldit.IValueItEntity;
27 import org.turro.fieldit.StringList;
28 import org.turro.fieldit.ValueItSet;
29 import org.turro.i18n.I_;
30 import org.turro.zkoss.input.DateboxShort;
31 import org.turro.zkoss.layout.GridLayout;
32 import org.zkoss.zk.ui.HtmlBasedComponent;
33 import org.zkoss.zk.ui.event.Event;
34 import org.zkoss.zk.ui.event.EventListener;
35 import org.zkoss.zk.ui.event.Events;
36 import org.zkoss.zul.Checkbox;
37 import org.zkoss.zul.Datebox;
38 import org.zkoss.zul.Doublebox;
39 import org.zkoss.zul.Longbox;
40 import org.zkoss.zul.Textbox;
60 private void addFields() {
61 getChildren().clear();
71 private HtmlBasedComponent getEditor(
final ValueIt value) {
72 FieldIt fi = value.getFieldIt();
73 HtmlBasedComponent editor =
null;
74 if(fi.getJavaClass().equals(String.class)) {
76 final Textbox comp =
new Textbox();
78 comp.setValue((String) value.getObjectValue());
80 comp.addEventListener(Events.ON_CHANGE,
new EventListener() {
82 public void onEvent(Event event)
throws Exception {
84 value.setObjectValue(comp.getValue());
85 Events.postEvent(ValueItGrid.this,
new Event(Events.ON_CHANGE));
89 }
else if(fi.getJavaClass().equals(Long.class)) {
90 final Longbox comp =
new Longbox();
91 comp.setValue((Long) value.getObjectValue());
92 comp.addEventListener(Events.ON_CHANGE,
new EventListener() {
94 public void onEvent(Event event)
throws Exception {
95 value.setObjectValue(comp.getValue());
96 Events.postEvent(ValueItGrid.this,
new Event(Events.ON_CHANGE));
100 }
else if(fi.getJavaClass().equals(Double.class)) {
101 final Doublebox comp =
new Doublebox();
102 comp.setValue((Double) value.getObjectValue());
103 comp.addEventListener(Events.ON_CHANGE,
new EventListener() {
105 public void onEvent(Event event)
throws Exception {
106 value.setObjectValue(comp.getValue());
107 Events.postEvent(ValueItGrid.this,
new Event(Events.ON_CHANGE));
111 }
else if(fi.getJavaClass().equals(Date.class)) {
112 final Datebox comp =
new DateboxShort();
113 comp.setValue((Date) value.getObjectValue());
114 comp.addEventListener(Events.ON_CHANGE,
new EventListener() {
116 public void onEvent(Event event)
throws Exception {
117 value.setObjectValue(comp.getValue());
118 Events.postEvent(ValueItGrid.this,
new Event(Events.ON_CHANGE));
122 }
else if(fi.getJavaClass().equals(Boolean.class)) {
123 final Checkbox comp =
new Checkbox();
124 Boolean b = (Boolean) value.getObjectValue();
125 comp.setChecked(b ==
null ?
false : b);
126 comp.addEventListener(Events.ON_CHECK,
new EventListener() {
128 public void onEvent(Event event)
throws Exception {
129 value.setObjectValue(comp.isChecked());
130 Events.postEvent(ValueItGrid.this,
new Event(Events.ON_CHANGE));
134 }
else if(fi.getJavaClass().equals(StringList.class)) {
135 final StringListListbox comp =
new StringListListbox(fi);
136 comp.setObjectValue(value.getObjectString());
137 comp.setMold(
"select");
138 comp.addEventListener(Events.ON_SELECT,
new EventListener() {
140 public void onEvent(Event event)
throws Exception {
141 value.setObjectValue(comp.getObjectValue());
142 Events.postEvent(ValueItGrid.this,
new Event(Events.ON_CHANGE));
146 }
else if(fi.getJavaClass().equals(AutoFillList.class)) {
147 final AutoFillCombobox comp =
new AutoFillCombobox(fi);
148 comp.setObjectValue(value.getValue());
149 comp.addEventListener(Events.ON_SELECT,
new EventListener() {
151 public void onEvent(Event event)
throws Exception {
152 value.setObjectValue(comp.getObjectValue());
153 Events.postEvent(ValueItGrid.this,
new Event(Events.ON_CHANGE));
156 comp.addEventListener(Events.ON_CHANGE,
new EventListener() {
158 public void onEvent(Event event)
throws Exception {
159 value.setObjectValue(comp.getObjectValue());
160 comp.saveValue(comp.getObjectValue());
161 Events.postEvent(ValueItGrid.this,
new Event(Events.ON_CHANGE));
static String get(String msg)
void setColumns(int columns)
GridLayout addComponent(HtmlBasedComponent comp)
GridLayout addCaption(String label)
void setEntity(IValueItEntity entity)
Collection< ValueIt > getValues()