Source Code Cross Referenced for MenuBarBean.java in  » Content-Management-System » contineo » org » contineo » web » navigation » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » contineo » org.contineo.web.navigation 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.contineo.web.navigation;
002:
003:        import org.apache.commons.lang.StringUtils;
004:        import org.apache.commons.logging.Log;
005:        import org.apache.commons.logging.LogFactory;
006:
007:        import org.contineo.core.security.Menu;
008:        import org.contineo.core.security.dao.MenuDAO;
009:
010:        import org.contineo.util.Context;
011:
012:        import org.contineo.web.SessionManagement;
013:        import org.contineo.web.StyleBean;
014:        import org.contineo.web.i18n.Messages;
015:
016:        import java.util.ArrayList;
017:        import java.util.Collection;
018:        import java.util.List;
019:
020:        import javax.faces.context.FacesContext;
021:        import javax.faces.el.MethodBinding;
022:        import javax.faces.event.ActionEvent;
023:
024:        /**
025:         * <p>
026:         * The MenuBarBean class determines which menu item fired the ActionEvent and
027:         * stores the modified id information in a String. MenuBarBean also controls the
028:         * orientation of the Menu Bar.
029:         * </p>
030:         *
031:         * @author Marco Meschieri
032:         * @version $Id: MenuBarBean.java,v 1.9 2007/10/11 16:33:56 marco Exp $
033:         * @since 3.0
034:         */
035:        public class MenuBarBean {
036:            protected static Log logger = LogFactory.getLog(MenuBarBean.class);
037:
038:            // records which menu item fired the event
039:            private String actionFired;
040:
041:            // records the param value for the menu item which fired the event
042:            private String param;
043:
044:            // orientation of the menubar ("horizontal" or "vertical")
045:            private String orientation = "horizontal";
046:
047:            // list for the dynamic menus w/ getter & setter
048:            protected List<MenuItem> model = new ArrayList<MenuItem>();
049:            private NavigationBean navigation;
050:
051:            /**
052:             * Get the param value for the menu item which fired the event.
053:             *
054:             * @return the param value
055:             */
056:            public String getParam() {
057:                return param;
058:            }
059:
060:            /**
061:             * Set the param value.
062:             */
063:            public void setParam(String param) {
064:                this .param = param;
065:            }
066:
067:            /**
068:             * Get the modified ID of the fired action.
069:             *
070:             * @return the modified ID
071:             */
072:            public String getActionFired() {
073:                return actionFired;
074:            }
075:
076:            public List<MenuItem> getModel() {
077:                if (model.isEmpty()) {
078:                    createMenuItems();
079:                }
080:
081:                return model;
082:            }
083:
084:            public void setModel(List<MenuItem> model) {
085:                this .model = model;
086:            }
087:
088:            /**
089:             * Identify the ID of the element that fired the event and return it in a
090:             * form suitable for display.
091:             *
092:             * @param e the event that fired the listener
093:             */
094:            public void primaryListener(ActionEvent e) {
095:                MenuItem menu = (MenuItem) e.getSource();
096:
097:                if (StringUtils.isNotEmpty(menu.getContent().getTemplate())) {
098:                    navigation.setSelectedPanel(menu.getContent());
099:                }
100:            }
101:
102:            /**
103:             * Get the orientation of the menu ("horizontal" or "vertical")
104:             *
105:             * @return the orientation of the menu
106:             */
107:            public String getOrientation() {
108:                return orientation;
109:            }
110:
111:            /**
112:             * Set the orientation of the menu ("horizontal" or "vertical").
113:             *
114:             * @param orientation the new orientation of the menu
115:             */
116:            public void setOrientation(String orientation) {
117:                this .orientation = orientation;
118:            }
119:
120:            /**
121:             * Finds all first-level menus accessible by the current user
122:             *
123:             * @return
124:             */
125:            protected void createMenuItems() {
126:                model.clear();
127:
128:                String username = SessionManagement.getUsername();
129:                PageContentBean page = new PageContentBean("home", "home");
130:                page.setContentTitle("Home");
131:                page.setDisplayText("Home");
132:                page.setIcon(StyleBean.getImagePath("home.png"));
133:
134:                MenuItem item = createMenuItem("home", null,
135:                        "#{menuBar.primaryListener}", null, null, StyleBean
136:                                .getImagePath("home.png"), false, null, page);
137:                model.add(item);
138:
139:                try {
140:                    if (username != null) {
141:                        MenuDAO menuDao = (MenuDAO) Context.getInstance()
142:                                .getBean(MenuDAO.class);
143:                        Collection<Menu> menus = menuDao.findByUserName(
144:                                username, 1);
145:
146:                        for (Menu menu : menus) {
147:                            createMenuStructure(menu, null);
148:                        }
149:                    }
150:                } catch (Throwable t) {
151:                    logger.error(t.getMessage(), t);
152:                }
153:
154:                MenuItem helpMenu = createMenuItem("Help", "m-help",
155:                        "#{menuBar.primaryListener}", null, null, StyleBean
156:                                .getImagePath("help.png"), false, null, null);
157:
158:                PageContentBean infoPage = new PageContentBean("info", "info");
159:                infoPage.setContentTitle(Messages.getMessage("msg.jsp.info"));
160:                helpMenu.getChildren().add(
161:                        createMenuItem("About Contineo", "m-about",
162:                                "#{menuBar.primaryListener}", null, null,
163:                                StyleBean.getImagePath("about.png"), false,
164:                                null, infoPage));
165:                model.add(helpMenu);
166:            }
167:
168:            private void createMenuStructure(Menu menu, MenuItem parent) {
169:                PageContentBean page;
170:                MenuItem item;
171:                page = new PageContentBean("m-"
172:                        + Integer.toString(menu.getMenuId()));
173:
174:                if (StringUtils.isNotEmpty(menu.getMenuRef())) {
175:                    page.setTemplate(menu.getMenuRef());
176:                }
177:
178:                page.setContentTitle(Messages.getMessage(menu.getMenuText()));
179:                page.setIcon(StyleBean.getImagePath(menu.getMenuIcon()));
180:
181:                item = createMenuItem(Messages.getMessage(menu.getMenuText()),
182:                        "m-" + Integer.toString(menu.getMenuId()),
183:                        "#{menuBar.primaryListener}", null, null, (menu
184:                                .getMenuIcon() != null) ? StyleBean
185:                                .getImagePath(menu.getMenuIcon()) : null,
186:                        false, null, page);
187:
188:                if (parent == null) {
189:                    model.add(item);
190:                } else {
191:                    parent.getChildren().add(item);
192:                }
193:
194:                // For 'Documents' menu, skip children
195:                if (menu.getMenuId() != Menu.MENUID_DOCUMENTS) {
196:                    MenuDAO menuDao = (MenuDAO) Context.getInstance().getBean(
197:                            MenuDAO.class);
198:                    Collection<Menu> children = menuDao.findByUserName(
199:                            SessionManagement.getUsername(), menu.getMenuId());
200:
201:                    for (Menu child : children) {
202:                        createMenuStructure(child, item);
203:                    }
204:                }
205:            }
206:
207:            protected MenuItem createMenuItem(String label, String id,
208:                    String actionListener, String action, String link,
209:                    String icon, boolean immediate, String target,
210:                    PageContentBean content) {
211:                MenuItem menuItem = new MenuItem();
212:                menuItem.setValue(label);
213:
214:                if (id != null) {
215:                    menuItem.setId(id);
216:                }
217:
218:                if (actionListener != null) {
219:                    menuItem
220:                            .setActionListener(createActionListenerMethodBinding(actionListener));
221:                }
222:
223:                if (action != null) {
224:                    menuItem.setAction(createActionMethodBinding(action));
225:                }
226:
227:                if (link != null) {
228:                    menuItem.setLink(link);
229:                }
230:
231:                if (icon != null) {
232:                    menuItem.setIcon(icon);
233:                }
234:
235:                menuItem.setImmediate(immediate);
236:
237:                if (target != null) {
238:                    menuItem.setTarget(target);
239:                }
240:
241:                if (content != null) {
242:                    menuItem.setContent(content);
243:                }
244:
245:                return menuItem;
246:            }
247:
248:            protected MethodBinding createActionListenerMethodBinding(
249:                    String actionListenerString) {
250:                Class[] args = { ActionEvent.class };
251:                MethodBinding methodBinding = null;
252:
253:                methodBinding = FacesContext.getCurrentInstance()
254:                        .getApplication().createMethodBinding(
255:                                actionListenerString, args);
256:
257:                return methodBinding;
258:            }
259:
260:            protected MethodBinding createActionMethodBinding(String action) {
261:                Class[] args = {};
262:                MethodBinding methodBinding = null;
263:
264:                methodBinding = FacesContext.getCurrentInstance()
265:                        .getApplication().createMethodBinding(action, args);
266:
267:                return methodBinding;
268:            }
269:
270:            public void setNavigation(NavigationBean navigation) {
271:                this.navigation = navigation;
272:            }
273:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.