Source Code Cross Referenced for EventHandlerMap.java in  » Ajax » zk » org » zkoss » zk » ui » metainfo » 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 » zk » org.zkoss.zk.ui.metainfo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* EventHandlerMap.java
002:
003:        {{IS_NOTE
004:        	Purpose:
005:        		
006:        	Description:
007:        		
008:        	History:
009:        		Wed Mar 28 16:28:40     2007, Created by tomyeh
010:        }}IS_NOTE
011:
012:        Copyright (C) 2007 Potix Corporation. All Rights Reserved.
013:
014:        {{IS_RIGHT
015:        	This program is distributed under GPL Version 2.0 in the hope that
016:        	it will be useful, but WITHOUT ANY WARRANTY.
017:        }}IS_RIGHT
018:         */
019:        package org.zkoss.zk.ui.metainfo;
020:
021:        import java.util.Set;
022:        import java.util.Collections;
023:        import java.util.List;
024:        import java.util.LinkedList;
025:        import java.util.Map;
026:        import java.util.HashMap;
027:        import java.util.Iterator;
028:
029:        import org.zkoss.lang.Objects;
030:        import org.zkoss.zk.ui.Component;
031:
032:        /**
033:         * A map of instances of {@link EventHandler}.
034:         *
035:         * <p>Note: it is not thread safe. Thus, it is better to {@link #clone}
036:         * and then modifying the cloned instance if you want to change it
037:         * concurrently.
038:         *
039:         * @author tomyeh
040:         */
041:        public class EventHandlerMap implements  Cloneable, java.io.Serializable {
042:            /** The event handler map, (String evtnm, EventHandler evthd).
043:             */
044:            private Map _evthds;
045:
046:            /** Returns whether no event handler at all.
047:             */
048:            public boolean isEmpty() {
049:                return _evthds == null || _evthds.isEmpty();
050:            }
051:
052:            /** Returns the first effective event handler of the specified event name,
053:             * or null if not available.
054:             *
055:             * <p>It checks whether an event handler is effective by calling
056:             * {@link EventHandler#isEffective(Component)}.
057:             *
058:             * @param comp the component used to evaluate whether an event handler
059:             * is effective.
060:             * @see EventHandler#isEffective(Component)
061:             * @since 3.0.0
062:             */
063:            public EventHandler get(Component comp, String evtnm) {
064:                if (_evthds != null) {
065:                    final List ehl = (List) _evthds.get(evtnm);
066:                    if (ehl != null) {
067:                        for (Iterator it = ehl.iterator(); it.hasNext();) {
068:                            final EventHandler eh = (EventHandler) it.next();
069:                            if (eh.isEffective(comp))
070:                                return eh;
071:                        }
072:                    }
073:                }
074:                return null;
075:            }
076:
077:            /** Returns a readonly collection of event names (String), or
078:             * an empty collection if no event name is registered.
079:             * @since 3.0.2
080:             */
081:            public Set getEventNames() {
082:                return _evthds != null ? _evthds.keySet()
083:                        : Collections.EMPTY_SET;
084:            }
085:
086:            /** Returns a readonly list of all event handlers associated
087:             * with the specified event name, or null if no handler is associated
088:             * with.
089:             *
090:             * <p>Unlike {@link #get(Component,String)}, it returns all
091:             * event handlers no matter whether they are effective.
092:             *
093:             * @since 3.0.0
094:             */
095:            public List getAll(String evtnm) {
096:                if (_evthds != null)
097:                    return (List) _evthds.get(evtnm);
098:                return null;
099:            }
100:
101:            /**
102:             * @deprecated As of release 3.0.0, replaced by getAll(evtnm)[0].
103:             * See also {@link #get(Component, String)} or {@link #getAll}
104:             */
105:            public EventHandler get(String evtnm) {
106:                if (_evthds != null) {
107:                    final List ehl = (List) _evthds.get(evtnm);
108:                    if (ehl != null)
109:                        return (EventHandler) ehl.get(0); //must not empty
110:                }
111:                return null;
112:            }
113:
114:            /** Adds the event handler for the specified event name.
115:             * <p>Note: the new handler won't overwrite the previous one,
116:             * unless {@link EventHandler#getCondition} is the same.
117:             * Rather, the new handler is appended to the list. You can retreive
118:             * list by invoking {@link #getAll}.
119:             *
120:             * @see #getAll
121:             * @since 3.0.0
122:             */
123:            public void add(String evtnm, EventHandler evthd) {
124:                if (evtnm == null || evthd == null)
125:                    throw new IllegalArgumentException("null");
126:
127:                if (_evthds == null)
128:                    _evthds = new HashMap(4);
129:
130:                List ehl = (List) _evthds.get(evtnm);
131:                if (ehl == null) {
132:                    _evthds.put(evtnm, ehl = new LinkedList());
133:                } else {
134:                    for (Iterator it = ehl.iterator(); it.hasNext();) {
135:                        final EventHandler eh = (EventHandler) it.next();
136:                        if (Objects.equals(eh.getCondition(), evthd
137:                                .getCondition()))
138:                            it.remove(); //replicate
139:                    }
140:                }
141:
142:                ehl.add(evthd);
143:            }
144:
145:            /** Adds all event handlers of the specified map to this map.
146:             */
147:            public void addAll(EventHandlerMap src) {
148:                if (src != null && !src.isEmpty()) {
149:                    for (Iterator it = src._evthds.entrySet().iterator(); it
150:                            .hasNext();) {
151:                        final Map.Entry me = (Map.Entry) it.next();
152:                        final String evtnm = (String) me.getKey();
153:                        final List srcl = (List) me.getValue();
154:                        for (Iterator e = srcl.iterator(); e.hasNext();)
155:                            add(evtnm, (EventHandler) e.next());
156:                    }
157:                }
158:            }
159:
160:            //Cloneable//
161:            /** Clones this event handler map.
162:             */
163:            public Object clone() {
164:                final EventHandlerMap clone = new EventHandlerMap();
165:                clone.addAll(this );
166:                return clone;
167:            }
168:
169:            //Object//
170:            public String toString() {
171:                return "[evthd:" + _evthds + ']';
172:            }
173:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.