2 * Copyright (c) 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM - Initial API and implementation
11 package net.sourceforge.phpeclipse.webbrowser;
14 import java.util.List;
16 import net.sourceforge.phpeclipse.webbrowser.internal.BrowserManager;
17 import net.sourceforge.phpeclipse.webbrowser.internal.ExternalWebBrowserWorkingCopy;
18 import net.sourceforge.phpeclipse.webbrowser.internal.Trace;
19 import net.sourceforge.phpeclipse.webbrowser.internal.WebBrowserEditor;
20 import net.sourceforge.phpeclipse.webbrowser.internal.WebBrowserUIPlugin;
21 import net.sourceforge.phpeclipse.webbrowser.internal.WebBrowserUtil;
23 import org.eclipse.swt.widgets.Display;
25 * The main interface to the internal Web browser. If allows
26 * you to query the file types supported by the Web browser
29 public class WebBrowser {
31 * WebBrowser constructor comment.
33 private WebBrowser() {
38 * Returns true if the internal Web browser is supported on this
39 * platform and the user has chosen to use it.
43 public static boolean isUsingInternalBrowser() {
44 return (getCurrentWebBrowser() instanceof IInternalWebBrowser);
48 * Display the given URL in a Web browser. If the user has chosen not
49 * to use the internal browser, an external browser will be used. If
50 * not, a browser in the current page will be reused if forceNewPage
51 * is not true and the user preference is not set. Finally, showToolbar
52 * will decide when the toolbar should be shown in the internal browser.
56 public static void openURL(final IWebBrowserEditorInput input) {
57 Trace.trace(Trace.FINEST, "openURL() " + input);
61 Display.getDefault().asyncExec(new Runnable() {
63 if (!isUsingInternalBrowser()){
64 IWebBrowser browser = getCurrentWebBrowser();
65 browser.openURL(input.getURL());
67 WebBrowserEditor.open(input);
73 * Return a list of all the installed Web browsers.
77 public static List getWebBrowsers() {
78 return BrowserManager.getInstance().getWebBrowsers();
82 * Return the current default web browser.
86 public static IWebBrowser getCurrentWebBrowser() {
87 return BrowserManager.getInstance().getCurrentWebBrowser();
91 * Set the current default web browser.
95 public static void getCurrentWebBrowser(IWebBrowser browser) {
96 BrowserManager.getInstance().setCurrentWebBrowser(browser);
100 * Create a new external Web browser.
104 public static IExternalWebBrowserWorkingCopy createExternalWebBrowser() {
105 return new ExternalWebBrowserWorkingCopy();
109 * Display the given URL in a Web browser.
111 * @param url java.net.URL
113 public static void openURL(URL url) {
114 IWebBrowser browser = getCurrentWebBrowser();
116 browser.openURL(url);
118 Display.getDefault().asyncExec(new Runnable() {
120 WebBrowserUtil.openError(WebBrowserUIPlugin.getResource("%errorNoBrowser"));