Source Code Cross Referenced for Dispatcher.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.List;
012:
013:        import net.mygwt.ui.client.event.BaseEvent;
014:        import net.mygwt.ui.client.util.Observable;
015:
016:        /**
017:         * Dispatchers are responsible for dispatching application events to
018:         * controllers.
019:         * 
020:         * <dl>
021:         * <dt><b>Events:</b></dt>
022:         * 
023:         * <dd><b>Dispatcher.BeforeDispatch</b> : (source, value)<br>
024:         * <div>Fires before an event is dispatched. Listeners can set the
025:         * <code>doit</code> field to <code>false</code> to cancel the action.</div>
026:         * <ul>
027:         * <li>source : this</li>
028:         * <li>value : the app event</li>
029:         * </ul>
030:         * </dd>
031:         * 
032:         * <dd><b>Dispatcher.AfterDispatch</b> : (source, data)<br>
033:         * <div>Fires after an event has been dispatched.</div>
034:         * <ul>
035:         * <li>source : this</li>
036:         * <li>value : the app event</li>
037:         * </ul>
038:         * </dd>
039:         * 
040:         * </dl>
041:         * 
042:         * @see DispatcherListener
043:         */
044:        public class Dispatcher extends Observable {
045:
046:            /**
047:             * Fires before an event is dispatched (value is 1100).
048:             */
049:            public static final int BeforeDispatch = 1100;
050:
051:            /**
052:             * Fires after an event has been dispatched (value is 1110).
053:             */
054:            public static final int AfterDispatch = 1110;
055:
056:            private static Dispatcher instance;
057:
058:            /**
059:             * Forwards an app event to the dispatcher.
060:             * 
061:             * @param event the app event
062:             */
063:            public static void forwardEvent(AppEvent event) {
064:                instance.dispatch(event);
065:            }
066:
067:            /**
068:             * Creates and forwards an app event to the dispatcher.
069:             * 
070:             * @param eventType the app event type
071:             */
072:            public static void forwardEvent(int eventType) {
073:                instance.dispatch(eventType);
074:            }
075:
076:            /**
077:             * Returns the singleton instance.
078:             * 
079:             * @return the dispatcher
080:             */
081:            public static Dispatcher get() {
082:                if (instance == null) {
083:                    instance = new Dispatcher();
084:                }
085:                return instance;
086:            }
087:
088:            private List controllers;
089:
090:            private Dispatcher() {
091:                instance = this ;
092:                controllers = new ArrayList();
093:            }
094:
095:            /**
096:             * Adds a controller.
097:             * 
098:             * @param controller the controller to be added
099:             */
100:            public void addController(Controller controller) {
101:                if (!controllers.contains(controller)) {
102:                    controllers.add(controller);
103:                }
104:            }
105:
106:            /**
107:             * Adds a listener to receive dispatch events.
108:             * 
109:             * @param listener the listener to add
110:             */
111:            public void addDispatcherListener(DispatcherListener listener) {
112:                DispatcherTypedListener typedListener = new DispatcherTypedListener(
113:                        listener);
114:                addListener(BeforeDispatch, typedListener);
115:                addListener(AfterDispatch, typedListener);
116:            }
117:
118:            /**
119:             * The dispatcher will query its controllers and pass the app event to any
120:             * controllers that can handle the particular event type.
121:             * 
122:             * @param event the app event
123:             */
124:            public void dispatch(AppEvent event) {
125:                BaseEvent be = new BaseEvent();
126:                be.source = this ;
127:                be.value = event;
128:                if (fireEvent(BeforeDispatch, be)) {
129:                    for (int i = 0; i < controllers.size(); i++) {
130:                        Controller controller = (Controller) controllers.get(i);
131:                        if (controller.canHandle(event)) {
132:                            if (!controller.initialized) {
133:                                controller.initialized = true;
134:                                controller.initialize();
135:                            }
136:                            controller.handleEvent(event);
137:                        }
138:                    }
139:                    fireEvent(AfterDispatch, be);
140:                }
141:            }
142:
143:            /**
144:             * The dispatcher will query its controllers and pass the app event to
145:             * controllers that can handle the particular event type.
146:             * 
147:             * @param type the event type
148:             */
149:            public void dispatch(int type) {
150:                dispatch(new AppEvent(type));
151:            }
152:
153:            /**
154:             * The dispatcher will query its controllers and pass the app event to
155:             * controllers that can handle the particular event type.
156:             * 
157:             * @param type the event type
158:             * @param data the app event data
159:             */
160:            public void dispatch(int type, Object data) {
161:                dispatch(new AppEvent(type, data));
162:            }
163:
164:            /**
165:             * Returns all controllers.
166:             * 
167:             * @return the list of controllers
168:             */
169:            public List getControllers() {
170:                return controllers;
171:            }
172:
173:            /**
174:             * Removes a controller.
175:             * 
176:             * @param controller the controller to be removed
177:             */
178:            public void removeController(Controller controller) {
179:                controllers.remove(controller);
180:            }
181:
182:            /**
183:             * Removes a previously added listener.
184:             * 
185:             * @param listener the listener to be removed
186:             */
187:            public void removeDispatcherListener(DispatcherListener listener) {
188:                if (eventTable != null) {
189:                    eventTable.unhook(BeforeDispatch, listener);
190:                    eventTable.unhook(AfterDispatch, listener);
191:                }
192:            }
193:
194:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.