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


001:        /*******************************************************************************
002:         * Copyright (c) 2005, 2007 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.internal.handlers;
011:
012:        import java.io.BufferedWriter;
013:        import java.io.IOException;
014:        import java.io.StringWriter;
015:
016:        import org.eclipse.core.commands.IHandler;
017:        import org.eclipse.core.expressions.Expression;
018:        import org.eclipse.core.expressions.IEvaluationContext;
019:        import org.eclipse.ui.ISources;
020:        import org.eclipse.ui.handlers.IHandlerActivation;
021:        import org.eclipse.ui.handlers.IHandlerService;
022:        import org.eclipse.ui.internal.services.EvaluationResultCache;
023:
024:        /**
025:         * <p>
026:         * A token representing the activation of a handler. This token can later be
027:         * used to cancel that activation. Without this token, then handler will only
028:         * become inactive if the component in which the handler was activated is
029:         * destroyed.
030:         * </p>
031:         * <p>
032:         * This caches the command id and the handler, so that they can later be
033:         * identified.
034:         * </p>
035:         * <p>
036:         * <b>Note:</b> this class has a natural ordering that is inconsistent with 
037:         * equals.
038:         * </p>
039:         * 
040:         * @since 3.1
041:         */
042:        final class HandlerActivation extends EvaluationResultCache implements 
043:                IHandlerActivation {
044:
045:            /**
046:             * The identifier for the command which the activated handler handles. This
047:             * value is never <code>null</code>.
048:             */
049:            private final String commandId;
050:
051:            /**
052:             * The depth of services at which this token was created. This is used as a
053:             * final tie-breaker if all other things are equivalent.
054:             */
055:            private final int depth;
056:
057:            /**
058:             * The handler that has been activated. This value may be <code>null</code>.
059:             */
060:            private final IHandler handler;
061:
062:            /**
063:             * The handler service from which this handler activation was request. This
064:             * value is never <code>null</code>.
065:             */
066:            private final IHandlerService handlerService;
067:
068:            /**
069:             * Constructs a new instance of <code>HandlerActivation</code>.
070:             * 
071:             * @param commandId
072:             *            The identifier for the command which the activated handler
073:             *            handles. This value must not be <code>null</code>.
074:             * @param handler `
075:             *            The handler that has been activated. This value may be
076:             *            <code>null</code>.
077:             * @param expression
078:             *            The expression that must evaluate to <code>true</code>
079:             *            before this handler is active. This value may be
080:             *            <code>null</code> if it is always active.</code>.
081:             * @param depth
082:             *            The depth at which this activation was created within the
083:             *            services hierarchy. This is used as the final tie-breaker if
084:             *            all other conditions are equal. This should be a positive
085:             *            integer.
086:             * @param handlerService
087:             *            The handler service from which the handler activation was
088:             *            requested; must not be <code>null</code>.
089:             * @see ISources
090:             */
091:            HandlerActivation(final String commandId, final IHandler handler,
092:                    final Expression expression, final int depth,
093:                    final IHandlerService handlerService) {
094:                super (expression);
095:
096:                if (commandId == null) {
097:                    throw new NullPointerException(
098:                            "The command identifier for a handler activation cannot be null"); //$NON-NLS-1$
099:                }
100:
101:                if (handlerService == null) {
102:                    throw new NullPointerException(
103:                            "The handler service for an activation cannot be null"); //$NON-NLS-1$
104:                }
105:
106:                this .commandId = commandId;
107:                this .depth = depth;
108:                this .handler = handler;
109:                this .handlerService = handlerService;
110:            }
111:
112:            public final void clearActive() {
113:                clearResult();
114:            }
115:
116:            /**
117:             * Implement {@link Comparable#compareTo(Object)}.
118:             * <p>
119:             * <b>Note:</b> this class has a natural ordering that is inconsistent with
120:             * equals.
121:             * </p>
122:             */
123:            public final int compareTo(final Object object) {
124:                final IHandlerActivation activation = (IHandlerActivation) object;
125:                int difference;
126:
127:                // Check the priorities
128:                int this Priority = this .getSourcePriority();
129:                int thatPriority = activation.getSourcePriority();
130:
131:                // rogue bit problem - ISources.ACTIVE_MENU
132:                int this Lsb = 0;
133:                int thatLsb = 0;
134:
135:                if (((this Priority & ISources.ACTIVE_MENU) | (thatPriority & ISources.ACTIVE_MENU)) != 0) {
136:                    this Lsb = this Priority & 1;
137:                    this Priority = (this Priority >> 1) & 0x7fffffff;
138:                    thatLsb = thatPriority & 1;
139:                    thatPriority = (thatPriority >> 1) & 0x7fffffff;
140:                }
141:
142:                difference = this Priority - thatPriority;
143:                if (difference != 0) {
144:                    return difference;
145:                }
146:
147:                // if all of the higher bits are the same, check the
148:                // difference of the LSB
149:                difference = this Lsb - thatLsb;
150:                if (difference != 0) {
151:                    return difference;
152:                }
153:
154:                // Check depth
155:                final int this Depth = this .getDepth();
156:                final int thatDepth = activation.getDepth();
157:                difference = this Depth - thatDepth;
158:                return difference;
159:            }
160:
161:            public final String getCommandId() {
162:                return commandId;
163:            }
164:
165:            public final int getDepth() {
166:                return depth;
167:            }
168:
169:            public final IHandler getHandler() {
170:                return handler;
171:            }
172:
173:            public final IHandlerService getHandlerService() {
174:                return handlerService;
175:            }
176:
177:            public final boolean isActive(final IEvaluationContext context) {
178:                return evaluate(context);
179:            }
180:
181:            public final String toString() {
182:                final StringWriter sw = new StringWriter();
183:                final BufferedWriter buffer = new BufferedWriter(sw);
184:
185:                try {
186:                    buffer.write("HandlerActivation(commandId="); //$NON-NLS-1$
187:                    buffer.write(commandId);
188:                    buffer.write(',');
189:                    buffer.newLine();
190:                    buffer.write("\thandler="); //$NON-NLS-1$
191:                    buffer.write(handler == null ? "" : handler.toString()); //$NON-NLS-1$
192:                    buffer.write(',');
193:                    buffer.newLine();
194:                    buffer.write("\texpression="); //$NON-NLS-1$
195:                    Expression exp = getExpression();
196:                    buffer.write(exp == null ? "" : exp.toString()); //$NON-NLS-1$
197:                    buffer.write(",sourcePriority="); //$NON-NLS-1$
198:                    buffer.write(Integer.toString(getSourcePriority()));
199:                    buffer.write(')');
200:                    buffer.flush();
201:                } catch (IOException e) {
202:                    // we're a string buffer, there should be no IO exception
203:                }
204:                return sw.toString();
205:            }
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.