Source Code Cross Referenced for MenuBuilder.java in  » ERP-CRM-Financial » Personal-Finance-Manager » br » com » igor » builder » 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 » ERP CRM Financial » Personal Finance Manager » br.com.igor.builder.menu 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on 07/03/2004
003:         * 
004:         * Swing Components - visit http://sf.net/projects/gfd
005:         * 
006:         * Copyright (C) 2004  Igor Regis da Silva Simões
007:         * 
008:         * This program is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public License
010:         * as published by the Free Software Foundation; either version 2
011:         * of the License, or (at your option) any later version.
012:         *
013:         * This program is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         * GNU General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public License
019:         * along with this program; if not, write to the Free Software
020:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
021:         * 
022:         */
023:
024:        package br.com.igor.builder.menu;
025:
026:        import java.awt.Component;
027:        import java.awt.event.ActionListener;
028:        import java.net.URL;
029:        import java.util.ArrayList;
030:        import java.util.Enumeration;
031:        import java.util.Iterator;
032:
033:        import javax.swing.JMenu;
034:        import javax.swing.JMenuItem;
035:        import javax.swing.JSeparator;
036:        import javax.swing.event.MenuEvent;
037:        import javax.swing.event.MenuListener;
038:        import javax.xml.parsers.DocumentBuilder;
039:        import javax.xml.parsers.DocumentBuilderFactory;
040:
041:        import org.w3c.dom.Document;
042:        import org.w3c.dom.NamedNodeMap;
043:        import org.w3c.dom.Node;
044:        import org.w3c.dom.NodeList;
045:
046:        import br.com.igor.beans.aplicativos.IconeFactory;
047:        import br.com.igor.plugin.core.DynamicClassLoader;
048:
049:        /**
050:         * @author Igor Regis da Silva Simões
051:         */
052:        public abstract class MenuBuilder extends JMenu {
053:            protected MenuBuilderListener listener = new MenuBuilderListener();
054:
055:            private ArrayList menuItens = new ArrayList();
056:
057:            private DynamicClassLoader classLoader = DynamicClassLoader
058:                    .getClassLoader();
059:
060:            /**
061:             * Cria uma nova instância de MenuJanelaFacotry
062:             * @param xmlFile Endereço do arquivo xml
063:             * @param fileOpen boolean indicando se existe um arquivo aberto
064:             * @throws MenuCreationException
065:             */
066:            @SuppressWarnings("unchecked")
067:            public MenuBuilder(final String xmlFile, final boolean fileOpen)
068:                    throws MenuCreationException {
069:                //Por enquando não vale a pena colocar a criação dos menu em Thread separada
070:                //        (new Thread(){
071:                //            {
072:                //                setPriority(Thread.MIN_PRIORITY);
073:                //                setDaemon(true);
074:                //            }
075:                //            public void run()
076:                //            {
077:                try {
078:                    Enumeration enu = DynamicClassLoader.getClassLoader()
079:                            .getResources(xmlFile);
080:                    while (enu.hasMoreElements()) //for each xml file...
081:                    {
082:                        DocumentBuilderFactory factory = DocumentBuilderFactory
083:                                .newInstance();
084:                        factory.setValidating(true);
085:                        factory.setNamespaceAware(true);
086:
087:                        URL url = (URL) enu.nextElement();
088:
089:                        DocumentBuilder builder = factory.newDocumentBuilder();
090:                        Document document = builder.parse(url.openStream(), url
091:                                .toString()); //We load/parse the file
092:
093:                        NodeList menus = document.getLastChild()
094:                                .getChildNodes();//get the menus definition inside this file
095:
096:                        for (int i = 0; i < menus.getLength(); i++)//for each menu entry
097:                        {
098:                            Node n = null;
099:                            if ((n = menus.item(i)).getNodeName().equals(
100:                                    "MenuItem"))//We build a MenuItem
101:                            {
102:                                NamedNodeMap atributos = n.getAttributes();
103:                                Node atributo = null;
104:
105:                                JMenuItem item = new JMenuItem();
106:                                item
107:                                        .setText((atributos
108:                                                .getNamedItem("Icone") == null ? "       "
109:                                                : "")
110:                                                + MenuBuilderMessages
111:                                                        .getMessages()
112:                                                        .getString(
113:                                                                n
114:                                                                        .getLastChild()
115:                                                                        .getNodeValue()
116:                                                                        .trim()));
117:
118:                                if ((atributo = atributos
119:                                        .getNamedItem("SecurityName")) != null)
120:                                    item.setEnabled(hasAccess(atributo
121:                                            .getNodeValue()));
122:                                if ((atributo = atributos
123:                                        .getNamedItem("Action")) != null)
124:                                    item
125:                                            .addActionListener((ActionListener) classLoader
126:                                                    .loadClass(
127:                                                            atributo
128:                                                                    .getNodeValue())
129:                                                    .getDeclaredMethod(
130:                                                            "getAction",
131:                                                            new Class[] {})
132:                                                    .invoke(null,
133:                                                            new Object[] {}));
134:                                if ((atributo = atributos
135:                                        .getNamedItem("Command")) != null)
136:                                    item.setActionCommand(atributo
137:                                            .getNodeValue().trim());
138:                                if ((atributo = atributos
139:                                        .getNamedItem("Mnemonic")) != null)
140:                                    item.setMnemonic(MenuBuilderMessages
141:                                            .getMessages().getString(
142:                                                    atributo.getNodeValue())
143:                                            .charAt(0));
144:                                if ((atributo = atributos
145:                                        .getNamedItem("ToolTip")) != null)
146:                                    item.setToolTipText(MenuBuilderMessages
147:                                            .getMessages().getString(
148:                                                    atributo.getNodeValue()
149:                                                            .trim()));
150:                                if ((atributo = atributos.getNamedItem("Icone")) != null)
151:                                    item.setIcon(IconeFactory.getIconeFactory()
152:                                            .getImageIcon(
153:                                                    atributo.getNodeValue()));
154:                                if (!fileOpen
155:                                        && (atributo = atributos
156:                                                .getNamedItem("NeedFileOpen")) != null)
157:                                    item.setEnabled(!Boolean.valueOf(
158:                                            atributo.getNodeValue())
159:                                            .booleanValue());
160:
161:                                MenuBuilder.this .menuItens.add(item);
162:                            } else if ((n = menus.item(i)).getNodeName()
163:                                    .equals("Separator"))//We build a Separator
164:                            {
165:                                MenuBuilder.this .menuItens
166:                                        .add(new JSeparator());
167:                            } else if ((n = menus.item(i)).getNodeName()
168:                                    .equals("MenuInterno"))//We build a Submenu
169:                            {
170:
171:                                NamedNodeMap atributos = n.getAttributes();
172:                                Node atributo = null;
173:                                String builderName = null;
174:                                /*TODO É necessário controle de acesso para menus?
175:                                if ((atributo = atributos.getNamedItem("SecurityName")) != null)
176:                                	System.out.println(atributo.getNodeValue());
177:                                 */
178:
179:                                builderName = atributos.getNamedItem("Builder")
180:                                        .getNodeValue();
181:                                JMenu menu = (JMenu) classLoader.loadClass(
182:                                        builderName).getConstructor(
183:                                        new Class[] { boolean.class })
184:                                        .newInstance(
185:                                                new Object[] { Boolean
186:                                                        .valueOf(fileOpen) });
187:
188:                                menu.setText("       "
189:                                        + MenuBuilderMessages.getMessages()
190:                                                .getString(
191:                                                        n.getLastChild()
192:                                                                .getNodeValue()
193:                                                                .trim()));
194:
195:                                if ((atributo = atributos
196:                                        .getNamedItem("Mnemonic")) != null)
197:                                    menu.setMnemonic(atributo.getNodeValue()
198:                                            .charAt(0));
199:
200:                                MenuBuilder.this .menuItens.add(menu);
201:                            }
202:                        }
203:                    }
204:                } catch (Exception e) {
205:                    throw new MenuCreationException(e);
206:                }
207:
208:                rebuildMenu(false);
209:                addMenuListener(listener);
210:            }
211:
212:            //    }).start();
213:            //	}
214:
215:            /**
216:             * Indica se o usuário atual possui acesso pára o determinado nivel de segurança
217:             * @param securityLevel Nivel de segurança a ser checado o direito de acesso
218:             * @return Indica false caso o ususário não possua acesso
219:             */
220:            public abstract boolean hasAccess(String securityLevel);
221:
222:            /**
223:             *	Este meptodo reconstrói o menu 
224:             * @param removeAll Indica se devem ser removidos todos os itens
225:             */
226:            protected void rebuildMenu(boolean removeAll) {
227:                if (removeAll)
228:                    this .removeAll();
229:
230:                Iterator menus = this .menuItens.iterator();
231:                while (menus.hasNext()) {
232:                    add((Component) menus.next());
233:                }
234:            }
235:
236:            /**
237:             *
238:             */
239:            private class MenuBuilderListener implements  MenuListener {
240:                /**
241:                 * @see javax.swing.event.MenuListener#menuSelected(javax.swing.event.MenuEvent)
242:                 */
243:                public void menuSelected(MenuEvent e) {
244:                    rebuildMenu(true);
245:                }
246:
247:                /**
248:                 * @see javax.swing.event.MenuListener#menuDeselected(javax.swing.event.MenuEvent)
249:                 */
250:                public void menuDeselected(MenuEvent e) {
251:                    // TODO Auto-generated method stub
252:
253:                }
254:
255:                /**
256:                 * @see javax.swing.event.MenuListener#menuCanceled(javax.swing.event.MenuEvent)
257:                 */
258:                public void menuCanceled(MenuEvent e) {
259:                    // TODO Auto-generated method stub
260:
261:                }
262:            }
263:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.