Source Code Cross Referenced for AbstractHandler.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » commands » 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 » IDE Eclipse » ui workbench » org.eclipse.ui.commands 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2004, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.ui.commands;
011:
012:        import java.util.ArrayList;
013:        import java.util.Collections;
014:        import java.util.HashMap;
015:        import java.util.List;
016:        import java.util.Map;
017:
018:        import org.eclipse.core.commands.ExecutionEvent;
019:        import org.eclipse.core.commands.ExecutionException;
020:        import org.eclipse.core.commands.HandlerEvent;
021:        import org.eclipse.core.commands.IHandlerAttributes;
022:        import org.eclipse.core.commands.IHandlerListener;
023:
024:        /**
025:         * This class is a partial implementation of <code>IHandler</code>. This
026:         * abstract implementation provides support for handler listeners. You should
027:         * subclass from this method unless you want to implement your own listener
028:         * support. Subclasses should call
029:         * {@link AbstractHandler#fireHandlerChanged(HandlerEvent)}when the handler
030:         * changes. Subclasses should also override
031:         * {@link AbstractHandler#getAttributeValuesByName()}if they have any
032:         * attributes.
033:         * 
034:         * @since 3.0
035:         * @deprecated Please use the "org.eclipse.core.commands" plug-in instead.
036:         * @see org.eclipse.core.commands.AbstractHandler
037:         */
038:        public abstract class AbstractHandler extends
039:                org.eclipse.core.commands.AbstractHandler implements  IHandler {
040:
041:            /**
042:             * Those interested in hearing about changes to this instance of
043:             * <code>IHandler</code>. This member is null iff there are
044:             * no listeners attached to this handler. (Most handlers don't
045:             * have any listeners, and this optimization saves some memory.)
046:             */
047:            private List handlerListeners;
048:
049:            /**
050:             * @see IHandler#addHandlerListener(IHandlerListener)
051:             */
052:            public void addHandlerListener(
053:                    org.eclipse.ui.commands.IHandlerListener handlerListener) {
054:                if (handlerListener == null) {
055:                    throw new NullPointerException();
056:                }
057:                if (handlerListeners == null) {
058:                    handlerListeners = new ArrayList();
059:                }
060:                if (!handlerListeners.contains(handlerListener)) {
061:                    handlerListeners.add(handlerListener);
062:                }
063:            }
064:
065:            /**
066:             * The default implementation does nothing. Subclasses who attach listeners
067:             * to other objects are encouraged to detach them in this method.
068:             * 
069:             * @see org.eclipse.ui.commands.IHandler#dispose()
070:             */
071:            public void dispose() {
072:                // Do nothing.
073:            }
074:
075:            public Object execute(final ExecutionEvent event)
076:                    throws ExecutionException {
077:                try {
078:                    return execute(event.getParameters());
079:                } catch (final org.eclipse.ui.commands.ExecutionException e) {
080:                    throw new ExecutionException(e.getMessage(), e.getCause());
081:                }
082:            }
083:
084:            /**
085:             * Fires an event to all registered listeners describing changes to this
086:             * instance.
087:             * 
088:             * @param handlerEvent
089:             *            the event describing changes to this instance. Must not be
090:             *            <code>null</code>.
091:             */
092:            protected void fireHandlerChanged(HandlerEvent handlerEvent) {
093:                super .fireHandlerChanged(handlerEvent);
094:
095:                if (handlerListeners != null) {
096:                    final boolean attributesChanged = handlerEvent
097:                            .isEnabledChanged()
098:                            || handlerEvent.isHandledChanged();
099:                    final Map previousAttributes;
100:                    if (attributesChanged) {
101:                        previousAttributes = new HashMap();
102:                        previousAttributes.putAll(getAttributeValuesByName());
103:                        if (handlerEvent.isEnabledChanged()) {
104:                            Boolean disabled = !isEnabled() ? Boolean.TRUE
105:                                    : Boolean.FALSE;
106:                            previousAttributes.put("enabled", disabled); //$NON-NLS-1$
107:                        }
108:                        if (handlerEvent.isHandledChanged()) {
109:                            Boolean notHandled = !isHandled() ? Boolean.TRUE
110:                                    : Boolean.FALSE;
111:                            previousAttributes.put(
112:                                    IHandlerAttributes.ATTRIBUTE_HANDLED,
113:                                    notHandled);
114:                        }
115:                    } else {
116:                        previousAttributes = null;
117:                    }
118:                    final org.eclipse.ui.commands.HandlerEvent legacyEvent = new org.eclipse.ui.commands.HandlerEvent(
119:                            this , attributesChanged, previousAttributes);
120:
121:                    for (int i = 0; i < handlerListeners.size(); i++) {
122:                        ((org.eclipse.ui.commands.IHandlerListener) handlerListeners
123:                                .get(i)).handlerChanged(legacyEvent);
124:                    }
125:                }
126:            }
127:
128:            protected void fireHandlerChanged(
129:                    final org.eclipse.ui.commands.HandlerEvent handlerEvent) {
130:                if (handlerEvent == null) {
131:                    throw new NullPointerException();
132:                }
133:
134:                if (handlerListeners != null) {
135:                    for (int i = 0; i < handlerListeners.size(); i++) {
136:                        ((org.eclipse.ui.commands.IHandlerListener) handlerListeners
137:                                .get(i)).handlerChanged(handlerEvent);
138:                    }
139:                }
140:
141:                if (super .hasListeners()) {
142:                    final boolean enabledChanged;
143:                    final boolean handledChanged;
144:                    if (handlerEvent.haveAttributeValuesByNameChanged()) {
145:                        Map previousAttributes = handlerEvent
146:                                .getPreviousAttributeValuesByName();
147:
148:                        Object attribute = previousAttributes.get("enabled"); //$NON-NLS-1$
149:                        if (attribute instanceof  Boolean) {
150:                            enabledChanged = ((Boolean) attribute)
151:                                    .booleanValue();
152:                        } else {
153:                            enabledChanged = false;
154:                        }
155:
156:                        attribute = previousAttributes
157:                                .get(IHandlerAttributes.ATTRIBUTE_HANDLED);
158:                        if (attribute instanceof  Boolean) {
159:                            handledChanged = ((Boolean) attribute)
160:                                    .booleanValue();
161:                        } else {
162:                            handledChanged = false;
163:                        }
164:                    } else {
165:                        enabledChanged = false;
166:                        handledChanged = true;
167:                    }
168:                    final HandlerEvent newEvent = new HandlerEvent(this ,
169:                            enabledChanged, handledChanged);
170:                    super .fireHandlerChanged(newEvent);
171:                }
172:            }
173:
174:            /**
175:             * This simply return an empty map. The default implementation has no
176:             * attributes.
177:             * 
178:             * @see IHandler#getAttributeValuesByName()
179:             */
180:            public Map getAttributeValuesByName() {
181:                return Collections.EMPTY_MAP;
182:            }
183:
184:            /**
185:             * Returns true iff there is one or more IHandlerListeners attached to this
186:             * AbstractHandler.
187:             * 
188:             * @return true iff there is one or more IHandlerListeners attached to this
189:             *         AbstractHandler
190:             * @since 3.1
191:             */
192:            protected final boolean hasListeners() {
193:                return super .hasListeners() || handlerListeners != null;
194:            }
195:
196:            public boolean isEnabled() {
197:                final Object handled = getAttributeValuesByName()
198:                        .get("enabled"); //$NON-NLS-1$
199:                if (handled instanceof  Boolean) {
200:                    return ((Boolean) handled).booleanValue();
201:                }
202:
203:                return false;
204:            }
205:
206:            public boolean isHandled() {
207:                final Object handled = getAttributeValuesByName().get(
208:                        IHandlerAttributes.ATTRIBUTE_HANDLED);
209:                if (handled instanceof  Boolean) {
210:                    return ((Boolean) handled).booleanValue();
211:                }
212:
213:                return false;
214:            }
215:
216:            /**
217:             * @see IHandler#removeHandlerListener(IHandlerListener)
218:             */
219:            public void removeHandlerListener(
220:                    org.eclipse.ui.commands.IHandlerListener handlerListener) {
221:                if (handlerListener == null) {
222:                    throw new NullPointerException();
223:                }
224:                if (handlerListeners == null) {
225:                    return;
226:                }
227:
228:                if (handlerListeners != null) {
229:                    handlerListeners.remove(handlerListener);
230:                }
231:                if (handlerListeners.isEmpty()) {
232:                    handlerListeners = null;
233:                }
234:            }
235:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.