BrightSide Workbench Full Report + Source Code
ElephantMenu.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2020 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.menu;
20 
21 import java.util.Map;
22 import org.turro.string.Strings;
23 import org.turro.command.Command;
24 import org.turro.elephant.util.Components;
25 import org.turro.elephant.util.Images;
26 import org.turro.elephant.zkoss.Modal;
27 import org.turro.i18n.I_;
28 import org.turro.util.CompareUtil;
29 import org.turro.zul.frame.Framework;
30 import org.zkoss.zul.Menu;
31 
36 public class ElephantMenu extends Menu implements Comparable<ElephantMenu> {
37 
38  public ElephantMenu() {
39  }
40 
41  public ElephantMenu(String label) {
42  super(I_.get(label));
43  }
44 
45  public ElephantMenu(String label, String image) {
46  super(I_.get(label), Images.getImage(image));
47  }
48 
50  return Components.from(this).parent(ElephantMenuBar.class);
51  }
52 
54  return Components.from(this).parent(ElephantMenu.class);
55  }
56 
58  return Components.from(this).parent(ElephantSubmenu.class);
59  }
60 
63  appendChild(mp);
64  return mp;
65  }
66 
67  protected void addToSessionMenu(ElephantSubmenu submenu) {}
68  protected void addToMenu(ElephantMenuBar menubar) {}
69  protected void addToToolsMenu(ElephantSubmenu submenu) {}
70 
71  @Override
72  public int compareTo(ElephantMenu o) {
73  int result = CompareUtil.compare(getClass().getName(), o.getClass().getName());
74  return result;
75  }
76 
77  /* Include helper */
78 
79  public static String makeInclude(String include) {
80  if(Strings.isBlank(include)) {
81  return null;
82  } else if(include.startsWith("/WEB-INF")) {
83  return include;
84  } else if(include.startsWith("//")) {
85  return include.substring(1);
86  }
87  return "/WEB-INF/_zul" + include;
88  }
89 
90  public static void showEntity(Object id, String attribute, String label, String include) {
91  showEntity(id, attribute, label, include, null);
92  }
93 
94  public static void showEntity(Object id, String attribute, String label, String include, Map<String, Object> dynProps) {
95  Framework frame = Framework.getCurrent();
96  if((id instanceof Long && ((Long)id) < 1) || id == null) {
97  frame.getDesktop().removeAttribute(attribute);
98  } else {
99  frame.getDesktop().setAttribute(attribute, id);
100  }
101  if(label.startsWith("@")) {
102  frame.addContent(label.substring(1), makeInclude(include), dynProps);
103  } else {
104  frame.addContent(I_.get(label) + " #" + (id == null ? "0" : id.toString()), makeInclude(include), dynProps);
105  }
106  frame.invalidateSelected();
107  }
108 
109  public static void showZulFile(String label, String include) {
110  showZulFile(label, include, null);
111  }
112 
113  public static void showZulFile(String label, String include, Map<String, Object> dynProps) {
114  Framework frame = Framework.getCurrent();
115  if(label.startsWith("@")) {
116  frame.addContent(label.substring(1), makeInclude(include), dynProps);
117  } else {
118  frame.addContent(I_.get(label), makeInclude(include), dynProps);
119  }
120  }
121 
122  public static void showModalZulFile(String label, String source, Command command) {
123  showModalZulFile(label, source, null, null);
124  }
125 
126  public static void showModalZulFile(String label, String include, Map args, Command command) {
127  Framework frame = Framework.getCurrent();
128  if(label.startsWith("@")) {
129  frame.showModal(label.substring(1), makeInclude(include), args, command);
130  } else {
131  frame.showModal(I_.get(label), makeInclude(include), args, command);
132  }
133  }
134 
135  public static void showPopupZulFile(String label, String include) {
136  showPopupZulFile(label, include, null);
137  }
138 
139  public static void showPopupZulFile(String label, String include, Map args) {
140  Framework frame = Framework.getCurrent();
141  if(label.startsWith("@")) {
142  frame.showPopup(label.substring(1), makeInclude(include), args);
143  } else {
144  frame.showPopup(I_.get(label), makeInclude(include), args);
145  }
146  }
147 
148  public static void showEntityModal(Object id, String attribute, String include, Command command) {
149  Framework frame = Framework.getCurrent();
150  if((id instanceof Long && ((Long)id) < 1) || id == null) {
151  frame.getDesktop().removeAttribute(attribute);
152  } else {
153  frame.getDesktop().setAttribute(attribute, id);
154  }
155  Modal.doModal(makeInclude(include), command);
156  }
157 
158 }
static Components from(Object component)
Definition: Components.java:46
static String getImage(String image)
Definition: Images.java:36
static int doModal(String file)
Definition: Modal.java:38
static String get(String msg)
Definition: I_.java:41
void addToMenu(ElephantMenuBar menubar)
static void showPopupZulFile(String label, String include)
void addToSessionMenu(ElephantSubmenu submenu)
static void showModalZulFile(String label, String source, Command command)
static String makeInclude(String include)
int compareTo(ElephantMenu o)
static void showPopupZulFile(String label, String include, Map args)
static void showModalZulFile(String label, String include, Map args, Command command)
static void showEntityModal(Object id, String attribute, String include, Command command)
static void showZulFile(String label, String include, Map< String, Object > dynProps)
static void showEntity(Object id, String attribute, String label, String include)
ElephantMenu(String label, String image)
ElephantSubmenu getParentSubmenu()
ElephantMenuBar getMenuBar()
ElephantSubmenu addSubmenu()
static void showZulFile(String label, String include)
static void showEntity(Object id, String attribute, String label, String include, Map< String, Object > dynProps)
void addToToolsMenu(ElephantSubmenu submenu)
void addContent(String label, String src)
Definition: Framework.java:69
void showPopup(String label, String src, Map arg)
Definition: Framework.java:121
static Framework getCurrent()
Definition: Framework.java:203
void showModal(String label, String src, Map arg, Command command)
Definition: Framework.java:111
static void setAttribute(Object object, String key, Object value)
Definition: Framework.java:216