18 package org.turro.contacts.zul.fields;
20 import java.util.Date;
21 import java.util.List;
22 import org.turro.contacts.Contact;
23 import org.turro.contacts.FieldDef;
24 import org.turro.contacts.FieldValue;
25 import org.turro.contacts.db.ContactsPU;
26 import org.turro.contacts.zul.contact.FieldValueCombobox;
27 import org.turro.elephant.db.WhereClause;
28 import org.turro.i18n.I_;
29 import org.turro.zkoss.input.DateboxShort;
30 import org.zkoss.zk.ui.event.Event;
31 import org.zkoss.zk.ui.event.EventListener;
32 import org.zkoss.zk.ui.event.Events;
33 import org.zkoss.zul.Checkbox;
34 import org.zkoss.zul.Datebox;
35 import org.zkoss.zul.Doublebox;
36 import org.zkoss.zul.Grid;
37 import org.zkoss.zul.Label;
38 import org.zkoss.zul.Longbox;
39 import org.zkoss.zul.Row;
40 import org.zkoss.zul.Rows;
50 private String tabKey;
59 this.contact = contact;
60 rows.getChildren().clear();
61 if(contact !=
null && tabKey !=
null) {
67 for(
final FieldDef fd : getTabFields()) {
68 final Row row =
new Row();
70 rows.appendChild(row);
72 row.appendChild(
new Label(
I_.
get(fd.getLabelKey())));
74 if(fd.getJavaClass().equals(String.class)) {
78 value.addEventListener(Events.ON_CHANGE,
new EventListener() {
80 public void onEvent(Event event)
throws Exception {
84 row.appendChild(value);
85 }
else if(fd.getJavaClass().equals(Long.class)) {
86 final Longbox value =
new Longbox();
87 value.setValue((Long) getFieldValue(contact, fd));
88 value.addEventListener(Events.ON_CHANGE,
new EventListener() {
90 public void onEvent(Event event)
throws Exception {
91 setFieldValue(contact, fd, value.getValue());
94 row.appendChild(value);
95 }
else if(fd.getJavaClass().equals(Double.class)) {
96 final Doublebox value =
new Doublebox();
97 value.setValue((Double) getFieldValue(contact, fd));
98 value.addEventListener(Events.ON_CHANGE,
new EventListener() {
100 public void onEvent(Event event)
throws Exception {
101 setFieldValue(contact, fd, value.getValue());
104 row.appendChild(value);
105 }
else if(fd.getJavaClass().equals(Date.class)) {
107 value.setValue((Date) getFieldValue(contact, fd));
108 value.addEventListener(Events.ON_CHANGE,
new EventListener() {
110 public void onEvent(Event event)
throws Exception {
111 setFieldValue(contact, fd, value.getValue());
114 row.appendChild(value);
115 }
else if(fd.getJavaClass().equals(Boolean.class)) {
116 final Checkbox value =
new Checkbox();
117 Boolean b = (Boolean) getFieldValue(contact, fd);
118 value.setChecked(b ==
null ?
false : b);
119 value.addEventListener(Events.ON_CHECK,
new EventListener() {
121 public void onEvent(Event event)
throws Exception {
122 setFieldValue(contact, fd, value.isChecked());
125 row.appendChild(value);
132 if(fv.getFieldDef().getId().equals(fd.
getId())) {
133 return fv.getObjectValue();
139 private void setFieldValue(Contact contact, FieldDef fd, Object value) {
140 for(FieldValue fv : contact.getFieldValues()) {
141 if(fv.getFieldDef().getId().equals(fd.getId())) {
142 fv.setObjectValue(value);
146 FieldValue fv =
new FieldValue();
147 fv.setContact(contact);
149 fv.setObjectValue(value);
150 contact.getFieldValues().add(fv);
153 private List<FieldDef> getTabFields() {
154 WhereClause wc =
new WhereClause();
155 wc.addClause(
"select distinct fieldDef");
156 wc.addClause(
"from FieldDef as fieldDef");
157 wc.addClause(
"where fieldDef.tabKey = :tabKey");
158 wc.addNamedValue(
"tabKey", tabKey);
159 return (List<FieldDef>)
new ContactsPU().getResultList(wc);
static String get(String msg)