BrightSide Workbench Full Report + Source Code
Popups.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.zkoss.dialog;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.function.Consumer;
25 import org.turro.zul.frame.Framework;
26 import org.zkoss.zk.ui.HtmlBasedComponent;
27 import org.zkoss.zk.ui.event.Event;
28 import org.zkoss.zk.ui.event.EventListener;
29 import org.zkoss.zk.ui.event.Events;
30 import org.zkoss.zk.ui.ext.AfterCompose;
31 import org.zkoss.zul.Div;
32 import org.zkoss.zul.Include;
33 import org.zkoss.zul.Popup;
34 import org.zkoss.zul.Space;
35 
40 public class Popups extends Div {
41 
42  private final List<HtmlBasedComponent> components;
43 
44  public Popups width(String width) {
45  setWidth(width);
46  return this;
47  }
48 
49  public Popups height(String height) {
50  setHeight(height);
51  return this;
52  }
53 
54  public Popups scrollable() {
55  setStyle("overflow-y:auto");
56  return this;
57  }
58 
59  public Popups onClose(Consumer<Popups> onClose) {
60  if(onClose != null) {
61  EventListener el = (EventListener) (Event event) -> {
62  onClose.accept(Popups.this);
63  detach();
64  };
65  addEventListener(Events.ON_CLOSE, el);
66  }
67  return this;
68  }
69 
70  public Popups addSpace() {
71  components.add(new Space());
72  return this;
73  }
74 
75  public Popups addComponent(HtmlBasedComponent component) {
76  components.add(component);
77  return this;
78  }
79 
80  public Popups addComponent(String uri, Map args) {
81  Include include = new Include("/WEB-INF/_zul" + uri);
82  if(args != null) {
83  args.forEach((k, v) -> include.setDynamicProperty((String) k, v));
84  }
85  include.setDynamicProperty("popup", Framework.getCurrent().getGlobalPopup());
86  components.add(include);
87  return this;
88  }
89 
90  public void popup() {
91  createComponents();
93  popup.appendChild(this);
94  popup.open(Framework.getCurrent());
95  }
96 
97  /* Factory */
98 
99  public static Popups instance() {
100  return new Popups();
101  }
102 
103  private Popups() {
104  super();
105  components = new ArrayList<>();
106  }
107 
108  /* Container */
109 
110  private void createComponents() {
111  components.forEach(component -> {
112  appendChild(component);
113  if(component instanceof AfterCompose) {
114  ((AfterCompose) component).afterCompose();
115  }
116  });
117  }
118 
119 }
Popups width(String width)
Definition: Popups.java:44
Popups onClose(Consumer< Popups > onClose)
Definition: Popups.java:59
static Popups instance()
Definition: Popups.java:99
Popups height(String height)
Definition: Popups.java:49
Popups addComponent(HtmlBasedComponent component)
Definition: Popups.java:75
Popups addComponent(String uri, Map args)
Definition: Popups.java:80
static Framework getCurrent()
Definition: Framework.java:203