19 package org.turro.menu;
21 import java.util.Collection;
22 import java.util.function.BiConsumer;
23 import org.turro.string.Strings;
24 import org.turro.elephant.util.Components;
25 import org.turro.elephant.util.Images;
26 import org.turro.i18n.I_;
27 import org.turro.security.Permission;
28 import org.turro.zul.frame.Framework;
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.zul.Menuitem;
33 import org.zkoss.zul.Menupopup;
34 import org.zkoss.zul.Menuseparator;
35 import org.zkoss.zul.Toolbarbutton;
43 private boolean separator =
false;
58 return addMenu(label,
null,
null);
62 return addMenu(label, image,
null);
66 return addMenu(label,
null, permission);
73 if(permission !=
null) m.setVisible(permission.
check());
86 return addMenuitem(label,
null, listener, toolButton);
98 return addMenuitem(label, image, include, toolButton,
null);
102 return addMenuitem(label, image, listener, toolButton,
null);
106 return addMenuitem(label,
null, include, permission);
110 return addMenuitem(label,
null, listener, permission);
114 return addMenuitem(label,
null, include, toolButton, permission);
118 return addMenuitem(label,
null, listener, toolButton, permission);
122 return addMenuitem(label, image, include,
false, permission);
126 return addMenuitem(label, image, listener,
false, permission);
130 if(permission ==
null || permission.
check()) {
131 EventListener listener =
null;
132 if(include !=
null) {
133 listener = (EventListener) (Event event) -> {
137 return addMenuitem(label, image, listener, toolButton, permission);
143 if(permission ==
null || permission.
check()) {
145 if(toolButton && toolbar !=
null) {
146 Toolbarbutton button =
new Toolbarbutton();
148 button.setTooltiptext(
I_.
get(label));
149 if(!Strings.isBlank(image)) {
152 if(listener !=
null) {
153 button.addEventListener(Events.ON_CLICK, listener);
157 Menuitem mi =
new Menuitem(
I_.
get(label));
158 if(!Strings.isBlank(image)) {
162 if(listener !=
null) {
163 mi.addEventListener(Events.ON_CLICK, listener);
170 if(!getChildren().isEmpty()) separator =
true;
176 em.addToSessionMenu(
this);
183 em.addToToolsMenu(
this);
193 public <T>
ElephantSubmenu addCollecction(Collection<T> items, BiConsumer<ElephantSubmenu, T> consumer) {
194 items.stream().forEach((i) -> consumer.accept(
ElephantSubmenu.this, i));
198 public <T> ElephantSubmenu addObject(T item, BiConsumer<ElephantSubmenu, T> consumer) {
199 consumer.accept(ElephantSubmenu.this, item);
203 private ElephantToolbar getToolbar() {
205 return emb !=
null ? emb.getToolbar() :
null;
208 private void checkSeparator() {
210 appendChild(
new Menuseparator());
static Components from(Object component)
static String getImage(String image)
static String get(String msg)
void addContent(String label, String src)
static Framework getCurrent()