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


001:        /*******************************************************************************
002:         * Copyright (c) 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.statushandlers;
011:
012:        import java.util.ArrayList;
013:        import java.util.Iterator;
014:        import java.util.List;
015:
016:        import org.eclipse.core.runtime.IConfigurationElement;
017:        import org.eclipse.core.runtime.IExtension;
018:        import org.eclipse.core.runtime.IExtensionPoint;
019:        import org.eclipse.core.runtime.Platform;
020:        import org.eclipse.core.runtime.dynamichelpers.ExtensionTracker;
021:        import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler;
022:        import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
023:        import org.eclipse.ui.PlatformUI;
024:        import org.eclipse.ui.internal.WorkbenchPlugin;
025:
026:        /**
027:         * The registry of status handlers extensions.
028:         * 
029:         * @since 3.3
030:         * 
031:         */
032:        public class StatusHandlerRegistry implements  IExtensionChangeHandler {
033:
034:            private static final String STATUSHANDLERS_POINT_NAME = "statusHandlers"; //$NON-NLS-1$
035:
036:            private static final String TAG_STATUSHANDLER = "statusHandler"; //$NON-NLS-1$
037:
038:            private static final String TAG_STATUSHANDLER_PRODUCTBINDING = "statusHandlerProductBinding"; //$NON-NLS-1$
039:
040:            private ArrayList statusHandlerDescriptors = new ArrayList();
041:
042:            private ArrayList productBindingDescriptors = new ArrayList();
043:
044:            private StatusHandlerDescriptorsMap statusHandlerDescriptorsMap;
045:
046:            private StatusHandlerDescriptor defaultHandlerDescriptor;
047:
048:            private static StatusHandlerRegistry instance;
049:
050:            /**
051:             * Creates an instance of the class.
052:             */
053:            private StatusHandlerRegistry() {
054:                IExtensionTracker tracker = PlatformUI.getWorkbench()
055:                        .getExtensionTracker();
056:                IExtensionPoint handlersPoint = Platform.getExtensionRegistry()
057:                        .getExtensionPoint(WorkbenchPlugin.PI_WORKBENCH,
058:                                STATUSHANDLERS_POINT_NAME);
059:                IExtension[] extensions = handlersPoint.getExtensions();
060:
061:                statusHandlerDescriptorsMap = new StatusHandlerDescriptorsMap();
062:
063:                // initial population
064:                for (int i = 0; i < extensions.length; i++) {
065:                    addExtension(tracker, extensions[i]);
066:                }
067:
068:                tracker.registerHandler(this , ExtensionTracker
069:                        .createExtensionPointFilter(handlersPoint));
070:
071:                // registers on products ext. point to, needed
072:                // for changing the default handler if product is changed
073:                IExtensionPoint productsPoint = Platform.getExtensionRegistry()
074:                        .getExtensionPoint(Platform.PI_RUNTIME,
075:                                Platform.PT_PRODUCT);
076:
077:                tracker.registerHandler(this , ExtensionTracker
078:                        .createExtensionPointFilter(productsPoint));
079:            }
080:
081:            /**
082:             * Returns StatusHandlerRegistry singleton instance.
083:             * 
084:             * @return StatusHandlerRegistry instance
085:             */
086:            public static StatusHandlerRegistry getDefault() {
087:                if (instance == null) {
088:                    instance = new StatusHandlerRegistry();
089:                }
090:                return instance;
091:            }
092:
093:            /*
094:             * (non-Javadoc)
095:             * 
096:             * @see org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler#addExtension(org.eclipse.core.runtime.dynamichelpers.IExtensionTracker,
097:             *      org.eclipse.core.runtime.IExtension)
098:             */
099:            public void addExtension(IExtensionTracker tracker,
100:                    IExtension extension) {
101:                IConfigurationElement[] configElements = extension
102:                        .getConfigurationElements();
103:                for (int j = 0; j < configElements.length; j++) {
104:                    if (configElements[j].getName().equals(TAG_STATUSHANDLER)) {
105:                        StatusHandlerDescriptor descriptor = new StatusHandlerDescriptor(
106:                                configElements[j]);
107:                        tracker.registerObject(extension, descriptor,
108:                                IExtensionTracker.REF_STRONG);
109:                        statusHandlerDescriptors.add(descriptor);
110:                    } else if (configElements[j].getName().equals(
111:                            TAG_STATUSHANDLER_PRODUCTBINDING)) {
112:                        StatusHandlerProductBindingDescriptor descriptor = new StatusHandlerProductBindingDescriptor(
113:                                configElements[j]);
114:                        tracker.registerObject(extension, descriptor,
115:                                IExtensionTracker.REF_STRONG);
116:                        productBindingDescriptors.add(descriptor);
117:                    }
118:                }
119:                buildHandlersStructure();
120:            }
121:
122:            /*
123:             * (non-Javadoc)
124:             * 
125:             * @see org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler#removeExtension(org.eclipse.core.runtime.IExtension,
126:             *      java.lang.Object[])
127:             */
128:            public void removeExtension(IExtension extension, Object[] objects) {
129:                for (int i = 0; i < objects.length; i++) {
130:                    if (objects[i] instanceof  StatusHandlerDescriptor) {
131:                        statusHandlerDescriptors.remove(objects[i]);
132:                    } else if (objects[i] instanceof  StatusHandlerProductBindingDescriptor) {
133:                        productBindingDescriptors.remove(objects[i]);
134:                    }
135:                }
136:                buildHandlersStructure();
137:            }
138:
139:            /**
140:             * Returns the default product handler descriptor, or null if the product is
141:             * not defined or there is no product binding
142:             * 
143:             * @return the default handler
144:             */
145:            public StatusHandlerDescriptor getDefaultHandlerDescriptor() {
146:                return defaultHandlerDescriptor;
147:            }
148:
149:            /**
150:             * Returns a list of handler descriptors which should be used for statuses
151:             * with given plugin id.
152:             * 
153:             * @param pluginId
154:             * @return list of handler descriptors
155:             */
156:            public List getHandlerDescriptors(String pluginId) {
157:                return statusHandlerDescriptorsMap
158:                        .getHandlerDescriptors(pluginId);
159:            }
160:
161:            /**
162:             * Returns status handler descriptor for given id.
163:             * 
164:             * @param statusHandlerId
165:             *            the id to get for
166:             * @return the status handler descriptor
167:             */
168:            public StatusHandlerDescriptor getHandlerDescriptor(
169:                    String statusHandlerId) {
170:                StatusHandlerDescriptor descriptor = null;
171:                for (Iterator it = statusHandlerDescriptors.iterator(); it
172:                        .hasNext();) {
173:                    descriptor = (StatusHandlerDescriptor) it.next();
174:                    if (descriptor.getId().equals(statusHandlerId)) {
175:                        return descriptor;
176:                    }
177:                }
178:
179:                if (defaultHandlerDescriptor != null
180:                        && defaultHandlerDescriptor.getId().equals(
181:                                statusHandlerId)) {
182:                    return defaultHandlerDescriptor;
183:                }
184:
185:                return null;
186:            }
187:
188:            /**
189:             * Disposes the registry.
190:             */
191:            public void dispose() {
192:                PlatformUI.getWorkbench().getExtensionTracker()
193:                        .unregisterHandler(this );
194:            }
195:
196:            /**
197:             * Sets the default product handler descriptor if product exists and binding
198:             * is defined and creates handler descriptors tree due to the prefix policy.
199:             */
200:            private void buildHandlersStructure() {
201:                statusHandlerDescriptorsMap.clear();
202:                defaultHandlerDescriptor = null;
203:
204:                String productId = Platform.getProduct() != null ? Platform
205:                        .getProduct().getId() : null;
206:
207:                List allHandlers = new ArrayList();
208:
209:                String defaultHandlerId = null;
210:
211:                for (Iterator it = productBindingDescriptors.iterator(); it
212:                        .hasNext();) {
213:                    StatusHandlerProductBindingDescriptor descriptor = ((StatusHandlerProductBindingDescriptor) it
214:                            .next());
215:
216:                    if (descriptor.getProductId().equals(productId)) {
217:                        defaultHandlerId = descriptor.getHandlerId();
218:                    }
219:                }
220:
221:                for (Iterator it = statusHandlerDescriptors.iterator(); it
222:                        .hasNext();) {
223:                    StatusHandlerDescriptor descriptor = ((StatusHandlerDescriptor) it
224:                            .next());
225:
226:                    allHandlers.add(descriptor);
227:                }
228:
229:                StatusHandlerDescriptor handlerDescriptor = null;
230:
231:                for (Iterator it = allHandlers.iterator(); it.hasNext();) {
232:                    handlerDescriptor = (StatusHandlerDescriptor) it.next();
233:
234:                    if (handlerDescriptor.getId().equals(defaultHandlerId)) {
235:                        defaultHandlerDescriptor = handlerDescriptor;
236:                    } else {
237:                        statusHandlerDescriptorsMap
238:                                .addHandlerDescriptor(handlerDescriptor);
239:                    }
240:                }
241:            }
242:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.