Source Code Cross Referenced for Controller.java in  » Ajax » MyGWT » net » mygwt » ui » client » mvc » 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 » Ajax » MyGWT » net.mygwt.ui.client.mvc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * MyGWT Widget Library
003:         * Copyright(c) 2007, MyGWT.
004:         * licensing@mygwt.net
005:         * 
006:         * http://mygwt.net/license
007:         */
008:        package net.mygwt.ui.client.mvc;
009:
010:        import java.util.ArrayList;
011:        import java.util.HashSet;
012:        import java.util.List;
013:
014:        /**
015:         * <code>Controllers</code> process and respond to application events.
016:         */
017:        public abstract class Controller {
018:
019:            /**
020:             * Forward an event to a view. Ensures the view is initialized before
021:             * forwarding the event.
022:             * 
023:             * @param view the view to forward the event
024:             * @param event the event to be forwarded
025:             */
026:            public static void forwardToView(View view, AppEvent event) {
027:                if (!view.initialized) {
028:                    view.initialize();
029:                    view.initialized = true;
030:                }
031:                view.handleEvent(event);
032:            }
033:
034:            protected Controller parent;
035:            protected List children;
036:
037:            boolean initialized;
038:            private HashSet events;
039:
040:            /**
041:             * Add a child controller.
042:             * 
043:             * @param controller the controller to added
044:             */
045:            public void addChild(Controller controller) {
046:                if (children == null)
047:                    children = new ArrayList();
048:                children.add(controller);
049:                controller.parent = this ;
050:            }
051:
052:            /**
053:             * Determines if the controller can handle the particular event. Default
054:             * implementation checks against registered event types then queries all child
055:             * controllers.
056:             * 
057:             * @param event the event
058:             * @return <code>true</code> if event can be handled, <code>false</code>
059:             *         otherwise
060:             */
061:            public boolean canHandle(AppEvent event) {
062:                if (events != null && events.contains(new Integer(event.type)))
063:                    return true;
064:                if (children != null) {
065:                    for (int i = 0; i < children.size(); i++) {
066:                        Controller c = (Controller) children.get(i);
067:                        if (c.canHandle(event))
068:                            return true;
069:                    }
070:                }
071:                return false;
072:            }
073:
074:            /**
075:             * Forwards an event to any child controllers who can handle the event.
076:             * 
077:             * @param event the event to forward
078:             */
079:            public void forwardToChild(AppEvent event) {
080:                if (children != null) {
081:                    for (int i = 0; i < children.size(); i++) {
082:                        Controller c = (Controller) children.get(i);
083:                        if (!c.initialized) {
084:                            c.initialize();
085:                            c.initialized = true;
086:                        }
087:                        if (c.canHandle(event)) {
088:                            c.handleEvent(event);
089:                        }
090:                    }
091:                }
092:            }
093:
094:            /**
095:             * Processes the event.
096:             * 
097:             * @param event the current event
098:             */
099:            public abstract void handleEvent(AppEvent event);
100:
101:            /**
102:             * Called once prior to handleEvent being called.
103:             */
104:            public void initialize() {
105:
106:            }
107:
108:            /**
109:             * Registers the event type.
110:             * 
111:             * @param type the event type
112:             */
113:            public void registerEventType(int type) {
114:                if (events == null) {
115:                    events = new HashSet();
116:                }
117:                events.add(new Integer(type));
118:            }
119:
120:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.