19 package org.turro.zkoss.dialog;
22 import java.util.Date;
23 import java.util.function.Supplier;
24 import org.turro.string.Strings;
25 import org.turro.elephant.impl.util.StringParser;
26 import org.turro.i18n.I_;
27 import org.turro.zkoss.input.DateboxShort;
28 import org.turro.zkoss.input.ExpressionInput;
29 import org.turro.zkoss.input.FileListbox;
30 import org.turro.zkoss.input.GenericBandbox;
31 import org.turro.zkoss.input.GenericCombobox;
32 import org.turro.zkoss.input.GenericListbox;
33 import org.turro.zkoss.label.Labels;
34 import org.zkoss.zk.ui.HtmlBasedComponent;
35 import org.zkoss.zul.A;
36 import org.zkoss.zul.Checkbox;
37 import org.zkoss.zul.Combobox;
38 import org.zkoss.zul.Datebox;
39 import org.zkoss.zul.Decimalbox;
40 import org.zkoss.zul.Hlayout;
41 import org.zkoss.zul.Label;
42 import org.zkoss.zul.Listbox;
43 import org.zkoss.zul.Space;
44 import org.zkoss.zul.Textbox;
45 import org.zkoss.zul.Vlayout;
53 private final String label;
54 private final Object value;
56 private boolean onlyLabel;
57 private String format, help;
58 private int scale, maxLength = 255;
59 private Enum[] choices;
63 private Supplier<HtmlBasedComponent> onEditor;
66 this.onlyLabel =
true;
91 this.maxLength = maxLength;
96 this.choices = choices;
101 this.onEditor = onEditor;
107 if(Strings.isBlank(label)) {
108 appendChild(
new Space());
136 if(onEditor !=
null) {
137 return onEditor.get();
138 }
else if(value instanceof Boolean) {
139 Checkbox cb =
new Checkbox();
140 cb.setChecked((Boolean) value);
141 cb.setLabel(
I_.
get(label));
144 }
else if(value instanceof Number) {
148 }
else if(value instanceof Date) {
149 Datebox db =
new Datebox((Date) value);
150 db.setFormat(format);
152 }
else if(value instanceof Enum) {
153 InputEnum ie =
new InputEnum(choices);
154 ie.setObjectValue((Enum) value);
157 }
else if(value instanceof File) {
159 fl.setMold(
"select");
162 fl.setSelectFirst(
true);
165 Textbox tb =
new Textbox((String) value);
169 tb.setMaxlength(maxLength);
176 if(
editor instanceof Checkbox) {
177 return Boolean.valueOf(((Checkbox)
editor).isChecked());
178 }
else if(
editor instanceof Decimalbox) {
182 }
else if(
editor instanceof Datebox) {
183 return ((Datebox)
editor).getValue();
190 }
else if(
editor instanceof Listbox) {
191 return ((Listbox)
editor).getSelectedItem().getValue();
192 }
else if(
editor instanceof InputEnum) {
193 return ((InputEnum)
editor).getObjectValue();
195 return ((Textbox)
editor).getText();
201 if(
editor instanceof Checkbox) {
203 }
else if(
editor instanceof InputEnum) {
204 }
else if(
editor instanceof Combobox) {
207 editor.setStyle(
"padding:0px;margin:0px;");
213 if(!Strings.isBlank(help)) {
214 Hlayout hbox =
new Hlayout();
215 hbox.setSclass(
"z-valign-middle");
216 hbox.setValign(
"middle");
219 b.setIconSclass(
"z-icon-question");
220 b.setTarget(
"_blank");
231 return field(
null,
null).onlyLabel();
235 return field(label,
null).onlyLabel();
239 return field(label,
null);
static Object convertToClass(Class javaClass, Object value)
static String get(String msg)
HtmlBasedComponent editor
HtmlBasedComponent createEditor()
DialogField scale(int scale)
void initiateEditor(HtmlBasedComponent editor)
DialogField onEditor(Supplier< HtmlBasedComponent > onEditor)
DialogField choices(Enum[] choices)
static DialogField field(String label, Object value)
HtmlBasedComponent getEditor()
DialogField maxLength(int maxLength)
static DialogField label(String label)
DialogField help(String help)
static DialogField space()
DialogField format(String format)
HtmlBasedComponent labelComponent()
DialogField lines(int lines)
static DialogField field(String label)
static Labels text(String text)
Labels style(String style)