01: /*******************************************************************************
02: * Copyright (c) 2005, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.browser;
11:
12: import java.util.Hashtable;
13:
14: import org.eclipse.ui.PartInitException;
15: import org.eclipse.ui.browser.AbstractWorkbenchBrowserSupport;
16: import org.eclipse.ui.browser.IWebBrowser;
17:
18: /**
19: * Extends the abstract browser support class by providing minimal support for
20: * external browsers. This class is used when no alternative implementation is
21: * plugged in via the 'org.eclipse.ui.browserSupport' extension point.
22: *
23: * @since 3.1
24: */
25: public class DefaultWorkbenchBrowserSupport extends
26: AbstractWorkbenchBrowserSupport {
27: private Hashtable browsers;
28: private static final String DEFAULT_BROWSER_ID_BASE = "org.eclipse.ui.defaultBrowser"; //$NON-NLS-1$
29:
30: /**
31: * The default constructor.
32: */
33: public DefaultWorkbenchBrowserSupport() {
34: browsers = new Hashtable();
35: }
36:
37: void registerBrowser(IWebBrowser browser) {
38: browsers.put(browser.getId(), browser);
39: }
40:
41: void unregisterBrowser(IWebBrowser browser) {
42: browsers.remove(browser.getId());
43: }
44:
45: IWebBrowser findBrowser(String id) {
46: return (IWebBrowser) browsers.get(id);
47: }
48:
49: protected IWebBrowser doCreateBrowser(int style, String browserId,
50: String name, String tooltip) throws PartInitException {
51: return new DefaultWebBrowser(this , browserId);
52: }
53:
54: /*
55: * (non-Javadoc)
56: *
57: * @see org.eclipse.ui.browser.IWorkbenchBrowserSupport#createBrowser(int,
58: * java.lang.String, java.lang.String, java.lang.String)
59: */
60: public IWebBrowser createBrowser(int style, String browserId,
61: String name, String tooltip) throws PartInitException {
62: IWebBrowser browser = findBrowser(browserId == null ? getDefaultId()
63: : browserId);
64: if (browser != null) {
65: return browser;
66: }
67: browser = doCreateBrowser(style, browserId, name, tooltip);
68: registerBrowser(browser);
69: return browser;
70: }
71:
72: /*
73: * (non-Javadoc)
74: *
75: * @see org.eclipse.ui.browser.IWorkbenchBrowserSupport#createBrowser(java.lang.String)
76: */
77: public IWebBrowser createBrowser(String browserId)
78: throws PartInitException {
79: return createBrowser(AS_EXTERNAL, browserId, null, null);
80: }
81:
82: private String getDefaultId() {
83: String id = null;
84: for (int i = 0; i < Integer.MAX_VALUE; i++) {
85: id = DEFAULT_BROWSER_ID_BASE + i;
86: if (browsers.get(id) == null)
87: break;
88: }
89: return id;
90: }
91: }
|