19 package org.turro.elephant.menu;
22 import java.util.ArrayList;
23 import java.util.Collection;
25 import java.util.concurrent.locks.Lock;
26 import java.util.concurrent.locks.ReentrantLock;
27 import org.turro.action.Contacts;
28 import org.turro.annotation.ProfileAction;
29 import org.turro.annotation.UserAction;
30 import org.turro.elephant.context.ElephantContext;
31 import org.turro.elephant.context.IConstructor;
32 import org.turro.i18n.I_;
33 import org.turro.plugin.contacts.IContact;
34 import org.turro.reflection.ReflectionUtil;
47 this.constructor = constructor;
51 if(constructor.
isInRole(
"webmenu:out")) {
52 return noActions(constructor);
54 return userActions(constructor);
58 return profileActions(constructor);
62 if(
"/app/frame".equals(action.
getLink())) {
81 if(favatar.exists()) {
90 private static Collection<IUserAction> _userActions, _profileActions, _noActions;
91 private static final Lock lock =
new ReentrantLock();
94 if(_userActions !=
null) {
96 if(idAction.equals(userAction.getId())) {
102 if(_profileActions !=
null) {
104 if(idAction.equals(userAction.getId())) {
105 userAction.execute();
112 private static Collection<IUserAction> userActions(
IConstructor constructor) {
113 if(_userActions ==
null) {
116 if(_userActions ==
null) {
117 _userActions =
new ArrayList<>();
118 elephantActions(constructor);
121 for(String menu : menus) {
122 Object obj = ReflectionUtil.instance(ReflectionUtil.classCheck(menu));
138 private static Collection<IUserAction> noActions(IConstructor constructor) {
139 if(_noActions ==
null) {
142 if(_noActions ==
null) {
143 String root = ElephantContext.getRootWebPath();
144 _noActions =
new ArrayList<>();
145 _noActions.add(
new DefaultUserAction(
"home", I_.get(
"Home"),
null, root +
"/user"));
146 _noActions.add(
new DefaultUserAction(
"agreements",
"Agreements",
null, root +
"/user/myagreements"));
155 private static void elephantActions(IConstructor constructor) {
156 String root = ElephantContext.getRootWebPath();
158 boolean contracts = ReflectionUtil.classCheckSilent(
"org.turro.financials.entity.Contract") !=
null,
159 dossiers = ReflectionUtil.classCheckSilent(
"org.turro.dossier.entity.Dossier") !=
null,
160 publications = ReflectionUtil.classCheckSilent(
"org.turro.publication.entity.Publication") !=
null;
162 _userActions.add(
new DefaultUserAction(
"home",
"Home",
null, root +
"/user"));
163 _userActions.add(
new DefaultUserAction(
"session",
"Session",
null));
164 _userActions.add(
new DefaultUserAction(
"acceptances",
"Acceptances",
165 root +
"/_zul/images/64/acceptance.png", root +
"/user/acceptances"));
166 _userActions.add(
new DefaultUserAction(
"agreements",
"Agreements",
167 root +
"/_zul/images/64/acceptance.png", root +
"/user/myagreements"));
168 _userActions.add(
new DefaultUserAction(
"polls",
"Polls",
169 root +
"/_zul/images/64/poll.png", root +
"/user/mypolls"));
171 _userActions.add(
new DefaultUserAction(
"myblogs",
"My blogs",
172 null, root +
"/user/myblogs"));
173 _userActions.add(
new DefaultUserAction(
"subscriptions",
"Subscriptions",
174 root +
"/_zul/images/64/subscription.png", root +
"/user/subscriptions"));
176 _userActions.add(
new DefaultUserAction(
"mycalendar",
"Calendar",
177 root +
"/_zul/images/64/calendar.png", root +
"/user/mycalendar"));
178 _userActions.add(
new DefaultUserAction(
"end",
"end",
null));
179 _userActions.add(
new DefaultUserAction(
"mycontacts",
"Contacts",
180 root +
"/_zul/images/64/contacts.png", root +
"/user/mycontacts"));
182 _userActions.add(
new DefaultUserAction(
"financials",
"Billing",
null));
183 _userActions.add(
new DefaultUserAction(
"contracts",
"Contracts",
184 root +
"/_zul/images/64/contract.png", root +
"/user/contracts"));
185 _userActions.add(
new DefaultUserAction(
"documents",
"Documents",
186 root +
"/_zul/images/64/documents.png", root +
"/user/documents"));
187 _userActions.add(
new DefaultUserAction(
"logistic",
"Logistic",
188 root +
"/_zul/images/64/shopping-cart.png", root +
"/user/logistic"));
189 _userActions.add(
new DefaultUserAction(
"end",
"end",
null));
192 _userActions.add(
new DefaultUserAction(
"dossiers",
"Dossiers",
null));
193 _userActions.add(
new DefaultUserAction(
"mydossiers",
"My Dossiers",
194 root +
"/_zul/images/64/dossier.png", root +
"/user/mydossiers"));
195 _userActions.add(
new DefaultUserAction(
"myprojects",
"My Projects",
196 root +
"/_zul/images/64/dossier.png", root +
"/user/myprojects"));
197 _userActions.add(
new DefaultUserAction(
"kbase",
"Knowledge base",
198 root +
"/_zul/images/64/kbase.png", root +
"/user/kbase"));
199 _userActions.add(
new DefaultUserAction(
"myissues",
"My Issues",
200 root +
"/_zul/images/64/issue.png", root +
"/user/myissues"));
201 _userActions.add(
new DefaultUserAction(
"pendingrevision",
"Pending revision",
202 root +
"/_zul/images/64/issue.png", root +
"/user/pendingrevision"));
203 _userActions.add(
new DefaultUserAction(
"newissue",
"Report Issue",
204 root +
"/_zul/images/64/issue_new.png", root +
"/user/newissue"));
205 _userActions.add(
new DefaultUserAction(
"end",
"end",
null));
208 _userActions.add(
new DefaultUserAction(
"baas",
"BaaS",
209 root +
"/_zul/images/64/desktop.png", root +
"/app/frame"));
212 private static Collection<IUserAction> profileActions(IConstructor constructor) {
213 if(_profileActions ==
null) {
216 if(_profileActions ==
null) {
217 _profileActions =
new ArrayList<>();
218 elephantProfileActions(constructor);
219 Set<String> menus = ElephantContext.getClassesByAnnotation(ProfileAction.class.getName());
221 for(String menu : menus) {
222 Object obj = ReflectionUtil.instance(ReflectionUtil.classCheck(menu));
223 if(obj instanceof IUserAction) {
224 if(((IUserAction) obj).isValid()) {
225 _profileActions.add((IUserAction) obj);
235 return _profileActions;
238 private static void elephantProfileActions(IConstructor constructor) {
239 String root = ElephantContext.getRootWebPath();
241 File file =
new File(ElephantContext.getRealPath(
"/user/my-data"));
243 _profileActions.add(
new DefaultUserAction(
"mydata",
"UAMyData",
244 root +
"/_zul/images/64/userMenu.png", root +
"/user/my-data"));
247 file =
new File(ElephantContext.getRealPath(
"/user/tellsomeone"));
249 _profileActions.add(
new DefaultUserAction(
"tellsome",
"UATellSomeone",
250 root +
"/_zul/images/64/favorite.png", root +
"/user/tellsomeone"));
static String getRealPath(String path)
static String getRootWebPath()
static Set< String > getClassesByAnnotation(Class annotationClass)
boolean isInRole(String role)