Source Code Cross Referenced for TreeNode.java in  » Web-Framework » JAT » com » jat » presentation » menu » 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 » Web Framework » JAT » com.jat.presentation.menu 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.jat.presentation.menu;
002:
003:        import java.util.Vector;
004:        import javax.servlet.http.HttpServletRequest;
005:
006:        import javax.swing.tree.DefaultMutableTreeNode;
007:        import com.jat.business.JatUser;
008:        import java.util.Enumeration;
009:        import com.jat.business.*;
010:        import com.jat.core.log.LogManager;
011:
012:        /**
013:         * <p>Title: JAT</p>
014:         * <p>Description: </p>
015:         * <p>Copyright: Copyright (c) 2004 -2005 Stefano Fratini (stefano.fratini@gmail.com)</p>
016:         * <p>Distributed under the terms of the GNU Lesser General Public License, v2.1 or later</p>
017:         * @author maurizio cesari
018:         * @version 1.1
019:         * @since 1.2
020:         */
021:
022:        public class TreeNode extends DefaultMutableTreeNode {
023:            private String url = "";
024:            private String icon = "";
025:            private String label = "";
026:            private String key = "";
027:            private String target = "";
028:            private String description = "";
029:            private Vector privileges = null;
030:            private boolean completed = false;
031:            private String section;
032:            private HttpServletRequest request;
033:
034:            public static Vector getAllNodes(String section, String key,
035:                    HttpServletRequest request) throws Exception {
036:                TreeNode tree = new TreeNode(section, key, request);
037:                Vector ret = new Vector();
038:                ret = ((TreeNode) tree.getRoot()).getChilds(ret);
039:                return ret;
040:            }
041:
042:            private Vector getChilds(Vector childs) {
043:                for (Enumeration e = this .children(); e.hasMoreElements();) {
044:                    TreeNode node = (TreeNode) e.nextElement();
045:                    if (node.isWritable()) {
046:                        childs.add(node);
047:                        childs = node.getChilds(childs);
048:                    }
049:                }
050:                return childs;
051:            }
052:
053:            protected TreeNode(String section, String key,
054:                    HttpServletRequest request) throws Exception {
055:                super ();
056:                this .section = section;
057:                if (this .section == null)
058:                    throw new Exception("Section not found");
059:                this .request = request;
060:                this .key = key;
061:                this .init();
062:            }
063:
064:            private TreeNode(String section, String key, String url,
065:                    String icon, String label, String target,
066:                    Vector privileges, HttpServletRequest request)
067:                    throws Exception {
068:                super ();
069:                this .section = section;
070:                this .key = key;
071:                this .url = url;
072:                this .icon = icon;
073:                this .label = label;
074:                this .target = target;
075:                this .privileges = privileges;
076:                this .request = request;
077:                loadChilds();
078:                this .completed = true;
079:            }
080:
081:            private void init() throws Exception {
082:                Vector menuVector = com.jat.core.config.Config.getCurrent()
083:                        .getSubKeys(section, key);
084:                for (Enumeration e = menuVector.elements(); e.hasMoreElements();) {
085:                    String childKey = (String) e.nextElement();
086:                    this .add(TreeNode.getTreeNode(section, childKey,
087:                            this .request));
088:                }
089:            }
090:
091:            private static TreeNode getTreeNode(String section, String key,
092:                    HttpServletRequest request) throws Exception {
093:                String label = com.jat.core.config.Config.getCurrent()
094:                        .getValue(section, key + ".label");
095:                String url = com.jat.core.config.Config.getCurrent().getValue(
096:                        section, key + ".url");
097:                if (url.indexOf("?") > 0)
098:                    url += "&menu_item=" + label;
099:                else
100:                    url += "?menu_item=" + label;
101:                String icon = com.jat.core.config.Config.getCurrent().getValue(
102:                        section, key + ".icon");
103:                String target = com.jat.core.config.Config.getCurrent()
104:                        .getValue(section, key + ".target");
105:                Vector privileges = new Vector();
106:                try {
107:                    privileges = com.jat.core.config.Config.getCurrent()
108:                            .getSubValues(section, key + ".privilege");
109:                } catch (Exception ignored) {
110:                }
111:                return new TreeNode(section, key, url, icon, label, target,
112:                        privileges, request);
113:            }
114:
115:            public String getKey() {
116:                return key;
117:            }
118:
119:            public String getTarget() {
120:                return target;
121:            }
122:
123:            public HttpServletRequest getRequest() {
124:                return request;
125:            }
126:
127:            public String getUrl() {
128:                return url;
129:            }
130:
131:            public String getIcon() {
132:                return icon;
133:            }
134:
135:            /** Per la selezione dell'icona associata all'item quando selezionato.
136:             * */
137:
138:            public String getSelectedIcon() {
139:                String app = getIcon();
140:                return app.substring(0, app.indexOf(".")) + "_sel"
141:                        + app.substring(app.indexOf("."), app.length());
142:            }
143:
144:            public String getLabel() {
145:                return label;
146:            }
147:
148:            public String getSection() {
149:                return section;
150:            }
151:
152:            public boolean isWritable() {
153:                if (this .isRoot())
154:                    return true;
155:                if (this .getLevel() > 1) {
156:                    if (!isSelected())
157:                        return false;
158:                }
159:                return this .hasPrivilege();
160:            }
161:
162:            private boolean isSelected() {
163:                String selectedItem = (String) this .request.getSession()
164:                        .getAttribute("MENU_ITEM_SELECTED");
165:                if (selectedItem == null)
166:                    return false;
167:                return this .getParent(1).hasChildSelected(selectedItem);
168:            }
169:
170:            private TreeNode getParent(int level) {
171:                if (this .getLevel() == level)
172:                    return this ;
173:                return ((com.jat.presentation.menu.TreeNode) this .getParent())
174:                        .getParent(level);
175:            }
176:
177:            private boolean hasChildSelected(String selectedItem) {
178:                if (this .getLabel().equals(selectedItem))
179:                    return true;
180:                if (this .isLeaf())
181:                    return false;
182:                for (Enumeration e = this .children(); e.hasMoreElements();) {
183:                    com.jat.presentation.menu.TreeNode child = (com.jat.presentation.menu.TreeNode) e
184:                            .nextElement();
185:                    if (child.hasChildSelected(selectedItem))
186:                        return true;
187:                }
188:                return false;
189:            }
190:
191:            public boolean hasPrivilege() {
192:                JatUser user = (JatUser) this .request.getSession()
193:                        .getAttribute(JatUser.JAT_USER);
194:                if (user == null)
195:                    return this .privileges == null
196:                            || this .privileges.size() < 1;
197:                else if (this .privileges != null && privileges.size() > 0) {
198:                    for (Enumeration e = this .privileges.elements(); e
199:                            .hasMoreElements();) {
200:                        try {
201:                            if (user.hasPrivilege((String) e.nextElement(),
202:                                    null))
203:                                return true;
204:                        } catch (BusinessException ex) {
205:                            LogManager.sendError(this .getClass().getName()
206:                                    + "::hasPrivilege: exception: " + ex);
207:                        }
208:                    }
209:                    return false;
210:                }
211:                return true;
212:            }
213:
214:            public String getMenuClass(String position) {
215:                return "MenuLiv" + super .getLevel() + position; // esempio: "Left"
216:            }
217:
218:            public int getColSpanLabel() {
219:                return getLevels() + 1 - getLevel();
220:            }
221:
222:            public int getColSpanSeparator() {
223:                return getLevels() + 4;
224:            }
225:
226:            private void loadChilds() throws Exception {
227:                Vector childKeys = com.jat.core.config.Config.getCurrent()
228:                        .getSubKeys(section, key + ".child");
229:                for (Enumeration e = childKeys.elements(); e.hasMoreElements();) {
230:                    TreeNode node = TreeNode.getTreeNode(section, (String) e
231:                            .nextElement(), this .request);
232:                    add(node);
233:                }
234:            }
235:
236:            public int getLevels() {
237:                return ((TreeNode) super .getRoot()).getDepth();
238:            }
239:
240:            public String toString() {
241:                description = "Nodo:[url=" + url + "],[icon=" + icon
242:                        + "],[label=" + label + "],[key=" + key + "],[level="
243:                        + super .getLevel() + "][depth=" + this .getDepth() + "]";
244:                return description;
245:            }
246:
247:            public String toStringSimple() {
248:                description = "<p>[key=" + key + "],[level=" + super .getLevel()
249:                        + "][depth=" + this .getDepth() + "]</p>";
250:                return description;
251:            }
252:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.