Source Code Cross Referenced for WorkbenchBrowserSupport.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » internal » browser » 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.browser 
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.browser;
011:
012:        import org.eclipse.core.runtime.CoreException;
013:        import org.eclipse.core.runtime.IConfigurationElement;
014:        import org.eclipse.core.runtime.IExtension;
015:        import org.eclipse.core.runtime.IExtensionPoint;
016:        import org.eclipse.core.runtime.Platform;
017:        import org.eclipse.core.runtime.dynamichelpers.ExtensionTracker;
018:        import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler;
019:        import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
020:        import org.eclipse.swt.custom.BusyIndicator;
021:        import org.eclipse.swt.widgets.Display;
022:        import org.eclipse.ui.PartInitException;
023:        import org.eclipse.ui.PlatformUI;
024:        import org.eclipse.ui.browser.AbstractWorkbenchBrowserSupport;
025:        import org.eclipse.ui.browser.IWebBrowser;
026:        import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
027:        import org.eclipse.ui.internal.WorkbenchPlugin;
028:        import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
029:
030:        /**
031:         * Implements the support interface and delegates the calls to the active
032:         * support if contributed via the extension point, or the default support
033:         * otherwise.
034:         * 
035:         * @since 3.1
036:         */
037:        public class WorkbenchBrowserSupport extends
038:                AbstractWorkbenchBrowserSupport {
039:
040:            private static WorkbenchBrowserSupport instance;
041:
042:            private IWorkbenchBrowserSupport activeSupport;
043:
044:            private boolean initialized;
045:
046:            private String desiredBrowserSupportId;
047:
048:            private IExtensionChangeHandler handler = new IExtensionChangeHandler() {
049:
050:                /* (non-Javadoc)
051:                 * @see org.eclipse.core.runtime.dynamicHelpers.IExtensionChangeHandler#addExtension(org.eclipse.core.runtime.dynamicHelpers.IExtensionTracker, org.eclipse.core.runtime.IExtension)
052:                 */
053:                public void addExtension(IExtensionTracker tracker,
054:                        IExtension extension) {
055:                    //Do nothing
056:                }
057:
058:                /* (non-Javadoc)
059:                 * @see org.eclipse.core.runtime.dynamicHelpers.IExtensionChangeHandler#removeExtension(org.eclipse.core.runtime.IExtension, java.lang.Object[])
060:                 */
061:                public void removeExtension(IExtension source, Object[] objects) {
062:                    for (int i = 0; i < objects.length; i++) {
063:                        if (objects[i] == activeSupport) {
064:                            dispose();
065:                            // remove ourselves - we'll be added again in initalize if
066:                            // needed
067:                            PlatformUI.getWorkbench().getExtensionTracker()
068:                                    .unregisterHandler(handler);
069:                        }
070:                    }
071:                }
072:            };
073:
074:            /**
075:             * Cannot be instantiated from outside.
076:             */
077:            private WorkbenchBrowserSupport() {
078:            }
079:
080:            /**
081:             * Returns the shared instance.
082:             * 
083:             * @return shared instance
084:             */
085:            public static IWorkbenchBrowserSupport getInstance() {
086:                if (instance == null) {
087:                    instance = new WorkbenchBrowserSupport();
088:                }
089:                return instance;
090:            }
091:
092:            /* (non-Javadoc)
093:             * @see org.eclipse.ui.browser.IWorkbenchBrowserSupport#createBrowser(int, java.lang.String, java.lang.String, java.lang.String)
094:             */
095:            public IWebBrowser createBrowser(int style, String browserId,
096:                    String name, String tooltip) throws PartInitException {
097:                return getActiveSupport().createBrowser(style, browserId, name,
098:                        tooltip);
099:            }
100:
101:            /* (non-Javadoc)
102:             * @see org.eclipse.ui.browser.IWorkbenchBrowserSupport#createBrowser(java.lang.String)
103:             */
104:            public IWebBrowser createBrowser(String browserId)
105:                    throws PartInitException {
106:                return getActiveSupport().createBrowser(browserId);
107:            }
108:
109:            /* (non-Javadoc)
110:             * @see org.eclipse.ui.browser.IWorkbenchBrowserSupport#isInternalWebBrowserAvailable()
111:             */
112:            public boolean isInternalWebBrowserAvailable() {
113:                return getActiveSupport().isInternalWebBrowserAvailable();
114:            }
115:
116:            private IWorkbenchBrowserSupport getActiveSupport() {
117:                if (initialized == false) {
118:                    loadActiveSupport();
119:                }
120:                // ensure we always have an active instance
121:                if (activeSupport == null) {
122:                    activeSupport = new DefaultWorkbenchBrowserSupport();
123:                }
124:                return activeSupport;
125:            }
126:
127:            /**
128:             * Answers whether the system has a non-default browser installed.
129:             * 
130:             * @return whether the system has a non-default browser installed
131:             */
132:            public boolean hasNonDefaultBrowser() {
133:                return !(getActiveSupport() instanceof  DefaultWorkbenchBrowserSupport);
134:            }
135:
136:            private void loadActiveSupport() {
137:                BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {
138:                    /*
139:                     * (non-Javadoc)
140:                     * 
141:                     * @see java.lang.Runnable#run()
142:                     */
143:                    public void run() {
144:                        IConfigurationElement[] elements = Platform
145:                                .getExtensionRegistry()
146:                                .getConfigurationElementsFor(
147:                                        PlatformUI.PLUGIN_ID,
148:                                        IWorkbenchRegistryConstants.PL_BROWSER_SUPPORT);
149:                        IConfigurationElement elementToUse = null;
150:
151:                        if (desiredBrowserSupportId != null) {
152:                            elementToUse = findDesiredElement(elements);
153:                        } else {
154:                            elementToUse = getElementToUse(elements);
155:                        }
156:                        if (elementToUse != null) {
157:                            initialized = initializePluggableBrowserSupport(elementToUse);
158:                        }
159:                    }
160:
161:                    /**
162:                     * Search for the element whose extension has ID equal to that of
163:                     * the field desiredBrowserSupport.
164:                     * 
165:                     * @param elements
166:                     *            the elements to search
167:                     * @return the element or <code>null</code>
168:                     */
169:                    private IConfigurationElement findDesiredElement(
170:                            IConfigurationElement[] elements) {
171:                        for (int i = 0; i < elements.length; i++) {
172:                            if (desiredBrowserSupportId.equals(elements[i]
173:                                    .getDeclaringExtension()
174:                                    .getUniqueIdentifier())) {
175:                                return elements[i];
176:                            }
177:                        }
178:                        return null;
179:                    }
180:
181:                    private IExtensionPoint getExtensionPoint() {
182:                        return Platform
183:                                .getExtensionRegistry()
184:                                .getExtensionPoint(
185:                                        PlatformUI.PLUGIN_ID,
186:                                        IWorkbenchRegistryConstants.PL_BROWSER_SUPPORT);
187:                    }
188:
189:                    private IConfigurationElement getElementToUse(
190:                            IConfigurationElement[] elements) {
191:                        if (elements.length == 0) {
192:                            return null;
193:                        }
194:                        IConfigurationElement defaultElement = null;
195:                        IConfigurationElement choice = null;
196:                        // find the first default element and
197:                        // the first non-default element. If non-default
198:                        // is found, pick it. Otherwise, use default.
199:                        for (int i = 0; i < elements.length; i++) {
200:                            IConfigurationElement element = elements[i];
201:                            if (element.getName().equals(
202:                                    IWorkbenchRegistryConstants.TAG_SUPPORT)) {
203:                                String def = element
204:                                        .getAttribute(IWorkbenchRegistryConstants.ATT_DEFAULT);
205:                                if (def != null
206:                                        && Boolean.valueOf(def).booleanValue()) {
207:                                    if (defaultElement == null) {
208:                                        defaultElement = element;
209:                                    }
210:                                } else {
211:                                    // non-default
212:                                    if (choice == null) {
213:                                        choice = element;
214:                                    }
215:                                }
216:                            }
217:                        }
218:                        if (choice == null) {
219:                            choice = defaultElement;
220:                        }
221:                        return choice;
222:                    }
223:
224:                    private boolean initializePluggableBrowserSupport(
225:                            IConfigurationElement element) {
226:                        // Instantiate the browser support
227:                        try {
228:                            activeSupport = (AbstractWorkbenchBrowserSupport) WorkbenchPlugin
229:                                    .createExtension(
230:                                            element,
231:                                            IWorkbenchRegistryConstants.ATT_CLASS);
232:                            // start listening for removals
233:                            IExtensionTracker extensionTracker = PlatformUI
234:                                    .getWorkbench().getExtensionTracker();
235:                            extensionTracker
236:                                    .registerHandler(
237:                                            handler,
238:                                            ExtensionTracker
239:                                                    .createExtensionPointFilter(getExtensionPoint()));
240:                            // register the new browser support for removal
241:                            // notification
242:                            extensionTracker.registerObject(element
243:                                    .getDeclaringExtension(), activeSupport,
244:                                    IExtensionTracker.REF_WEAK);
245:                            return true;
246:                        } catch (CoreException e) {
247:                            WorkbenchPlugin
248:                                    .log(
249:                                            "Unable to instantiate browser support" + e.getStatus(), e);//$NON-NLS-1$
250:                        }
251:                        return false;
252:                    }
253:
254:                });
255:            }
256:
257:            /**
258:             * For debug purposes only.
259:             * 
260:             * @param desiredBrowserSupportId the desired browser system id
261:             */
262:            public void setDesiredBrowserSupportId(
263:                    String desiredBrowserSupportId) {
264:                dispose(); // prep for a new help system
265:                this .desiredBrowserSupportId = desiredBrowserSupportId;
266:            }
267:
268:            /**
269:             * Dispose of the active support.
270:             */
271:            protected void dispose() {
272:                activeSupport = null;
273:                initialized = false;
274:            }
275:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.