19 package org.turro.zkoss.dialog;
21 import java.util.ArrayList;
22 import java.util.List;
24 import java.util.function.Consumer;
25 import org.turro.zul.frame.Framework;
26 import org.zkoss.zk.ui.Executions;
27 import org.zkoss.zk.ui.HtmlBasedComponent;
28 import org.zkoss.zk.ui.Page;
29 import org.zkoss.zk.ui.event.Event;
30 import org.zkoss.zk.ui.event.EventListener;
31 import org.zkoss.zk.ui.event.Events;
32 import org.zkoss.zk.ui.ext.AfterCompose;
33 import org.zkoss.zul.Borderlayout;
34 import org.zkoss.zul.Button;
35 import org.zkoss.zul.Center;
36 import org.zkoss.zul.Hlayout;
37 import org.zkoss.zul.Include;
38 import org.zkoss.zul.South;
39 import org.zkoss.zul.Vlayout;
40 import org.zkoss.zul.Window;
49 private final List<DialogField> fields;
50 private final List<HtmlBasedComponent> components;
51 private Borderlayout blayout;
52 private Vlayout fieldsContainer;
53 private Hlayout buttonsContainer;
116 components.add(component);
125 Include include =
new Include(
"/WEB-INF/_zul" + uri);
127 args.forEach((k, v) -> include.setDynamicProperty((String) k, v));
129 include.setHeight(
height);
130 components.add(include);
139 if(getPage() ==
null) {
140 setPage(getMeAPage());
147 public <V> V getValue(String label, Class<V> javaClass) {
148 return (V) fields.stream().filter(f -> label.equals(f.getLabel())).findFirst().get().getEditorValue();
152 return fields.stream().filter(f -> label.equals(f.getLabel())).findFirst().get().getEditorValue();
155 public <E> E getEditor(String label) {
156 return (E) fields.stream().filter(f -> label.equals(f.getLabel())).findFirst().get().getEditor();
166 super(
title,
"normal",
false);
167 fields =
new ArrayList<>();
168 components =
new ArrayList<>();
170 setPosition(
"center");
175 private Page getMeAPage() {
176 Page
page = getPage();
178 if(Framework.getCurrent() !=
null) {
179 page = Framework.getCurrent().getPage();
181 page = Executions.getCurrent().getDesktop().getFirstPage();
189 private void createContainer() {
190 blayout =
new Borderlayout();
191 blayout.setVflex(
"1");
192 blayout.setHflex(
"1");
193 Center center =
new Center();
194 center.setBorder(
"none");
195 center.setStyle(
"overflow-y:auto");
196 fieldsContainer =
new Vlayout();
197 fieldsContainer.setSclass(
"inputDialogContainer");
198 center.appendChild(fieldsContainer);
199 blayout.appendChild(center);
200 if(!events.isEmpty()) {
201 South south =
new South();
202 south.setBorder(
"none");
203 south.setHeight(
"50px");
204 south.setStyle(
"padding-top:8px");
205 blayout.appendChild(south);
206 buttonsContainer =
new Hlayout();
207 buttonsContainer.setSclass(
"inputDialogContainer");
208 south.appendChild(buttonsContainer);
210 appendChild(blayout);
213 private void createFields() {
214 fields.forEach(field -> {
215 fieldsContainer.appendChild(field);
216 if(field.getEditor() instanceof AfterCompose) {
217 ((AfterCompose) field.getEditor()).afterCompose();
222 private void createComponents() {
223 components.forEach(component -> {
224 fieldsContainer.appendChild(component);
225 if(component instanceof AfterCompose) {
226 ((AfterCompose) component).afterCompose();
231 private boolean defaultDone =
false;
233 private void createButtons() {
234 if(!events.isEmpty()) {
235 Hlayout butCont =
new Hlayout();
236 butCont.setSclass(
"buttonDialogContainer");
237 butCont.setHflex(
"true");
238 butCont.setStyle(
"padding:10px;text-align:right");
239 butCont.setSpacing(
"15px");
240 buttonsContainer.appendChild(butCont);
241 events.forEach(dialogEvent -> {
242 Button b = dialogEvent.getButton().getButton();
243 EventListener el = (EventListener) (Event event) -> {
244 if(dialogEvent.getOnClik() !=
null) dialogEvent.getOnClik().accept(Dialogs.this);
245 Events.postEvent(
new Event(Events.ON_CLOSE, Dialogs.this));
247 b.addEventListener(Events.ON_CLICK, el);
249 b.setStyle(
"font-weight:bold");
250 blayout.addEventListener(Events.ON_OK, el);
253 butCont.appendChild(b);
Dialogs width(String width)
Object getValue(String label)
Dialogs height(String height)
Dialogs onOk(Consumer< Dialogs > onOk)
Dialogs position(String position)
Dialogs addComponent(String uri, Map args)
Dialogs addComponent(String uri, String height, Map args)
Dialogs onClose(Consumer< Dialogs > onClose)
static Dialogs title(String title)
Dialogs addComponent(HtmlBasedComponent component)
Dialogs onCancel(Consumer< Dialogs > onCancel)
Dialogs addField(DialogField field)