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.*;
18 import org.eclipse.swt.widgets.Display;
20 * The main interface to the internal Web browser. If allows
21 * you to query the file types supported by the Web browser
24 public class WebBrowser {
26 * WebBrowser constructor comment.
28 private WebBrowser() {
33 * Returns true if the internal Web browser is supported on this
34 * platform and the user has chosen to use it.
38 public static boolean isUsingInternalBrowser() {
39 return (getCurrentWebBrowser() instanceof IInternalWebBrowser);
43 * Display the given URL in a Web browser. If the user has chosen not
44 * to use the internal browser, an external browser will be used. If
45 * not, a browser in the current page will be reused if forceNewPage
46 * is not true and the user preference is not set. Finally, showToolbar
47 * will decide when the toolbar should be shown in the internal browser.
51 public static void openURL(final IWebBrowserEditorInput input) {
52 Trace.trace(Trace.FINEST, "openURL() " + input);
56 Display.getDefault().asyncExec(new Runnable() {
58 if (!isUsingInternalBrowser()){
59 IWebBrowser browser = getCurrentWebBrowser();
60 browser.openURL(input.getURL());
62 WebBrowserEditor.open(input);
68 * Return a list of all the installed Web browsers.
72 public static List getWebBrowsers() {
73 return BrowserManager.getInstance().getWebBrowsers();
77 * Return the current default web browser.
81 public static IWebBrowser getCurrentWebBrowser() {
82 return BrowserManager.getInstance().getCurrentWebBrowser();
86 * Set the current default web browser.
90 public static void getCurrentWebBrowser(IWebBrowser browser) {
91 BrowserManager.getInstance().setCurrentWebBrowser(browser);
95 * Create a new external Web browser.
99 public static IExternalWebBrowserWorkingCopy createExternalWebBrowser() {
100 return new ExternalWebBrowserWorkingCopy();
104 * Display the given URL in a Web browser.
106 * @param url java.net.URL
108 public static void openURL(URL url) {
109 IWebBrowser browser = getCurrentWebBrowser();
111 browser.openURL(url);
113 Display.getDefault().asyncExec(new Runnable() {
115 WebBrowserUtil.openError(WebBrowserUIPlugin.getResource("%errorNoBrowser"));