--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>net.sourceforge.phpeclipse.webbrowser</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+bin.includes = plugin.xml,\
+ *.jar,\
+ plugin.properties/,\
+ webbrowser.jar,\
+ icons/,\
+ home/,\
+ plugin.properties,\
+ defaultBrowsers.xml,\
+ .options
+jars.compile.order =
+src.includes = plugin.properties/,\
+ schema/,\
+ build.properties
+source.webbrowser.jar = webbrowser/
+output.webbrowser.jar = bin/
--- /dev/null
+<browsers>
+ <browser name="%browserInternetExplorer" params="" executable="iexplore.exe">
+ <location>C:\Program Files\Internet Explorer\IEXPLORE.EXE</location>
+ <location>D:\Program Files\Internet Explorer\IEXPLORE.EXE</location>
+ <location>E:\Program Files\Internet Explorer\IEXPLORE.EXE</location>
+ </browser>
+ <browser name="%browserNetscape4" params="" executable="netscape.exe">
+ <location>C:\Program Files\Netscape\Communicator\Program\netscape.exe</location>
+ <location>D:\Program Files\Netscape\Communicator\Program\netscape.exe</location>
+ <location>E:\Program Files\Netscape\Communicator\Program\netscape.exe</location>
+ </browser>
+ <browser name="%browserNetscape7" params="" executable="netsc.exe">
+ <location>C:\Program Files\Netscape\Netscape\netscp.exe</location>
+ <location>D:\Program Files\Netscape\Netscape\netscp.exe</location>
+ <location>E:\Program Files\Netscape\Netscape\netscp.exe</location>
+ </browser>
+ <browser name="%browserMozilla" params="" executable="mozilla.exe">
+ <location>C:\Program Files\mozilla.org\Mozilla\mozilla.exe</location>
+ <location>D:\Program Files\mozilla.org\Mozilla\mozilla.exe</location>
+ <location>E:\Program Files\mozilla.org\Mozilla\mozilla.exe</location>
+ </browser>
+ <browser name="%browserOpera" params="" executable="opera.exe">
+ <location>C:\Program Files\Opera7\opera.exe</location>
+ <location>D:\Program Files\Opera7\opera.exe</location>
+ <location>E:\Program Files\Opera7\opera.exe</location>
+ </browser>
+
+ <browser name="%browserMozilla" params="" executable="mozilla">
+ <location>/usr/bin/mozilla</location>
+ <location>/usr/X11/bin/mozilla</location>
+ </browser>
+ <browser name="%browserNetscape" params="" executable="netscape">
+ <location>/usr/bin/netscape</location>
+ <location>/usr/X11R6/bin/netscape</location>
+ </browser>
+ <browser name="%browserKonqueror" params="" executable="konqueror">
+ <location>/opt/kde3/bin/konqueror</location>
+ </browser>
+ <browser name="%browserGaleon" params="" executable="galeon">
+ <location>/opt/usr/gnome/bin/galeon</location>
+ </browser>
+</browsers>
--- /dev/null
+<html>
+<body bgcolor=white leftmargin=0 topmargin=15>
+
+</body>
+</html>
\ No newline at end of file
--- /dev/null
+pluginName=Web Browser
+providerName=IBM
+extensionPointURLMap=URL Map
+%extensionPointFavorites=Favorite URLs
+
+# --- Internal Web Browser ---
+internalWebBrowserName=Internal Web Browser
+viewWebBrowserTitle=Web Browser
+
+# Actions
+actionWebBrowserGo=Go to the selected URL
+actionWebBrowserBack=Back to the previous page
+actionWebBrowserForward=Forward to the next page
+actionWebBrowserStop=Stop loading the current page
+actionWebBrowserRefresh=Refresh the current page
+actionWebBrowserPrint=Print the current page
+actionWebBrowserFavorites=Favorites
+actionWebBrowserNoFavorites=No Favorites
+actionWebBrowserOrganizeFavorites=Organize Favorites...
+
+# Status text
+webBrowserStatusUninitialized=Not ready
+webBrowserStatusLoading=Loading...
+webBrowserStatusLoaded=Ready
+webBrowserStatusInteractive=Loading...
+webBrowserStatusComplete=Done
+
+# message if a resource is deleted
+dialogResourceDeletedTitle=Web Resource Deleted
+dialogResourceDeletedMessage=The file {0} initially opened in the Web Browser has been deleted from the file system. Do you want to ignore the deletion or close the Web Browser?
+dialogResourceDeletedIgnore=Ignore
+
+dialogOrganizeFavoritesTitle=Organize Favorites
+dialogOrganizeFavoritesMessage=Organize favorite URLs below. Select the name or URL to edit.
+dialogOrganizeFavoritesName=Name
+dialogOrganizeFavoritesURL=URL
+
+# --------------- Action Sets (toolbar icon groups) ---------------
+
+# Web Browser action set
+actionSetWebBrowserTitle=Web Browser
+actionSetOpenWebBrowser=Open Web Browser
+actionSetSwitchBrowser=Web Browser
+
+# --------------- Preferences ---------------
+
+# Name of the preference pages
+preferenceInternetTitle=Internet
+preferenceInternetDescription=General internet settings are available in the contained preference pages.
+preferenceWebBrowserTitle=Web Browser
+preferenceWebBrowserTitleLong=Installed Web Browsers
+preferenceWebBrowserDescription=Add, remove, or edit installed Web browsers.\nThe selected Web browser will be used whenever Web pages are opened.
+
+# Web Browser preferences
+prefUseInternalBrowser=Use the &internal Web Browser
+prefBrowserNewPage=&Open a new page for each request
+prefUseExternalBrowser=Use e&xternal Web Browser
+
+errorDialogTitle=Error
+errorCouldNotLaunchWebBrowser=Could not launch external Web Browser for {0}. Check the Web Browser preferences.
+errorNoBrowser=Could not open a Web browser because there are none configured. Check the Web Browser preferences.
+
+browserList=Installed &Web Browsers:
+add=&Add...
+edit=&Edit...
+remove=&Remove
+search=&Search...
+createBrowser=Add Installed Web Browser
+editInternalBrowser=Internal Web Browser
+editExternalBrowser=Edit Installed Web Browser
+clearURLHistory=Clear URL history when exiting workbench
+clearURLHistoryNow=Clear URL History Now
+name=&Name:
+location=&Location:
+parameters=&Parameters:
+parametersMessage=(Use {0} to include the URL)
+browse=&Browse...
+browseMessage=Specify the location of the Web Browser executable
+errorCouldNotLaunchInternalWebBrowser=Could not launch internal Web Browser. Please set an external browser in the Browser preferences.
+searchingTaskName=Searching for Web browsers...
+searching=Found {0} - Searching {1}
+searchingNoneFound=No Web browsers were found.
+selectDirectory=Select a directory to search for Web browsers:
+directoryDialogTitle=Directory Selection
+locationInvalid=The location value is not a valid path name.
+
+browserInternetExplorer=Internet Explorer
+browserNetscape4=Netscape Communicator v4.x
+browserNetscape7=Netscape v7.x
+browserNetscape=Netscape
+browserMozilla=Mozilla
+browserOpera=Opera
+browserKonqueror=Konqueror
+browserGaleon=Galeon
+browserExternal=External Browser
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.0"?>
+
+<plugin id="net.sourceforge.phpeclipse.webbrowser"
+ name="%pluginName"
+ version="3.0.0"
+ provider-name="%providerName"
+ class="org.eclipse.webbrowser.internal.WebBrowserUIPlugin">
+
+ <requires>
+ <import plugin="org.eclipse.core.resources" version="3.0.0" match="equivalent"/>
+ <import plugin="org.eclipse.core.runtime" version="3.0.0" match="equivalent"/>
+ <import plugin="org.eclipse.ui" version="3.0.0" match="equivalent"/>
+ <import plugin="org.eclipse.ui.ide" version="3.0.0" match="equivalent"/>
+ <import plugin="org.eclipse.ui.editors" version="3.0.0" match="equivalent"/>
+ </requires>
+
+ <runtime>
+ <library name="webbrowser.jar">
+ <export name="*"/>
+ <packages prefixes="org.eclipse.webbrowser"/>
+ </library>
+ </runtime>
+
+ <extension-point id="urlMap" name="%extensionPointURLMap" schema="schema/urlMap.exsd"/>
+ <extension-point id="favorites" name="%extensionPointFavorites" schema="schema/favorites.exsd"/>
+
+ <extension point="org.eclipse.ui.actionSets">
+ <actionSet
+ id="org.eclipse.webbrowser.actionSet"
+ label="%actionSetWebBrowserTitle"
+ visible="false">
+ <action
+ id="org.eclipse.webbrowser.action.open"
+ toolbarPath="browser"
+ label="%actionSetOpenWebBrowser"
+ tooltip="%actionSetOpenWebBrowser"
+ icon="icons/obj16/internal_browser.gif"
+ class="org.eclipse.webbrowser.OpenBrowserWorkbenchAction"/>
+ <action
+ id="org.eclipse.webbrowser.action.switch"
+ menubarPath="window/browser"
+ label="%actionSetSwitchBrowser"
+ tooltip="%actionSetSwitchBrowser"
+ style="pulldown"
+ class="org.eclipse.webbrowser.internal.SwitchBrowserWorkbenchAction"/>
+ </actionSet>
+ </extension>
+
+ <extension point="org.eclipse.ui.preferencePages">
+ <page
+ id="org.eclipse.internet"
+ name="%preferenceInternetTitle"
+ class="org.eclipse.webbrowser.internal.InternetPreferencePage"/>
+ <page
+ id="org.eclipse.webbrowser.preferencePage"
+ name="%preferenceWebBrowserTitle"
+ category="org.eclipse.internet"
+ class="org.eclipse.webbrowser.internal.WebBrowserPreferencePage"/>
+ </extension>
+
+ <extension point="net.sourceforge.phpeclipse.webbrowser.urlMap">
+ <urlMap
+ id="org.eclipse.webbrowser.standard.urlMap"
+ class="org.eclipse.webbrowser.internal.StandardURLMap"/>
+ </extension>
+
+ <extension point="net.sourceforge.phpeclipse.webbrowser.favorites">
+ <favorite
+ id="org.eclipse.webbrowser.favorite.eclipse"
+ name="PHPEclipse"
+ url="http://www.phpeclipse.de"
+ locked="false"/>
+ <favorite
+ id="org.eclipse.webbrowser.favorite.eclipse"
+ name="Eclipse"
+ url="http://www.eclipse.org"
+ locked="false"/>
+ </extension>
+
+ <extension point="org.eclipse.ui.editors">
+ <editor id="org.eclipse.webbrowser"
+ name="%viewWebBrowserTitle"
+ icon="icons/obj16/internal_browser.gif"
+ class="org.eclipse.webbrowser.internal.WebBrowserEditor"
+ extensions="gif,jpg,jpeg,xhtml"
+ contributorClass="org.eclipse.webbrowser.internal.WebBrowserEditorActionBarContributor"/>
+ </extension>
+
+ <extension point="org.eclipse.ui.elementFactories">
+ <factory id="org.eclipse.webbrowser.elementFactory"
+ class="org.eclipse.webbrowser.WebBrowserEditorInput"/>
+ </extension>
+
+</plugin>
\ No newline at end of file
--- /dev/null
+<?xml version='1.0' encoding='UTF-8'?>\r
+<!-- Schema file written by PDE -->\r
+<schema targetNamespace="org.eclipse.webbrowser">\r
+<annotation>\r
+ <appInfo>\r
+ <meta.schema plugin="org.eclipse.webbrowser" id="favorites" name="Favorite URLs"/>\r
+ </appInfo>\r
+ <documentation>\r
+ This extension point provides a way to define default Favorites (URLs).\r
+ </documentation>\r
+ </annotation>\r
+\r
+ <element name="extension">\r
+ <complexType>\r
+ <sequence>\r
+ <element ref="favorite" minOccurs="0" maxOccurs="unbounded"/>\r
+ </sequence>\r
+ <attribute name="point" type="string" use="required">\r
+ <annotation>\r
+ <documentation>\r
+ a fully qualified identifier of the target extension point\r
+ </documentation>\r
+ </annotation>\r
+ </attribute>\r
+ <attribute name="id" type="string">\r
+ <annotation>\r
+ <documentation>\r
+ an optional identifier of the extension instance\r
+ </documentation>\r
+ </annotation>\r
+ </attribute>\r
+ <attribute name="name" type="string">\r
+ <annotation>\r
+ <documentation>\r
+ an optional name of the extension instance\r
+ </documentation>\r
+ </annotation>\r
+ </attribute>\r
+ </complexType>\r
+ </element>\r
+\r
+ <element name="favorite">\r
+ <annotation>\r
+ <appInfo>\r
+ <meta.element labelAttribute="name"/>\r
+ </appInfo>\r
+ </annotation>\r
+ <complexType>\r
+ <sequence>\r
+ </sequence>\r
+ <attribute name="id" type="string" use="required">\r
+ <annotation>\r
+ <documentation>\r
+ specifies a unique identifier for this extension point\r
+ </documentation>\r
+ </annotation>\r
+ </attribute>\r
+ <attribute name="url" type="string" use="required">\r
+ <annotation>\r
+ <documentation>\r
+ specifies the URL of the favorite\r
+ </documentation>\r
+ </annotation>\r
+ </attribute>\r
+ <attribute name="name" type="string" use="required">\r
+ <annotation>\r
+ <documentation>\r
+ specifies the translatable name of the favorite\r
+ </documentation>\r
+ </annotation>\r
+ </attribute>\r
+ <attribute name="locked" type="boolean">\r
+ <annotation>\r
+ <documentation>\r
+ set to "true" if the favorite cannot be changed by the user, and "false" if the favorite is initially available, but the user can remove it\r
+ </documentation>\r
+ </annotation>\r
+ </attribute>\r
+ </complexType>\r
+ </element>\r
+\r
+ <annotation>\r
+ <appInfo>\r
+ <meta.section type="examples"/>\r
+ </appInfo>\r
+ <documentation>\r
+ The following is an example of the favorites extension point:
+
+<p>
+<pre>
+ <extension point="org.eclipse.webbrowser.favorites">
+ <startup
+ id="com.example.ExampleIdentifier"
+ name="eclipse"
+ url="http://www.eclipse.org"/>
+ </extension>
+</pre>
+</p>\r
+ </documentation>\r
+ </annotation>\r
+\r
+ <annotation>\r
+ <appInfo>\r
+ <meta.section type="apiInfo"/>\r
+ </appInfo>\r
+ <documentation>\r
+ \r
+ </documentation>\r
+ </annotation>\r
+\r
+ <annotation>\r
+ <appInfo>\r
+ <meta.section type="copyright"/>\r
+ </appInfo>\r
+ <documentation>\r
+ Copyright (c) 2000, 2003 IBM Corporation and others.<br>
+All rights reserved. This program and the accompanying materials are made
+available under the terms of the Common Public License v1.0 which accompanies
+this distribution, and is available at
+<a href="http://www.eclipse.org/legal/cpl-v10.html">http://www.eclipse.org/legal/cpl-v10.html</a>\r
+ </documentation>\r
+ </annotation>\r
+\r
+</schema>\r
--- /dev/null
+<?xml version='1.0' encoding='UTF-8'?>\r
+<!-- Schema file written by PDE -->\r
+<schema targetNamespace="org.eclipse.webbrowser">\r
+<annotation>\r
+ <appInfo>\r
+ <meta.schema plugin="org.eclipse.webbrowser" id="urlMap" name="URL Mapping"/>\r
+ </appInfo>\r
+ <documentation>\r
+ This extension point provides a way to map URLs (Strings) entered in the internal Web browser to another URL. For instance, it can be user to map the word "eclipse" to "http://www.eclipse.org".\r
+ </documentation>\r
+ </annotation>\r
+\r
+ <element name="extension">\r
+ <complexType>\r
+ <sequence>\r
+ <element ref="urlMap" minOccurs="0" maxOccurs="unbounded"/>\r
+ </sequence>\r
+ <attribute name="point" type="string" use="required">\r
+ <annotation>\r
+ <documentation>\r
+ a fully qualified identifier of the target extension point\r
+ </documentation>\r
+ </annotation>\r
+ </attribute>\r
+ <attribute name="id" type="string">\r
+ <annotation>\r
+ <documentation>\r
+ an optional identifier of the extension instance\r
+ </documentation>\r
+ </annotation>\r
+ </attribute>\r
+ <attribute name="name" type="string">\r
+ <annotation>\r
+ <documentation>\r
+ an optional name of the extension instance\r
+ </documentation>\r
+ </annotation>\r
+ </attribute>\r
+ </complexType>\r
+ </element>\r
+\r
+ <element name="urlMap">\r
+ <annotation>\r
+ <appInfo>\r
+ <meta.element labelAttribute="name"/>\r
+ </appInfo>\r
+ </annotation>\r
+ <complexType>\r
+ <sequence>\r
+ </sequence>\r
+ <attribute name="id" type="string" use="required">\r
+ <annotation>\r
+ <documentation>\r
+ specifies a unique identifier for this extension point\r
+ </documentation>\r
+ </annotation>\r
+ </attribute>\r
+ <attribute name="class" type="string" use="required">\r
+ <annotation>\r
+ <documentation>\r
+ specifies the fully qualified name of the Java class that implements <samp>IURLMap</samp>.\r
+ </documentation>\r
+ <appInfo>\r
+ <meta.attribute kind="java" basedOn="org.eclipse.webbrowser.IURLMap"/>\r
+ </appInfo>\r
+ </annotation>\r
+ </attribute>\r
+ </complexType>\r
+ </element>\r
+\r
+ <annotation>\r
+ <appInfo>\r
+ <meta.section type="examples"/>\r
+ </appInfo>\r
+ <documentation>\r
+ The following is an example of a URL map extension point:
+
+<p>
+<pre>
+ <extension point="org.eclipse.webbrowser.urlMap">
+ <startup
+ id="com.example.ExampleIdentifier"
+ class="com.example.ExampleURLMap"/>
+ </extension>
+</pre>
+</p>\r
+ </documentation>\r
+ </annotation>\r
+\r
+ <annotation>\r
+ <appInfo>\r
+ <meta.section type="apiInfo"/>\r
+ </appInfo>\r
+ <documentation>\r
+ Value of the attribute <b>class</b> must be a fully qualified name of a Java class that implements the interface <b>org.eclipse.webbrowser.IURLMap</b>.\r
+ </documentation>\r
+ </annotation>\r
+\r
+ <annotation>\r
+ <appInfo>\r
+ <meta.section type="copyright"/>\r
+ </appInfo>\r
+ <documentation>\r
+ Copyright (c) 2000, 2003 IBM Corporation and others.<br>
+All rights reserved. This program and the accompanying materials are made
+available under the terms of the Common Public License v1.0 which accompanies
+this distribution, and is available at
+<a href="http://www.eclipse.org/legal/cpl-v10.html">http://www.eclipse.org/legal/cpl-v10.html</a>\r
+ </documentation>\r
+ </annotation>\r
+\r
+</schema>\r
--- /dev/null
+/**
+ * Copyright (c) 2004 IBM Corporation and others.
+ * All rights reserved. Â This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ */
+package org.eclipse.webbrowser;
+
+import org.eclipse.swt.browser.Browser;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.webbrowser.internal.WebBrowser;
+/**
+ * Web browser widget. Extends the eclipse Browser widget by adding an
+ * optional toolbar and statusbar.
+ */
+public class ExtendedBrowser extends WebBrowser {
+ public ExtendedBrowser(Composite parent, final boolean showToolbar, final boolean showStatusbar) {
+ super(parent, showToolbar, showStatusbar);
+ }
+
+ /**
+ * Return the underlying browser control.
+ *
+ * @return org.eclipse.swt.browser.Browser
+ */
+ public Browser getBrowser() {
+ return browser;
+ }
+
+ public void home() {
+ super.home();
+ }
+
+ public void setURL(String url) {
+ super.setURL(url);
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.eclipse.webbrowser;
+/**
+ *
+ */
+public interface IExternalWebBrowser extends IWebBrowser {
+ public String getLocation();
+
+ public String getParameters();
+
+ public void delete();
+
+ public boolean isWorkingCopy();
+
+ public IExternalWebBrowserWorkingCopy getWorkingCopy();
+}
\ No newline at end of file
--- /dev/null
+package org.eclipse.webbrowser;
+/**
+ *
+ */
+public interface IExternalWebBrowserWorkingCopy extends IExternalWebBrowser {
+ public void setName(String name);
+
+ public void setLocation(String location);
+
+ public void setParameters(String params);
+
+ public IExternalWebBrowser save();
+}
\ No newline at end of file
--- /dev/null
+package org.eclipse.webbrowser;
+/**
+ *
+ */
+public interface IInternalWebBrowser extends IWebBrowser {
+ public boolean getUseNewPage();
+
+ public boolean getClearHistoryOnExit();
+
+ public boolean isWorkingCopy();
+
+ public IInternalWebBrowserWorkingCopy getWorkingCopy();
+}
\ No newline at end of file
--- /dev/null
+package org.eclipse.webbrowser;
+/**
+ *
+ */
+public interface IInternalWebBrowserWorkingCopy extends IInternalWebBrowser {
+ public void setUseNewPage(boolean b);
+
+ public void setClearHistoryOnExit(boolean b);
+
+ public IInternalWebBrowser save();
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ */
+package org.eclipse.webbrowser;
+/**
+ * Interface for mapping special URLs to other locations.
+ */
+public interface IURLMap {
+ /**
+ * Returns a mapped URL
+ *
+ * @param url java.lang.String
+ * @return java.lang.String
+ */
+ public String getMappedURL(String url);
+}
\ No newline at end of file
--- /dev/null
+package org.eclipse.webbrowser;
+
+import java.net.URL;
+/**
+ *
+ */
+public interface IWebBrowser {
+ public String getName();
+
+ public void openURL(URL url);
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ */
+package org.eclipse.webbrowser;
+
+import java.net.URL;
+import org.eclipse.ui.IEditorInput;
+/**
+ * The editor input for the Web browser editor. If the
+ * integrated Web browser exists for this platform, (and
+ * the user has chosen to use it) this information will
+ * be used to populate the Web browser. If not, this
+ * information will be used to launch an external Web
+ * browser.
+ */
+public interface IWebBrowserEditorInput extends IEditorInput {
+ /**
+ * Returns true if this page can reuse the browser that the
+ * given input is being displayed in, or false if it should
+ * open up in a new page.
+ *
+ * @param input org.eclipse.webbrowser.IWebBrowserEditorInput
+ * @return boolean
+ */
+ public boolean canReplaceInput(IWebBrowserEditorInput input);
+
+ /**
+ * Returns the url that should be displayed in the browser.
+ *
+ * @return java.net.URL
+ */
+ public URL getURL();
+
+ /**
+ * Returns true if the Web statusbar should be shown.
+ *
+ * @return boolean
+ */
+ public boolean isStatusbarVisible();
+
+ /**
+ * Returns true if the Web toolbar should be shown.
+ *
+ * @return boolean
+ */
+ public boolean isToolbarVisible();
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ */
+package org.eclipse.webbrowser;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.webbrowser.WebBrowser;
+import org.eclipse.webbrowser.WebBrowserEditorInput;
+/**
+ * Action to open the Web browser.
+ */
+public class OpenBrowserAction extends Action {
+ /**
+ * OpenBrowserAction constructor comment.
+ */
+ public OpenBrowserAction() {
+ super();
+ }
+
+ /**
+ * Implementation of method defined on <code>IAction</code>.
+ */
+ public void run() {
+ WebBrowser.openURL(new WebBrowserEditorInput(null, WebBrowserEditorInput.SHOW_ALL | WebBrowserEditorInput.FORCE_NEW_PAGE));
+ }
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ */
+package org.eclipse.webbrowser;
+
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.ui.*;
+import org.eclipse.webbrowser.WebBrowser;
+import org.eclipse.webbrowser.WebBrowserEditorInput;
+/**
+ * Action to open the Web broswer.
+ */
+public class OpenBrowserWorkbenchAction implements IWorkbenchWindowActionDelegate {
+ /**
+ * OpenBrowserWorkbenchAction constructor comment.
+ */
+ public OpenBrowserWorkbenchAction() {
+ super();
+ }
+
+ /**
+ * Disposes this action delegate. The implementor should unhook any references
+ * to itself so that garbage collection can occur.
+ */
+ public void dispose() { }
+
+ /**
+ * Initializes this action delegate with the workbench window it will work in.
+ *
+ * @param window the window that provides the context for this delegate
+ */
+ public void init(IWorkbenchWindow window) { }
+
+ /**
+ * Performs this action.
+ * <p>
+ * This method is called when the delegating action has been triggered.
+ * Implement this method to do the actual work.
+ * </p>
+ *
+ * @param action the action proxy that handles the presentation portion of the
+ * action
+ */
+ public void run(IAction action) {
+ WebBrowser.openURL(new WebBrowserEditorInput(null, WebBrowserEditorInput.SHOW_ALL | WebBrowserEditorInput.FORCE_NEW_PAGE));
+ }
+
+ /**
+ * Notifies this action delegate that the selection in the workbench has changed.
+ * <p>
+ * Implementers can use this opportunity to change the availability of the
+ * action or to modify other presentation properties.
+ * </p>
+ *
+ * @param action the action proxy that handles presentation portion of the action
+ * @param selection the current selection in the workbench
+ */
+ public void selectionChanged(IAction action, ISelection selection) { }
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ */
+package org.eclipse.webbrowser;
+
+import java.net.URL;
+import java.util.List;
+
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.webbrowser.internal.*;
+/**
+ * The main interface to the internal Web browser. If allows
+ * you to query the file types supported by the Web browser
+ * and open a URL.
+ */
+public class WebBrowser {
+ /**
+ * WebBrowser constructor comment.
+ */
+ private WebBrowser() {
+ super();
+ }
+
+ /**
+ * Returns true if the internal Web browser is supported on this
+ * platform and the user has chosen to use it.
+ *
+ * @return boolean
+ */
+ public static boolean isUsingInternalBrowser() {
+ return (getCurrentWebBrowser() instanceof IInternalWebBrowser);
+ }
+
+ /**
+ * Display the given URL in a Web browser. If the user has chosen not
+ * to use the internal browser, an external browser will be used. If
+ * not, a browser in the current page will be reused if forceNewPage
+ * is not true and the user preference is not set. Finally, showToolbar
+ * will decide when the toolbar should be shown in the internal browser.
+ *
+ * @param input
+ */
+ public static void openURL(final IWebBrowserEditorInput input) {
+ Trace.trace(Trace.FINEST, "openURL() " + input);
+ if (input == null)
+ return;
+
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ if (!isUsingInternalBrowser()){
+ IWebBrowser browser = getCurrentWebBrowser();
+ browser.openURL(input.getURL());
+ } else
+ WebBrowserEditor.open(input);
+ }
+ });
+ }
+
+ /**
+ * Return a list of all the installed Web browsers.
+ *
+ * @return
+ */
+ public static List getWebBrowsers() {
+ return BrowserManager.getInstance().getWebBrowsers();
+ }
+
+ /**
+ * Return the current default web browser.
+ *
+ * @return
+ */
+ public static IWebBrowser getCurrentWebBrowser() {
+ return BrowserManager.getInstance().getCurrentWebBrowser();
+ }
+
+ /**
+ * Set the current default web browser.
+ *
+ * @return
+ */
+ public static void getCurrentWebBrowser(IWebBrowser browser) {
+ BrowserManager.getInstance().setCurrentWebBrowser(browser);
+ }
+
+ /**
+ * Create a new external Web browser.
+ *
+ * @return
+ */
+ public static IExternalWebBrowserWorkingCopy createExternalWebBrowser() {
+ return new ExternalWebBrowserWorkingCopy();
+ }
+
+ /**
+ * Display the given URL in a Web browser.
+ *
+ * @param url java.net.URL
+ */
+ public static void openURL(URL url) {
+ IWebBrowser browser = getCurrentWebBrowser();
+ if (browser != null)
+ browser.openURL(url);
+ else {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ WebBrowserUtil.openError(WebBrowserUIPlugin.getResource("%errorNoBrowser"));
+ }
+ });
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ */
+package org.eclipse.webbrowser;
+
+import java.net.URL;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.*;
+import org.eclipse.webbrowser.internal.ImageResource;
+import org.eclipse.webbrowser.internal.Trace;
+import org.eclipse.webbrowser.internal.WebBrowserPreference;
+import org.eclipse.webbrowser.internal.WebBrowserUIPlugin;
+import org.eclipse.core.runtime.IAdaptable;
+/**
+ * The editor input for the integrated web browser.
+ */
+public class WebBrowserEditorInput implements IWebBrowserEditorInput, IPersistableElement, IElementFactory {
+ // --- constants to pass into constructor ---
+
+ // if used, the toolbar will be available
+ public static final int SHOW_TOOLBAR = 1 << 1;
+
+ // if used, the status bar will be available
+ public static final int SHOW_STATUSBAR = 1 << 2;
+
+ // if used, this input will always force a new page
+ // and will never reuse an open Web browser
+ public static final int FORCE_NEW_PAGE = 1 << 3;
+
+ // if used, the original URL will be saved and
+ // the page can reopen to the same URL after
+ // shutting down
+ public static final int SAVE_URL = 1 << 5;
+
+ // if used, the browser will be transient and will not appear
+ // in the most recently used file list, nor will it reopen after
+ // restarting Eclipse
+ public static final int TRANSIENT = 1 << 6;
+
+ public static final int SHOW_ALL = SHOW_TOOLBAR | SHOW_STATUSBAR;
+
+ private static final String ELEMENT_FACTORY_ID = "org.eclipse.webbrowser.elementFactory";
+ private static final String MEMENTO_URL = "url";
+ private static final String MEMENTO_STYLE = "style";
+ private static final String MEMENTO_ID = "id";
+
+ private URL url;
+ private int style;
+ private String id = null;
+
+ /**
+ * WebBrowser editor input for the homepage.
+ */
+ public WebBrowserEditorInput() {
+ this(null);
+ }
+
+ /**
+ * WebBrowserEditorInput constructor comment.
+ */
+ public WebBrowserEditorInput(URL url) {
+ this(url, SHOW_ALL | SAVE_URL);
+ }
+
+ /**
+ * WebBrowserEditorInput constructor comment.
+ */
+ public WebBrowserEditorInput(URL url, int style) {
+ super();
+ this.url = url;
+ this.style = style;
+ }
+
+ /**
+ * WebBrowserEditorInput constructor comment.
+ */
+ public WebBrowserEditorInput(URL url, int style, String browserId) {
+ super();
+ this.url = url;
+ this.style = style;
+ this.id = browserId;
+ }
+
+ /**
+ * WebBrowserEditorInput constructor comment.
+ */
+ public WebBrowserEditorInput(URL url, boolean b) {
+ this(url);
+ }
+
+ /**
+ * Returns true if this page can reuse the browser that the
+ * given input is being displayed in, or false if it should
+ * open up in a new page.
+ *
+ * @param input org.eclipse.webbrowser.IWebBrowserEditorInput
+ * @return boolean
+ */
+ public boolean canReplaceInput(IWebBrowserEditorInput input) {
+ Trace.trace(Trace.FINEST, "canReplaceInput " + this + " " + input);
+ if ((style & FORCE_NEW_PAGE) != 0)
+ return false;
+ else if (input.isToolbarVisible() != isToolbarVisible())
+ return false;
+ else if (input.isStatusbarVisible() != isStatusbarVisible())
+ return false;
+ else if (id != null) {
+ if (!(input instanceof WebBrowserEditorInput))
+ return false;
+ String bid = ((WebBrowserEditorInput) input).getBrowserId();
+ return id.equals(bid);
+ } else
+ return false;
+ }
+
+ /**
+ * Creates an <code>IElement</code> from the state captured within
+ * an <code>IMemento</code>.
+ *
+ * @param memento a memento containing the state for an element
+ * @return an element, or <code>null</code> if the element could not be created
+ */
+ public IAdaptable createElement(IMemento memento) {
+ URL url2 = null;
+ try {
+ url2 = new URL(WebBrowserPreference.getHomePageURL());
+ } catch (Exception e) {
+ // could not determine the URL
+ }
+
+ int newStyle = SHOW_TOOLBAR | SHOW_STATUSBAR;
+ try {
+ newStyle = memento.getInteger(MEMENTO_STYLE).intValue();
+
+ if ((newStyle & SAVE_URL) != 0)
+ url = new URL(memento.getString(MEMENTO_URL));
+ } catch (Exception e) {
+ // could not determine the style
+ }
+
+ String id2 = null;
+ try {
+ id2 = memento.getString(MEMENTO_ID);
+ if (id2 != null && id2.length() < 1)
+ id2 = null;
+ } catch (Exception e) { }
+
+ return new WebBrowserEditorInput(url2, newStyle, id2);
+ }
+
+ /**
+ * Indicates whether some other object is "equal to" this one.
+ * In this case it means that the underlying IFolders are equal.
+ */
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!(obj instanceof WebBrowserEditorInput))
+ return false;
+ WebBrowserEditorInput other = (WebBrowserEditorInput) obj;
+
+ if (url != null && !url.equals(obj))
+ return false;
+
+ return canReplaceInput(other);
+ }
+
+ /**
+ * Returns whether the editor input exists.
+ * <p>
+ * This method is primarily used to determine if an editor input should
+ * appear in the "File Most Recently Used" menu. An editor input will appear
+ * in the list until the return value of <code>exists</code> becomes
+ * <code>false</code> or it drops off the bottom of the list.
+ *
+ * @return <code>true</code> if the editor input exists; <code>false</code>
+ * otherwise
+ */
+ public boolean exists() {
+ if ((style & TRANSIENT) != 0)
+ return false;
+ else
+ return true;
+ }
+
+ /**
+ * Returns an object which is an instance of the given class
+ * associated with this object. Returns <code>null</code> if
+ * no such object can be found.
+ *
+ * @param adapter the adapter class to look up
+ * @return a object castable to the given class,
+ * or <code>null</code> if this object does not
+ * have an adapter for the given class
+ */
+ public Object getAdapter(Class adapter) {
+ return null;
+ }
+
+ /**
+ * Returns the ID of an element factory which can be used to recreate
+ * this object. An element factory extension with this ID must exist
+ * within the workbench registry.
+ *
+ * @return the element factory ID
+ */
+ public String getFactoryId() {
+ return ELEMENT_FACTORY_ID;
+ }
+
+ public ImageDescriptor getImageDescriptor() {
+ return ImageResource.getImageDescriptor(ImageResource.IMG_INTERNAL_BROWSER);
+ }
+
+ /**
+ * Returns the name of this editor input for display purposes.
+ * <p>
+ * For instance, if the fully qualified input name is
+ * <code>"a\b\MyFile.gif"</code>, the return value would be just
+ * <code>"MyFile.gif"</code>.
+ *
+ * @return the file name string
+ */
+ public String getName() {
+ return WebBrowserUIPlugin.getResource("%viewWebBrowserTitle");
+ }
+
+ /*
+ * Returns an object that can be used to save the state of this editor input.
+ *
+ * @return the persistable element, or <code>null</code> if this editor input
+ * cannot be persisted
+ */
+ public IPersistableElement getPersistable() {
+ if ((style & TRANSIENT) != 0)
+ return null;
+ else
+ return this;
+ }
+
+ public String getToolTipText() {
+ if (url != null)
+ return url.toExternalForm();
+ else
+ return WebBrowserUIPlugin.getResource("%viewWebBrowserTitle");
+ }
+
+ /**
+ * Returns the url.
+ *
+ * @return java.net.URL
+ */
+ public URL getURL() {
+ return url;
+ }
+
+ /**
+ * Returns the browser id. Browsers with a set id will always & only be
+ * replaced by browsers with the same id.
+ *
+ * @return String
+ */
+ public String getBrowserId() {
+ return id;
+ }
+
+ /**
+ * Returns true if the status bar should be shown.
+ *
+ * @return boolean
+ */
+ public boolean isStatusbarVisible() {
+ return (style & SHOW_STATUSBAR) != 0;
+ }
+
+ /**
+ * Returns true if the toolbar should be shown.
+ *
+ * @return boolean
+ */
+ public boolean isToolbarVisible() {
+ return (style & SHOW_TOOLBAR) != 0;
+ }
+
+ /**
+ * Saves the state of an element within a memento.
+ *
+ * @param memento the storage area for element state
+ */
+ public void saveState(IMemento memento) {
+ if ((style & SAVE_URL) != 0 && url != null)
+ memento.putString(MEMENTO_URL, url.toExternalForm());
+
+ memento.putInteger(MEMENTO_STYLE, style);
+
+ if (id != null)
+ memento.putString(MEMENTO_ID, id);
+ }
+
+ /**
+ * Converts this object to a string.
+ *
+ * @return java.lang.String
+ */
+ public String toString() {
+ return "WebBrowserEditorInput[" + url + " " + style + " " + id + "]";
+ }
+}
\ No newline at end of file
--- /dev/null
+/**********************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.webbrowser.internal;
+
+import java.util.*;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.webbrowser.IWebBrowser;
+
+/**
+ * Monitor content provider.
+ */
+public class BrowserContentProvider implements IStructuredContentProvider {
+ /**
+ * BrowserContentProvider constructor comment.
+ */
+ public BrowserContentProvider() {
+ super();
+ }
+
+ /**
+ * Disposes of this content provider.
+ * This is called by the viewer when it is disposed.
+ */
+ public void dispose() { }
+
+ /**
+ * Returns the elements to display in the viewer
+ * when its input is set to the given element.
+ * These elements can be presented as rows in a table, items in a list, etc.
+ * The result is not modified by the viewer.
+ *
+ * @param inputElement the input element
+ * @return the array of elements to display in the viewer
+ */
+ public Object[] getElements(Object inputElement) {
+ List list = new ArrayList();
+ Iterator iterator = BrowserManager.getInstance().getWebBrowsers().iterator();
+ while (iterator.hasNext()) {
+ IWebBrowser browser = (IWebBrowser) iterator.next();
+ list.add(browser);
+ }
+ return list.toArray();
+ }
+
+ /**
+ * Notifies this content provider that the given viewer's input
+ * has been switched to a different element.
+ * <p>
+ * A typical use for this method is registering the content provider as a listener
+ * to changes on the new input (using model-specific means), and deregistering the viewer
+ * from the old input. In response to these change notifications, the content provider
+ * propagates the changes to the viewer.
+ * </p>
+ *
+ * @param viewer the viewer
+ * @param oldInput the old input element, or <code>null</code> if the viewer
+ * did not previously have an input
+ * @param newInput the new input element, or <code>null</code> if the viewer
+ * does not have an input
+ */
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
+}
\ No newline at end of file
--- /dev/null
+/**********************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.webbrowser.internal;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Preferences;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.XMLMemento;
+import org.eclipse.webbrowser.IExternalWebBrowser;
+import org.eclipse.webbrowser.IExternalWebBrowserWorkingCopy;
+import org.eclipse.webbrowser.IInternalWebBrowser;
+import org.eclipse.webbrowser.IWebBrowser;
+/**
+ *
+ */
+public class BrowserManager {
+ private static final int ADD = 0;
+ private static final int CHANGE = 1;
+ private static final int REMOVE = 2;
+
+ protected List browsers;
+ protected IWebBrowser currentBrowser;
+ protected List browserListeners = new ArrayList();
+
+ private Preferences.IPropertyChangeListener pcl;
+ protected boolean ignorePreferenceChanges = false;
+
+ protected static BrowserManager instance;
+
+ public static BrowserManager getInstance() {
+ if (instance == null)
+ instance = new BrowserManager();
+ return instance;
+ }
+
+ private BrowserManager() {
+ pcl = new Preferences.IPropertyChangeListener() {
+ public void propertyChange(Preferences.PropertyChangeEvent event) {
+ if (ignorePreferenceChanges)
+ return;
+ String property = event.getProperty();
+ if (property.equals("browsers")) {
+ loadBrowsers();
+ }
+ }
+ };
+
+ WebBrowserUIPlugin.getInstance().getPluginPreferences().addPropertyChangeListener(pcl);
+ }
+
+ protected void dispose() {
+ WebBrowserUIPlugin.getInstance().getPluginPreferences().removePropertyChangeListener(pcl);
+
+ // clear the cache
+ Iterator iterator = browsers.iterator();
+ while (iterator.hasNext()) {
+ Object obj = iterator.next();
+ if (obj instanceof IInternalWebBrowser) {
+ IInternalWebBrowser wb = (IInternalWebBrowser) obj;
+ if (wb.getClearHistoryOnExit())
+ WebBrowserPreference.setInternalWebBrowserHistory(null);
+ }
+ }
+ }
+
+ public IExternalWebBrowserWorkingCopy createExternalWebBrowser() {
+ return new ExternalWebBrowserWorkingCopy();
+ }
+
+ public List getWebBrowsers() {
+ if (browsers == null)
+ loadBrowsers();
+ return new ArrayList(browsers);
+ }
+
+ protected void loadBrowsers() {
+ Trace.trace(Trace.FINEST, "Loading web browsers");
+
+ Preferences prefs = WebBrowserUIPlugin.getInstance().getPluginPreferences();
+ String xmlString = prefs.getString("browsers");
+ if (xmlString != null && xmlString.length() > 0) {
+ browsers = new ArrayList();
+
+ try {
+ ByteArrayInputStream in = new ByteArrayInputStream(xmlString.getBytes());
+ Reader reader = new InputStreamReader(in);
+ IMemento memento = XMLMemento.createReadRoot(reader);
+
+ IMemento child = memento.getChild("internal");
+ if (child != null) {
+ InternalWebBrowser browser = new InternalWebBrowser();
+ browser.load(child);
+ browsers.add(browser);
+ }
+
+ IMemento[] children = memento.getChildren("external");
+ int size = children.length;
+ for (int i = 0; i < size; i++) {
+ ExternalWebBrowser browser = new ExternalWebBrowser();
+ browser.load(children[i]);
+ browsers.add(browser);
+ }
+
+ Integer current = memento.getInteger("current");
+ if (current != null) {
+ currentBrowser = (IWebBrowser) browsers.get(current.intValue());
+ }
+ } catch (Exception e) {
+ Trace.trace(Trace.WARNING, "Could not load browsers: " + e.getMessage());
+ }
+ addInternalBrowser(browsers);
+ if (currentBrowser == null && browsers.size() > 0)
+ currentBrowser = (IWebBrowser) browsers.get(0);
+ } else {
+ setupDefaultBrowsers();
+ saveBrowsers();
+ return;
+ }
+ }
+
+ protected void saveBrowsers() {
+ try {
+ ignorePreferenceChanges = true;
+ XMLMemento memento = XMLMemento.createWriteRoot("web-browsers");
+
+ Iterator iterator = browsers.iterator();
+ while (iterator.hasNext()) {
+ Object obj = iterator.next();
+ if (obj instanceof InternalWebBrowser) {
+ InternalWebBrowser browser = (InternalWebBrowser) obj;
+ IMemento child = memento.createChild("internal");
+ browser.save(child);
+ } else if (obj instanceof ExternalWebBrowser) {
+ ExternalWebBrowser browser = (ExternalWebBrowser) obj;
+ IMemento child = memento.createChild("external");
+ browser.save(child);
+ }
+ }
+
+ memento.putInteger("current", browsers.indexOf(currentBrowser));
+
+ StringWriter writer = new StringWriter();
+ memento.save(writer);
+ String xmlString = writer.getBuffer().toString();
+ Preferences prefs = WebBrowserUIPlugin.getInstance().getPluginPreferences();
+ prefs.setValue("browsers", xmlString);
+ WebBrowserUIPlugin.getInstance().savePluginPreferences();
+ } catch (Exception e) {
+ Trace.trace(Trace.SEVERE, "Could not save browsers", e);
+ }
+ ignorePreferenceChanges = false;
+ }
+
+ protected void addInternalBrowser(List browserList) {
+ if (browserList == null)
+ return;
+
+ Iterator iterator = browserList.iterator();
+ while (iterator.hasNext()) {
+ IWebBrowser browser = (IWebBrowser) iterator.next();
+ if (browser instanceof IInternalWebBrowser)
+ return;
+ }
+
+ // add the internal browser if we can
+ WebBrowserUIPlugin.getInstance().getLog().log(new Status(IStatus.INFO,
+ WebBrowserUIPlugin.PLUGIN_ID, 0, WebBrowserUtil.canUseInternalWebBrowser() + "/" + WebBrowserUtil.isInternalBrowserOperational(), null));
+ if (!WebBrowserUtil.canUseInternalWebBrowser() || !WebBrowserUtil.isInternalBrowserOperational())
+ return;
+
+ browserList.add(0, new InternalWebBrowser());
+ }
+
+ private void setupDefaultBrowsers() {
+ browsers = new ArrayList();
+
+ addInternalBrowser(browsers);
+
+ // handle all the EXTERNAL browsers by criteria and add those too at startup
+ WebBrowserUtil.addFoundBrowsers(browsers);
+
+ // by default, if internal is there, that is current, else set the first external one
+ if (!browsers.isEmpty())
+ currentBrowser = (IWebBrowser) browsers.get(0);
+ }
+
+ protected void addBrowser(IExternalWebBrowser browser) {
+ if (browsers == null)
+ loadBrowsers();
+ if (!browsers.contains(browser))
+ browsers.add(browser);
+ fireWebBrowserEvent(browser, ADD);
+ saveBrowsers();
+ }
+
+ protected void removeWebBrowser(IExternalWebBrowser browser) {
+ if (browsers == null)
+ loadBrowsers();
+ browsers.remove(browser);
+ fireWebBrowserEvent(browser, REMOVE);
+ }
+
+ // Internal Web browser CAN be "edited", just not created or removed
+ protected void browserChanged(IWebBrowser browser) {
+ fireWebBrowserEvent(browser, CHANGE);
+ saveBrowsers();
+ }
+
+ /**
+ * Add Web browser listener.
+ * @param listener
+ */
+ public void addWebBrowserListener(IWebBrowserListener listener) {
+ browserListeners.add(listener);
+ }
+
+ /**
+ * Remove Web browser listener.
+ * @param listener
+ */
+ public void removeWebBrowserListener(IWebBrowserListener listener) {
+ browserListeners.remove(listener);
+ }
+
+ /**
+ * Fire a Web browser event.
+ * @param browser
+ * @param type
+ */
+ protected void fireWebBrowserEvent(IWebBrowser browser, int type) {
+ Object[] obj = browserListeners.toArray();
+
+ int size = obj.length;
+ for (int i = 0; i < size; i++) {
+ IWebBrowserListener listener = (IWebBrowserListener) obj[i];
+ if (type == ADD)
+ listener.browserAdded(browser);
+ else if (type == CHANGE)
+ listener.browserChanged(browser);
+ else if (type == REMOVE)
+ listener.browserRemoved(browser);
+ }
+ }
+
+ public IWebBrowser getCurrentWebBrowser() {
+ if (browsers == null)
+ loadBrowsers();
+
+ return currentBrowser;
+ }
+
+ public void setCurrentWebBrowser(IWebBrowser wb) {
+ if (browsers.contains(wb))
+ currentBrowser = wb;
+ saveBrowsers();
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.eclipse.webbrowser.internal;
+/**********************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.webbrowser.IExternalWebBrowserWorkingCopy;
+import org.eclipse.core.runtime.IProgressMonitor;
+/**
+ *
+ */
+public class BrowserSearcher {
+ private static boolean cancelled;
+ private BrowserSearcher() {
+ super();
+ }
+
+ /**
+ * Search for installed VMs in the file system
+ */
+ protected static List search(Shell shell) {
+ final List foundBrowsers = new ArrayList();
+ final List existingPaths = WebBrowserUtil.getExternalBrowserPaths();
+
+ // select a target directory for the search
+ DirectoryDialog dialog = new DirectoryDialog(shell);
+ dialog.setMessage(WebBrowserUIPlugin.getResource("%selectDirectory"));
+ dialog.setText(WebBrowserUIPlugin.getResource("%directoryDialogTitle"));
+
+ String path = dialog.open();
+ if (path == null)
+ return null;
+
+ cancelled = false;
+
+ final File rootDir = new File(path);
+ ProgressMonitorDialog pm = new ProgressMonitorDialog(shell);
+
+ IRunnableWithProgress r = new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor) {
+ monitor.beginTask(
+ WebBrowserUIPlugin.getResource("%searchingTaskName"),
+ IProgressMonitor.UNKNOWN);
+ search(rootDir, existingPaths, foundBrowsers, monitor);
+ monitor.done();
+ if (monitor.isCanceled())
+ setCancelled(true);
+ }
+ };
+
+ try {
+ pm.run(true, true, r);
+ } catch (InvocationTargetException e) {
+ Trace.trace(Trace.SEVERE, "Invocation Exception occured running monitor: " + e);
+ } catch (InterruptedException e) {
+ Trace.trace(Trace.SEVERE, "Interrupted exception occured running monitor: " + e);
+ return null;
+ }
+
+ if (cancelled)
+ return null;
+
+ return foundBrowsers;
+ }
+
+ protected static void setCancelled(boolean b) {
+ cancelled = b;
+ }
+
+ protected static void search(File directory, List existingPaths, List foundBrowsers, IProgressMonitor monitor) {
+ if (monitor.isCanceled())
+ return;
+
+ String[] names = directory.list();
+ List subDirs = new ArrayList();
+
+ for (int i = 0; i < names.length; i++) {
+ if (monitor.isCanceled())
+ return;
+
+ File file = new File(directory, names[i]);
+
+ if (existingPaths.contains(file.getAbsolutePath().toLowerCase()))
+ continue;
+
+ IExternalWebBrowserWorkingCopy wc = WebBrowserUtil.createExternalBrowser(file);
+ if (wc != null)
+ foundBrowsers.add(wc);
+
+ try {
+ monitor.subTask(
+ MessageFormat.format(WebBrowserUIPlugin.getResource("%searching"),
+ new String[] { Integer.toString(foundBrowsers.size()), file.getCanonicalPath()}));
+ } catch (IOException ioe) {
+ }
+
+ if (file.isDirectory()) {
+ if (monitor.isCanceled())
+ return;
+ subDirs.add(file);
+ }
+ }
+ while (!subDirs.isEmpty()) {
+ File subDir = (File) subDirs.remove(0);
+ search(subDir, existingPaths, foundBrowsers, monitor);
+ if (monitor.isCanceled()) {
+ return;
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/**********************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.webbrowser.internal;
+
+import java.util.Iterator;
+
+import org.eclipse.jface.viewers.*;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.ui.help.WorkbenchHelp;
+import org.eclipse.webbrowser.IExternalWebBrowser;
+import org.eclipse.webbrowser.IExternalWebBrowserWorkingCopy;
+import org.eclipse.webbrowser.IInternalWebBrowser;
+import org.eclipse.webbrowser.IInternalWebBrowserWorkingCopy;
+import org.eclipse.webbrowser.IWebBrowser;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+/**
+ *
+ */
+public class BrowserTableComposite extends Composite {
+ protected Table table;
+ protected CheckboxTableViewer tableViewer;
+ protected Button edit;
+ protected Button remove;
+ protected Button search;
+ protected IWebBrowser selection;
+
+ protected Label location;
+ protected Label parameters;
+
+ public BrowserTableComposite(Composite parent, int style) {
+ super(parent, style);
+ createWidgets();
+ }
+
+ protected void createWidgets() {
+ GridLayout layout = new GridLayout();
+ layout.horizontalSpacing = 5;
+ layout.verticalSpacing = 5;
+ layout.marginWidth = 0;
+ layout.marginHeight = 0;
+ layout.numColumns = 2;
+ setLayout(layout);
+
+ GridData data = new GridData(GridData.FILL_BOTH);
+ setLayoutData(data);
+
+ Label label = new Label(this, SWT.NONE);
+ label.setText(WebBrowserUIPlugin.getResource("%browserList"));
+ data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
+ data.horizontalSpan = 2;
+ label.setLayoutData(data);
+
+ table = new Table(this, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION);
+ data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
+ data.widthHint = 300;
+ table.setLayoutData(data);
+ table.setHeaderVisible(false);
+ table.setLinesVisible(false);
+
+ TableLayout tableLayout = new TableLayout();
+ new TableColumn(table, SWT.NONE);
+
+ tableLayout.addColumnData(new ColumnWeightData(100));
+
+ table.setLayout(tableLayout);
+
+ tableViewer = new CheckboxTableViewer(table);
+
+ tableViewer.setContentProvider(new BrowserContentProvider());
+ tableViewer.setLabelProvider(new BrowserTableLabelProvider());
+
+ tableViewer.setInput("root");
+
+ // uncheck any other elements that might be checked and leave only the element checked to
+ // remain checked since one can only chose one brower at a time to be current.
+ tableViewer.addCheckStateListener(new ICheckStateListener() {
+ public void checkStateChanged(CheckStateChangedEvent e) {
+ checkNewDefaultBrowser(e.getElement());
+ IWebBrowser browser = (IWebBrowser) e.getElement();
+ BrowserManager.getInstance().setCurrentWebBrowser(browser);
+
+ // if no other browsers are checked, don't allow the single one currently
+ // checked to become unchecked, and lose a current browser. That is, don't
+ // permit unchecking if no other item is checked which is supposed to be the case.
+ Object[] obj = tableViewer.getCheckedElements();
+ if (obj.length == 0)
+ tableViewer.setChecked(e.getElement(), true);
+ }
+ });
+
+ // set a default, checked browser based on the current browser. If there is not a
+ // current browser, but the first item exists, use that instead.
+ // This will work currently until workbench shutdown, because current browser is not yet persisted.
+ IWebBrowser browser = BrowserManager.getInstance().getCurrentWebBrowser();
+ if (browser != null)
+ tableViewer.setChecked(browser, true);
+ else {
+ Object obj = tableViewer.getElementAt(0);
+ if (obj != null)
+ tableViewer.setChecked(obj, true);
+ }
+
+ tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ Object obj = getSelection(event.getSelection());
+
+ if (obj instanceof IInternalWebBrowser) {
+ selection = (IInternalWebBrowser) obj;
+ remove.setEnabled(false);
+ edit.setEnabled(true);
+ } else if (obj instanceof IExternalWebBrowser) {
+ selection = (IExternalWebBrowser) obj;
+ remove.setEnabled(true);
+ edit.setEnabled(true);
+ } else
+ selection = null;
+
+ if (selection == null) {
+ edit.setEnabled(false);
+ remove.setEnabled(false);
+ }
+ }
+ });
+
+ Composite buttonComp = new Composite(this, SWT.NONE);
+ layout = new GridLayout();
+ layout.horizontalSpacing = 0;
+ layout.verticalSpacing = 5;
+ layout.marginWidth = 0;
+ layout.marginHeight = 0;
+ layout.numColumns = 1;
+ buttonComp.setLayout(layout);
+ data = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_FILL);
+ buttonComp.setLayoutData(data);
+
+ Button add = SWTUtil.createButton(buttonComp, WebBrowserUIPlugin.getResource("%add"));
+ add.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ ExternalBrowserDialog dialog = new ExternalBrowserDialog(getShell());
+ if (dialog.open() == Window.CANCEL)
+ return;
+ tableViewer.refresh();
+ }
+ });
+
+ edit = SWTUtil.createButton(buttonComp, WebBrowserUIPlugin.getResource("%edit"));
+ edit.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ IWebBrowser browser2 = getSelectedWebBrowser();
+
+ if (browser2 instanceof IInternalWebBrowser) {
+ IInternalWebBrowserWorkingCopy wc = ((IInternalWebBrowser) browser2).getWorkingCopy();
+ InternalBrowserDialog dialog = new InternalBrowserDialog(getShell(), wc);
+ if (dialog.open() != Window.CANCEL) {
+ try {
+ tableViewer.refresh(wc.save());
+ } catch (Exception ex) { }
+ }
+ }
+ else if(browser2 instanceof IExternalWebBrowser) {
+ IExternalWebBrowserWorkingCopy wc = ((IExternalWebBrowser) browser2).getWorkingCopy();
+ ExternalBrowserDialog dialog = new ExternalBrowserDialog(getShell(), wc);
+ if (dialog.open() != Window.CANCEL) {
+ try {
+ tableViewer.refresh(wc.save());
+ } catch (Exception ex) { }
+ }
+ }
+ }
+ });
+ edit.setEnabled(false);
+
+ remove = SWTUtil.createButton(buttonComp, WebBrowserUIPlugin.getResource("%remove"));
+ remove.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ IWebBrowser browser2 = getSelectedWebBrowser();
+ try {
+ if (browser2 instanceof IInternalWebBrowser){
+ remove.setEnabled(false);
+ return; // nothing else possible to do
+ }
+ else if(browser2 instanceof IExternalWebBrowser) {
+ remove.setEnabled(true);
+ ((IExternalWebBrowser) browser2).delete();
+
+ tableViewer.remove(browser2);
+
+ // need here to ensure that if the item deleted was checked, ie, was
+ // the current browser, that the new current browser will be the first in the
+ // list, typically, the internal browser, which cannot be deleted, and be current.
+ if(((IExternalWebBrowser) browser2) == BrowserManager.getInstance().getCurrentWebBrowser()){
+ Object obj = tableViewer.getElementAt(0);
+ if(obj != null){
+ BrowserManager.getInstance().setCurrentWebBrowser((InternalWebBrowser)obj);
+ tableViewer.setChecked(obj, true);
+ }
+ }
+ }
+ } catch (Exception ex) { }
+ }
+ });
+ remove.setEnabled(false);
+
+ search = SWTUtil.createButton(buttonComp, WebBrowserUIPlugin.getResource("%search"));
+ search.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ java.util.List browsersToCreate = BrowserSearcher.search(getShell());
+
+ if (browsersToCreate == null) // cancelled
+ return;
+
+ if (browsersToCreate.isEmpty()) { // no browsers found
+ WebBrowserUtil.openMessage(WebBrowserUIPlugin.getResource("%searchingNoneFound"));
+ return;
+ }
+
+ Iterator iterator = browsersToCreate.iterator();
+ while (iterator.hasNext()) {
+ IExternalWebBrowserWorkingCopy browser2 = (IExternalWebBrowserWorkingCopy) iterator.next();
+ browser2.save();
+ }
+ tableViewer.refresh();
+ }
+ });
+ WorkbenchHelp.setHelp(search, ContextIds.PREF_BROWSER_EXTERNAL_SEARCH);
+
+ tableViewer.addCheckStateListener(new ICheckStateListener() {
+ public void checkStateChanged(CheckStateChangedEvent e) {
+ checkNewDefaultBrowser(e.getElement());
+ IWebBrowser browser2 = (IWebBrowser) e.getElement();
+ BrowserManager.getInstance().setCurrentWebBrowser(browser2);
+ }
+ });
+ search.setEnabled(true);
+ }
+
+ public IWebBrowser getSelectedWebBrowser() {
+ return selection;
+ }
+
+ protected Object getSelection(ISelection sel2) {
+ IStructuredSelection sel = (IStructuredSelection) sel2;
+ return sel.getFirstElement();
+ }
+
+ // Uncheck all the items except the current one that was just checked
+ protected void checkNewDefaultBrowser(Object browser) {
+ TableItem[] children = tableViewer.getTable().getItems();
+ for (int i = 0; i < children.length; i++) {
+ TableItem item = children[i];
+
+ if (!(item.getData().equals(browser)))
+ item.setChecked(false);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/**********************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.webbrowser.internal;
+
+import org.eclipse.jface.viewers.ILabelProviderListener;
+
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.webbrowser.IExternalWebBrowser;
+import org.eclipse.webbrowser.IInternalWebBrowser;
+import org.eclipse.webbrowser.IWebBrowser;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+/**
+ * Web browser table label provider.
+ */
+public class BrowserTableLabelProvider implements ITableLabelProvider {
+ /**
+ * BrowserTableLabelProvider constructor comment.
+ */
+ public BrowserTableLabelProvider() {
+ super();
+ }
+
+ /**
+ *
+ */
+ public void addListener(ILabelProviderListener listener) { }
+
+ /**
+ *
+ */
+ public void dispose() { }
+
+ /**
+ *
+ */
+ public Image getColumnImage(Object element, int columnIndex) {
+ if (columnIndex == 0) {
+ if (element instanceof IInternalWebBrowser)
+ return ImageResource.getImage(ImageResource.IMG_INTERNAL_BROWSER);
+ else
+ return ImageResource.getImage(ImageResource.IMG_EXTERNAL_BROWSER);
+ }
+ return null;
+ }
+
+ /**
+ * Returns the label text for the given column of the given element.
+ *
+ * @param element the object representing the entire row, or
+ * <code>null</code> indicating that no input object is set
+ * in the viewer
+ * @param columnIndex the zero-based index of the column in which the label appears
+ */
+ public String getColumnText(Object element, int columnIndex) {
+ IWebBrowser browser = (IWebBrowser)element;
+ if (browser instanceof IExternalWebBrowser) {
+ if (columnIndex == 0)
+ return notNull(((IExternalWebBrowser)browser).getName());
+ else if (columnIndex == 1)
+ return notNull(((IExternalWebBrowser)browser).getLocation());
+ else if (columnIndex == 2)
+ return notNull(((IExternalWebBrowser)browser).getParameters());
+ } else if(browser instanceof IInternalWebBrowser) {
+ if (columnIndex == 0)
+ return notNull(((IInternalWebBrowser)browser).getName());
+ }
+ return "";
+ }
+
+ protected String notNull(String s) {
+ if (s != null)
+ return s;
+ else
+ return "";
+ }
+
+ /**
+ *
+ */
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+
+ /**
+ *
+ */
+ public void removeListener(ILabelProviderListener listener) { }
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. Â This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ */
+package org.eclipse.webbrowser.internal;
+
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.graphics.*;
+/**
+ * An animated image to show busy status of the Web browser.
+ */
+public class BusyIndicator extends Canvas {
+ protected Image[] images;
+ protected Image image;
+
+ protected Thread busyThread;
+ protected boolean stop;
+
+ /**
+ * BusyWidget constructor comment.
+ * @param parent org.eclipse.swt.widgets.Composite
+ * @param style int
+ */
+ public BusyIndicator(Composite parent, int style) {
+ super(parent, style);
+
+ images = ImageResource.getBusyImages();
+
+ addPaintListener(new PaintListener() {
+ public void paintControl(PaintEvent event) {
+ onPaint(event);
+ }
+ });
+
+ image = images[0];
+ }
+
+ public Point computeSize(int wHint, int hHint, boolean changed) {
+ return new Point(25, 25);
+ }
+
+ /**
+ * Creates a thread to animate the image.
+ */
+ protected synchronized void createBusyThread() {
+ if (busyThread != null)
+ return;
+
+ stop = false;
+ busyThread = new Thread() {
+ protected int count;
+ public void run() {
+ try {
+ count = 1;
+ while (!stop) {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ if (!stop) {
+ if (count < 13)
+ setImage(images[count]);
+ count++;
+ if (count > 12)
+ count = 1;
+ }
+ }
+ });
+ try {
+ sleep(125);
+ } catch (Exception e) { }
+ }
+ if (busyThread == null)
+ Display.getDefault().syncExec(new Thread() {
+ public void run() {
+ setImage(images[0]);
+ }
+ });
+ } catch (Exception e) {
+ Trace.trace(Trace.WARNING, "Busy error", e);
+ }
+ }
+ };
+
+ busyThread.setPriority(Thread.NORM_PRIORITY + 2);
+ busyThread.setDaemon(true);
+ busyThread.start();
+ }
+
+ public void dispose() {
+ stop = true;
+ busyThread = null;
+ super.dispose();
+ }
+
+ /**
+ * Return the image or <code>null</code>.
+ */
+ public Image getImage() {
+ return image;
+ }
+
+ /**
+ * Returns true if it is currently busy.
+ *
+ * @return boolean
+ */
+ public boolean isBusy() {
+ return (busyThread != null);
+ }
+
+ /*
+ * Process the paint event
+ */
+ protected void onPaint(PaintEvent event) {
+ Rectangle rect = getClientArea();
+ if (rect.width == 0 || rect.height == 0)
+ return;
+
+ GC gc = event.gc;
+ if (image != null)
+ gc.drawImage(image, 2, 2);
+ }
+
+ /**
+ * Sets the indicators busy count up (true) or down (false) one.
+ *
+ * @param busy boolean
+ */
+ public synchronized void setBusy(boolean busy) {
+ if (busy) {
+ if (busyThread == null)
+ createBusyThread();
+ } else {
+ if (busyThread != null) {
+ stop = true;
+ busyThread = null;
+ }
+ }
+ }
+
+ /**
+ * Set the image.
+ * The value <code>null</code> clears it.
+ */
+ public void setImage(Image image) {
+ if (image != this.image && !isDisposed()) {
+ this.image = image;
+ redraw();
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. Â This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ */
+package org.eclipse.webbrowser.internal;
+/**
+ * Context help id constants.
+ */
+public interface ContextIds {
+ public static final String PREF_BROWSER = WebBrowserUIPlugin.PLUGIN_ID + ".wbpr0000";
+ public static final String PREF_BROWSER_INTERNAL = WebBrowserUIPlugin.PLUGIN_ID + ".wbpr0002";
+ public static final String PREF_BROWSER_EXTERNAL_ADD = WebBrowserUIPlugin.PLUGIN_ID + ".wbpr0004";
+ public static final String PREF_BROWSER_EXTERNAL_EDIT = WebBrowserUIPlugin.PLUGIN_ID + ".wbpr0005";
+ public static final String PREF_BROWSER_EXTERNAL_SEARCH = WebBrowserUIPlugin.PLUGIN_ID + ".wbpr0006";
+
+ public static final String WEB_BROWSER = WebBrowserUIPlugin.PLUGIN_ID + ".sewb0000";
+ public static final String WEB_BROWSER_URL = WebBrowserUIPlugin.PLUGIN_ID + ".sewb0002";
+ public static final String WEB_BROWSER_WEB = WebBrowserUIPlugin.PLUGIN_ID + ".sewb0004";
+}
\ No newline at end of file
--- /dev/null
+/**********************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.webbrowser.internal;
+
+import java.io.File;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.help.WorkbenchHelp;
+import org.eclipse.webbrowser.IExternalWebBrowserWorkingCopy;
+/**
+ *
+ */
+public class ExternalBrowserDialog extends Dialog {
+ protected IExternalWebBrowserWorkingCopy browser;
+ protected boolean isEdit;
+ protected Button newPageCheckbox;
+ protected Button clearHistoryCheckbox;
+ protected Button browseButton;
+ protected Text browserNameTextfield;
+ protected Text browserLocationTextfield;
+ protected Text browserParametersTextfield;
+ private Button okButton;
+
+ interface StringModifyListener {
+ public void valueChanged(String s);
+ }
+
+ /**
+ * @param parentShell
+ */
+ public ExternalBrowserDialog(Shell parentShell, IExternalWebBrowserWorkingCopy browser) {
+ super(parentShell);
+ this.browser = browser;
+ isEdit = true;
+ }
+
+ public ExternalBrowserDialog(Shell parentShell) {
+ super(parentShell);
+ browser = BrowserManager.getInstance().createExternalWebBrowser();
+ isEdit = false;
+ }
+
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+
+ if (isEdit)
+ shell.setText(WebBrowserUIPlugin.getResource("%editExternalBrowser"));
+ else
+ shell.setText(WebBrowserUIPlugin.getResource("%createBrowser"));
+ }
+
+ protected Text createText(Composite comp, String txt, final StringModifyListener listener) {
+ final Text text = new Text(comp, SWT.BORDER);
+ if (txt != null)
+ text.setText(txt);
+ GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
+ data.widthHint = 250;
+ text.setLayoutData(data);
+ if (listener != null)
+ text.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ listener.valueChanged(text.getText());
+ }
+ });
+ return text;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+ */
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+ ((GridLayout)composite.getLayout()).numColumns = 3;
+
+ if (isEdit)
+ WorkbenchHelp.setHelp(composite, ContextIds.PREF_BROWSER_EXTERNAL_EDIT);
+ else
+ WorkbenchHelp.setHelp(composite, ContextIds.PREF_BROWSER_EXTERNAL_ADD);
+
+ SWTUtil.createLabel(composite, WebBrowserUIPlugin.getResource("%name"));
+ browserNameTextfield = createText(composite, browser.getName(), new StringModifyListener() {
+ public void valueChanged(String s) {
+ browser.setName(s);
+ validateFields();
+ }
+ });
+
+ new Label(composite, SWT.NONE);
+
+ SWTUtil.createLabel(composite, WebBrowserUIPlugin.getResource("%location"));
+ browserLocationTextfield = createText(composite, browser.getLocation(), new StringModifyListener() {
+ public void valueChanged(String s) {
+ browser.setLocation(s);
+ validateFields();
+ }
+ });
+
+ browseButton = SWTUtil.createButton(composite, WebBrowserUIPlugin.getResource("%browse"));
+ browseButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
+ dialog.setText(WebBrowserUIPlugin.getResource("%browseMessage"));
+
+ String fname = browserLocationTextfield.getText();
+
+ dialog.setFileName(fname);
+ fname = dialog.open();
+
+ if (fname != null)
+ browserLocationTextfield.setText(fname);
+ }
+ });
+
+ SWTUtil.createLabel(composite, WebBrowserUIPlugin.getResource("%parameters"));
+ browserParametersTextfield = createText(composite, browser.getParameters(), new StringModifyListener() {
+ public void valueChanged(String s) {
+ browser.setParameters(s);
+ }
+ });
+
+ new Label(composite, SWT.NONE);
+
+ new Label(composite, SWT.NONE);
+ Label urlLabel = new Label(composite, SWT.NONE);
+ urlLabel.setText(WebBrowserUIPlugin.getResource("%parametersMessage", WebBrowserPreference.URL_PARAMETER));
+
+
+ return composite;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#okPressed()
+ */
+ protected void okPressed() {
+ // do simple field validation to at least ensure target directory entered is valid pathname
+ try {
+ File file = new File(browser.getLocation());
+ if(!file.isFile()){
+ WebBrowserUtil.openError(WebBrowserUIPlugin.getResource("%locationInvalid"));
+ return;
+ }
+ }
+ catch(Exception e){
+ WebBrowserUtil.openError(WebBrowserUIPlugin.getResource("%locationInvalid"));
+ return;
+ }
+
+ browser.save();
+ super.okPressed();
+ }
+
+ private void setOKButtonEnabled(boolean curIsEnabled) {
+ if (okButton == null)
+ okButton = getButton(IDialogConstants.OK_ID);
+
+ if (okButton != null)
+ okButton.setEnabled(curIsEnabled);
+ }
+
+ protected Control createButtonBar(Composite parent) {
+ Control buttonControl = super.createButtonBar(parent);
+ validateFields();
+ return buttonControl;
+ }
+
+ protected void validateFields() {
+ boolean valid = true;
+
+ String name = browserNameTextfield.getText();
+ if (name == null || name.trim().length() < 1)
+ valid = false;
+
+ String location = browserLocationTextfield.getText();
+ if (location == null || location.trim().length() < 1)
+ valid = false;
+
+ setOKButtonEnabled(valid);
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.eclipse.webbrowser.internal;
+
+import java.net.URL;
+
+import org.eclipse.swt.program.Program;
+import org.eclipse.ui.IMemento;
+import org.eclipse.webbrowser.IExternalWebBrowser;
+import org.eclipse.webbrowser.IExternalWebBrowserWorkingCopy;
+/**
+ *
+ */
+public class ExternalWebBrowser implements IExternalWebBrowser {
+ private static final String MEMENTO_NAME = "name";
+ private static final String MEMENTO_LOCATION = "location";
+ private static final String MEMENTO_PARAMETERS = "parameters";
+
+ protected String name;
+ protected String location;
+ protected String parameters;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.webbrowser.IWebBrowser#getName()
+ */
+ public String getName() {
+ return name;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.webbrowser.IExternalWebBrowser#getLocation()
+ */
+ public String getLocation() {
+ return location;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.webbrowser.IExternalWebBrowser#getParameters()
+ */
+ public String getParameters() {
+ return parameters;
+ }
+
+ public void delete() {
+ BrowserManager.getInstance().removeWebBrowser(this);
+ }
+
+ public boolean isWorkingCopy() {
+ return false;
+ }
+
+ public IExternalWebBrowserWorkingCopy getWorkingCopy() {
+ return new ExternalWebBrowserWorkingCopy(this);
+ }
+
+ protected void setInternal(IExternalWebBrowser browser) {
+ name = browser.getName();
+ location = browser.getLocation();
+ parameters = browser.getParameters();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.webbrowser.IWebBrowser#openURL(java.net.URL)
+ */
+ public void openURL(URL url) {
+ String urlText = WebBrowserPreference.getHomePageURL();
+
+ if (url != null)
+ urlText = url.toExternalForm();
+ else if (urlText.startsWith("file:") & urlText.length() > 6) {
+ if (urlText.charAt(5) != '/' && urlText.charAt(5) != '\\')
+ urlText = urlText.substring(0, 5) + "/" + urlText.substring(5);
+ }
+
+ // change spaces to "%20"
+ if (!WebBrowserUtil.isWindows()) {
+ int index = urlText.indexOf(" ");
+ while (index >= 0) {
+ urlText = urlText.substring(0, index) + "%20" + urlText.substring(index + 1);
+ index = urlText.indexOf(" ");
+ }
+ }
+
+ Trace.trace(Trace.FINEST, "Launching external Web browser: " + location + " - " + parameters + " - " + urlText);
+ if (location == null || location.length() == 0) {
+ try {
+ String extension = null;
+ if (url != null)
+ extension = url.getFile();
+ else
+ extension = "html";
+ int index = extension.indexOf(".");
+ if (index >= 0)
+ extension = extension.substring(index + 1);
+ Program program = Program.findProgram(extension);
+ program.execute(urlText);
+ } catch (Exception e) {
+ Trace.trace(Trace.SEVERE, "Error launching default external browser", e);
+ WebBrowserUtil.openError(WebBrowserUIPlugin.getResource("%errorCouldNotLaunchWebBrowser", urlText));
+ }
+ return;
+ }
+
+ String params = parameters;
+ if (params == null)
+ params = "";
+
+ int urlIndex = params.indexOf(WebBrowserPreference.URL_PARAMETER);
+ if (urlIndex >= 0)
+ params = params.substring(0, urlIndex) + " " + urlText + " " + params.substring(urlIndex + WebBrowserPreference.URL_PARAMETER.length());
+ else {
+ if (!params.endsWith(" "))
+ params += " ";
+ params += urlText;
+ }
+
+ try {
+ Trace.trace(Trace.FINEST, "Launching " + location + " " + params);
+ Runtime.getRuntime().exec(location + " " + params);
+ } catch (Exception e) {
+ Trace.trace(Trace.SEVERE, "Could not launch external browser", e);
+ WebBrowserUtil.openError(WebBrowserUIPlugin.getResource("%errorCouldNotLaunchWebBrowser", urlText));
+ }
+ }
+
+ protected void save(IMemento memento) {
+ memento.putString(MEMENTO_NAME, name);
+ memento.putString(MEMENTO_LOCATION, location);
+ memento.putString(MEMENTO_PARAMETERS, parameters);
+ }
+
+ protected void load(IMemento memento) {
+ name = memento.getString(MEMENTO_NAME);
+ location = memento.getString(MEMENTO_LOCATION);
+ parameters = memento.getString(MEMENTO_PARAMETERS);
+ }
+
+ public String toString() {
+ return "External Web browser: " + getName() + " / " + getLocation() + " / " + getParameters();
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.eclipse.webbrowser.internal;
+
+import org.eclipse.webbrowser.IExternalWebBrowser;
+import org.eclipse.webbrowser.IExternalWebBrowserWorkingCopy;
+/**
+ *
+ */
+public class ExternalWebBrowserWorkingCopy extends ExternalWebBrowser implements IExternalWebBrowserWorkingCopy {
+ protected ExternalWebBrowser browser;
+
+ // creation
+ public ExternalWebBrowserWorkingCopy() { }
+
+ // working copy
+ public ExternalWebBrowserWorkingCopy(ExternalWebBrowser browser) {
+ this.browser = browser;
+ setInternal(browser);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.webbrowser.IExternalWebBrowserWorkingCopy#setName(java.lang.String)
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.webbrowser.IExternalWebBrowserWorkingCopy#setLocation(java.lang.String)
+ */
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.webbrowser.IExternalWebBrowserWorkingCopy#setParameters(java.lang.String)
+ */
+ public void setParameters(String params) {
+ this.parameters = params;
+ }
+
+ public boolean isWorkingCopy() {
+ return true;
+ }
+
+ public IExternalWebBrowserWorkingCopy getWorkingCopy() {
+ return this;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.webbrowser.IExternalWebBrowserWorkingCopy#save()
+ */
+ public IExternalWebBrowser save() {
+ if (browser != null) {
+ browser.setInternal(this);
+ BrowserManager.getInstance().browserChanged(browser);
+ } else {
+ browser = new ExternalWebBrowser();
+ browser.setInternal(this);
+ BrowserManager.getInstance().addBrowser(browser);
+ }
+ return browser;
+ }
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. Â This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ */
+package org.eclipse.webbrowser.internal;
+/**
+ *
+ */
+public class Favorite {
+ protected String url;
+ protected String name;
+
+ public Favorite() { }
+
+ public Favorite(String name, String url) {
+ if (name == null)
+ name = "";
+ if (url == null)
+ url = "";
+ this.name = name;
+ this.url = url;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getURL() {
+ return url;
+ }
+
+ public void setURL(String url) {
+ this.url = url;
+ }
+
+ public boolean equals(Object obj) {
+ if (!(obj instanceof Favorite))
+ return false;
+
+ Favorite f = (Favorite) obj;
+ return (name.equals(f.name) && url.equals(f.url));
+ }
+
+ public String toString() {
+ return "(" + name + "/" + url + ")";
+ }
+}
\ No newline at end of file
--- /dev/null
+/**********************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.webbrowser.internal;
+
+import org.eclipse.webbrowser.IWebBrowser;
+
+/**
+ *
+ */
+public interface IWebBrowserListener {
+ public void browserAdded(IWebBrowser browser);
+
+ public void browserChanged(IWebBrowser browser);
+
+ public void browserRemoved(IWebBrowser browser);
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. Â This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ */
+package org.eclipse.webbrowser.internal;
+
+import java.net.URL;
+import java.util.Map;
+import java.util.HashMap;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ImageRegistry;
+/**
+ * Utility class to handle image resources.
+ */
+public class ImageResource {
+ // the image registry
+ private static ImageRegistry imageRegistry;
+
+ // map of image descriptors since these
+ // will be lost by the image registry
+ private static Map imageDescriptors;
+
+ // base urls for images
+ private static URL ICON_BASE_URL;
+
+ static {
+ try {
+ String pathSuffix = "icons/";
+ ICON_BASE_URL = WebBrowserUIPlugin.getInstance().getBundle().getEntry(pathSuffix);
+ } catch (Exception e) {
+ Trace.trace(Trace.SEVERE, "Could not set icon base URL", e);
+ }
+ }
+
+ private static Image[] busyImages;
+
+ private static final String URL_CLCL = "clcl16/";
+ private static final String URL_ELCL = "elcl16/";
+ private static final String URL_DLCL = "dlcl16/";
+
+ private static final String URL_OBJ = "obj16/";
+
+ // --- constants for images ---
+ // toolbar images
+ public static final String IMG_CLCL_NAV_BACKWARD = "IMG_CLCL_NAV_BACKWARD";
+ public static final String IMG_CLCL_NAV_FORWARD = "IMG_CLCL_NAV_FORWARD";
+ public static final String IMG_CLCL_NAV_STOP = "IMG_CLCL_NAV_STOP";
+ public static final String IMG_CLCL_NAV_REFRESH = "IMG_CLCL_NAV_REFRESH";
+ public static final String IMG_CLCL_NAV_GO = "IMG_CLCL_NAV_GO";
+ public static final String IMG_CLCL_NAV_FAVORITES = "cfavorites";
+ public static final String IMG_CLCL_NAV_HOME = "IMG_CLCL_NAV_HOME";
+ public static final String IMG_CLCL_NAV_PRINT = "IMG_CLCL_NAV_PRINT";
+
+ public static final String IMG_ELCL_NAV_BACKWARD = "IMG_ELCL_NAV_BACKWARD";
+ public static final String IMG_ELCL_NAV_FORWARD = "IMG_ELCL_NAV_FORWARD";
+ public static final String IMG_ELCL_NAV_STOP = "IMG_ELCL_NAV_STOP";
+ public static final String IMG_ELCL_NAV_REFRESH = "IMG_ELCL_NAV_REFRESH";
+ public static final String IMG_ELCL_NAV_GO = "IMG_ELCL_NAV_GO";
+ public static final String IMG_ELCL_NAV_FAVORITES = "efavorites";
+ public static final String IMG_ELCL_NAV_HOME = "IMG_ELCL_NAV_HOME";
+ public static final String IMG_ELCL_NAV_PRINT = "IMG_ELCL_NAV_PRINT";
+
+ public static final String IMG_DLCL_NAV_BACKWARD = "IMG_DLCL_NAV_BACKWARD";
+ public static final String IMG_DLCL_NAV_FORWARD = "IMG_DLCL_NAV_FORWARD";
+ public static final String IMG_DLCL_NAV_STOP = "IMG_DLCL_NAV_STOP";
+ public static final String IMG_DLCL_NAV_REFRESH = "IMG_DLCL_NAV_REFRESH";
+ public static final String IMG_DLCL_NAV_GO = "IMG_DLCL_NAV_GO";
+ public static final String IMG_DLCL_NAV_FAVORITES = "dfavorites";
+ public static final String IMG_DLCL_NAV_HOME = "IMG_DLCL_NAV_HOME";
+ public static final String IMG_DLCL_NAV_PRINT = "IMG_DLCL_NAV_PRINT";
+
+ // general object images
+ public static final String IMG_INTERNAL_BROWSER = "internalBrowser";
+ public static final String IMG_EXTERNAL_BROWSER = "externalBrowser";
+ public static final String IMG_FAVORITE = "favorite";
+
+ /**
+ * Cannot construct an ImageResource. Use static methods only.
+ */
+ private ImageResource() { }
+
+ /**
+ * Returns the busy images for the Web browser.
+ *
+ * @return org.eclipse.swt.graphics.Image[]
+ */
+ public static Image[] getBusyImages() {
+ return busyImages;
+ }
+
+ /**
+ * Return the image with the given key.
+ *
+ * @param key java.lang.String
+ * @return org.eclipse.swt.graphics.Image
+ */
+ public static Image getImage(String key) {
+ if (imageRegistry == null)
+ initializeImageRegistry();
+ return imageRegistry.get(key);
+ }
+
+ /**
+ * Return the image descriptor with the given key.
+ *
+ * @param key java.lang.String
+ * @return org.eclipse.jface.resource.ImageDescriptor
+ */
+ public static ImageDescriptor getImageDescriptor(String key) {
+ if (imageRegistry == null)
+ initializeImageRegistry();
+ return (ImageDescriptor) imageDescriptors.get(key);
+ }
+
+ /**
+ * Initialize the image resources.
+ */
+ protected static void initializeImageRegistry() {
+ imageRegistry = new ImageRegistry();
+ imageDescriptors = new HashMap();
+
+ // load Web browser images
+ registerImage(IMG_ELCL_NAV_BACKWARD, URL_ELCL + "nav_backward.gif");
+ registerImage(IMG_ELCL_NAV_FORWARD, URL_ELCL + "nav_forward.gif");
+ registerImage(IMG_ELCL_NAV_STOP, URL_ELCL + "nav_stop.gif");
+ registerImage(IMG_ELCL_NAV_REFRESH, URL_ELCL + "nav_refresh.gif");
+ registerImage(IMG_ELCL_NAV_GO, URL_ELCL + "nav_go.gif");
+ registerImage(IMG_ELCL_NAV_FAVORITES, URL_ELCL + "add_favorite.gif");
+ registerImage(IMG_ELCL_NAV_HOME, URL_ELCL + "nav_home.gif");
+ registerImage(IMG_ELCL_NAV_PRINT, URL_ELCL + "nav_print.gif");
+
+ registerImage(IMG_CLCL_NAV_BACKWARD, URL_CLCL + "nav_backward.gif");
+ registerImage(IMG_CLCL_NAV_FORWARD, URL_CLCL + "nav_forward.gif");
+ registerImage(IMG_CLCL_NAV_STOP, URL_CLCL + "nav_stop.gif");
+ registerImage(IMG_CLCL_NAV_REFRESH, URL_CLCL + "nav_refresh.gif");
+ registerImage(IMG_CLCL_NAV_GO, URL_CLCL + "nav_go.gif");
+ registerImage(IMG_CLCL_NAV_FAVORITES, URL_CLCL + "add_favorite.gif");
+ registerImage(IMG_CLCL_NAV_HOME, URL_CLCL + "nav_home.gif");
+ registerImage(IMG_CLCL_NAV_PRINT, URL_CLCL + "nav_print.gif");
+
+ registerImage(IMG_DLCL_NAV_BACKWARD, URL_DLCL + "nav_backward.gif");
+ registerImage(IMG_DLCL_NAV_FORWARD, URL_DLCL + "nav_forward.gif");
+ registerImage(IMG_DLCL_NAV_STOP, URL_DLCL + "nav_stop.gif");
+ registerImage(IMG_DLCL_NAV_REFRESH, URL_DLCL + "nav_refresh.gif");
+ registerImage(IMG_DLCL_NAV_GO, URL_DLCL + "nav_go.gif");
+ registerImage(IMG_DLCL_NAV_FAVORITES, URL_DLCL + "add_favorite.gif");
+ registerImage(IMG_DLCL_NAV_HOME, URL_DLCL + "nav_home.gif");
+ registerImage(IMG_DLCL_NAV_PRINT, URL_DLCL + "nav_print.gif");
+
+ registerImage(IMG_INTERNAL_BROWSER, URL_OBJ + "internal_browser.gif");
+ registerImage(IMG_EXTERNAL_BROWSER, URL_OBJ + "external_browser.gif");
+
+ registerImage(IMG_FAVORITE, URL_OBJ + "favorite.gif");
+
+ // busy images
+ busyImages = new Image[13];
+ for (int i = 0; i < 13; i++) {
+ registerImage("busy" + i, URL_OBJ + "frames" + java.io.File.separator + "frame" + (i+1) + ".gif");
+ busyImages[i] = getImage("busy" + i);
+ }
+ }
+
+ /**
+ * Register an image with the registry.
+ *
+ * @param key java.lang.String
+ * @param partialURL java.lang.String
+ */
+ private static void registerImage(String key, String partialURL) {
+ try {
+ ImageDescriptor id = ImageDescriptor.createFromURL(new URL(ICON_BASE_URL, partialURL));
+ imageRegistry.put(key, id);
+ imageDescriptors.put(key, id);
+ } catch (Exception e) {
+ Trace.trace(Trace.WARNING, "Error registering image " + key + " from " + partialURL, e);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/**********************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.webbrowser.internal;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.help.WorkbenchHelp;
+import org.eclipse.webbrowser.IInternalWebBrowserWorkingCopy;
+import org.eclipse.webbrowser.internal.SWTUtil;
+/**
+ *
+ */
+public class InternalBrowserDialog extends Dialog {
+ protected IInternalWebBrowserWorkingCopy browser;
+ protected boolean isEdit;
+ protected Button newPageCheckbox;
+ protected Button clearURLHistoryCheckbox;
+
+ /**
+ * @param parentShell
+ */
+ public InternalBrowserDialog(Shell parentShell, IInternalWebBrowserWorkingCopy browser) {
+ super(parentShell);
+ this.browser = browser;
+ isEdit = true;
+ }
+
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+
+ if (isEdit)
+ shell.setText(WebBrowserUIPlugin.getResource("%editInternalBrowser"));
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+ */
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+ ((GridLayout)composite.getLayout()).numColumns = 1;
+
+ Composite comp = new Composite(composite, SWT.NONE);
+ GridLayout layout = new GridLayout(1, true);
+ layout.marginHeight = 10;
+ layout.marginWidth = 10;
+ comp.setLayout(layout);
+ comp.setLayoutData(new GridData(GridData.FILL_BOTH));
+ WorkbenchHelp.setHelp(composite, ContextIds.PREF_BROWSER_INTERNAL);
+
+ newPageCheckbox = SWTUtil.createCheckbox(comp, WebBrowserUIPlugin.getResource("%prefBrowserNewPage"), false);
+ clearURLHistoryCheckbox = SWTUtil.createCheckbox(comp, WebBrowserUIPlugin.getResource("%clearURLHistory"), true);
+
+ newPageCheckbox.setSelection(browser.getUseNewPage());
+ clearURLHistoryCheckbox.setSelection(browser.getClearHistoryOnExit());
+
+ return composite;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#okPressed()
+ */
+ protected void okPressed() {
+ browser.setUseNewPage(newPageCheckbox.getSelection());
+ browser.setClearHistoryOnExit(clearURLHistoryCheckbox.getSelection());
+ browser.save();
+
+ super.okPressed();
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.eclipse.webbrowser.internal;
+
+import java.net.URL;
+
+import org.eclipse.ui.IMemento;
+import org.eclipse.webbrowser.IInternalWebBrowser;
+import org.eclipse.webbrowser.IInternalWebBrowserWorkingCopy;
+import org.eclipse.webbrowser.WebBrowserEditorInput;
+/**
+ *
+ */
+public class InternalWebBrowser implements IInternalWebBrowser {
+ private static final String MEMENTO_NEW_PAGE = "new_page";
+ private static final String MEMENTO_CLEAR_HISTORY_ON_EXIT = "clear_history";
+
+ protected boolean useNewPage;
+ protected boolean clearHistory;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.webbrowser.IWebBrowser#getName()
+ */
+ public String getName() {
+ return WebBrowserUIPlugin.getResource("%internalWebBrowserName");
+ }
+
+ public boolean getUseNewPage() {
+ return useNewPage;
+ }
+
+ public boolean getClearHistoryOnExit() {
+ return clearHistory;
+ }
+
+ public boolean isWorkingCopy() {
+ return false;
+ }
+
+ public IInternalWebBrowserWorkingCopy getWorkingCopy() {
+ return new InternalWebBrowserWorkingCopy(this);
+ }
+
+ protected void setInternal(IInternalWebBrowser browser) {
+ useNewPage = browser.getUseNewPage();
+ clearHistory = browser.getClearHistoryOnExit();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.webbrowser.IWebBrowser#openURL(java.net.URL)
+ */
+ public void openURL(URL url) {
+ WebBrowserEditor.open(new WebBrowserEditorInput(url));
+ }
+
+ protected void save(IMemento memento) {
+ memento.putString(MEMENTO_NEW_PAGE, useNewPage ? "true" : "false");
+ memento.putString(MEMENTO_CLEAR_HISTORY_ON_EXIT, clearHistory ? "true" : "false");
+ }
+
+ protected void load(IMemento memento) {
+ String s = memento.getString(MEMENTO_NEW_PAGE);
+ if ("true".equals(s))
+ useNewPage = true;
+ else
+ useNewPage = false;
+
+ s = memento.getString(MEMENTO_CLEAR_HISTORY_ON_EXIT);
+ if ("true".equals(s))
+ clearHistory = true;
+ else
+ clearHistory = false;
+ }
+
+ public String toString() {
+ return "Internal Web browser";
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.eclipse.webbrowser.internal;
+
+import org.eclipse.webbrowser.IInternalWebBrowser;
+import org.eclipse.webbrowser.IInternalWebBrowserWorkingCopy;
+/**
+ *
+ */
+public class InternalWebBrowserWorkingCopy extends InternalWebBrowser implements IInternalWebBrowserWorkingCopy {
+ protected InternalWebBrowser browser;
+
+ // working copy
+ public InternalWebBrowserWorkingCopy(InternalWebBrowser browser) {
+ this.browser = browser;
+ setInternal(browser);
+ }
+
+ public void setUseNewPage(boolean b) {
+ useNewPage = b;
+ }
+
+ public void setClearHistoryOnExit(boolean b) {
+ clearHistory = b;
+ }
+
+ public boolean isWorkingCopy() {
+ return true;
+ }
+
+ public IInternalWebBrowserWorkingCopy getWorkingCopy() {
+ return this;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.webbrowser.IExternalWebBrowserWorkingCopy#save()
+ */
+ public IInternalWebBrowser save() {
+ if (browser != null) {
+ browser.setInternal(this);
+ BrowserManager.getInstance().browserChanged(browser);
+ }
+ return browser;
+ }
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. Â This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ */
+package org.eclipse.webbrowser.internal;
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.help.WorkbenchHelp;
+/**
+ * A preference page that holds internet preferences.
+ */
+public class InternetPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
+ /**
+ * InternetPreferencePage constructor comment.
+ */
+ public InternetPreferencePage() {
+ super();
+ noDefaultAndApplyButton();
+ }
+
+ /**
+ * Create the preference options.
+ *
+ * @param parent org.eclipse.swt.widgets.Composite
+ * @return org.eclipse.swt.widgets.Control
+ */
+ protected Control createContents(Composite parent) {
+ initializeDialogUnits(parent);
+
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 1;
+ layout.horizontalSpacing = convertHorizontalDLUsToPixels(4);
+ layout.verticalSpacing = convertVerticalDLUsToPixels(4);
+ layout.marginWidth = 0;
+ layout.marginHeight = 0;
+ composite.setLayout(layout);
+ GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
+ composite.setLayoutData(data);
+ WorkbenchHelp.setHelp(composite, ContextIds.PREF_BROWSER);
+
+ Label label = new Label(composite, SWT.WRAP);
+ label.setText(WebBrowserUIPlugin.getResource("%preferenceInternetDescription"));
+ data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
+ label.setLayoutData(data);
+
+ Dialog.applyDialogFont(composite);
+
+ return composite;
+ }
+
+ /**
+ * Initializes this preference page using the passed desktop.
+ *
+ * @param desktop the current desktop
+ */
+ public void init(IWorkbench workbench) { }
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. Â This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ */
+package org.eclipse.webbrowser.internal;
+
+import java.net.URL;
+import java.util.Iterator;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.ui.*;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.webbrowser.WebBrowser;
+import org.eclipse.webbrowser.WebBrowserEditorInput;
+import org.eclipse.webbrowser.internal.Trace;
+/**
+ * Action to open the Web broswer on a resource.
+ */
+public class OpenWithBrowserActionDelegate implements IActionDelegate {
+ private IResource resource;
+
+ /**
+ * OpenBrowserAction constructor comment.
+ */
+ public OpenWithBrowserActionDelegate() {
+ super();
+ }
+
+ /**
+ * Performs this action.
+ * <p>
+ * This method is called when the delegating action has been triggered.
+ * Implement this method to do the actual work.
+ * </p>
+ *
+ * @param action the action proxy that handles the presentation portion of the
+ * action
+ */
+ public void run(IAction action) {
+ URL url = null;
+ try {
+ url = new URL("file://" + resource.getLocation());
+ WebBrowser.openURL(new WebBrowserEditorInput(url, WebBrowserEditorInput.SHOW_ALL | WebBrowserEditorInput.FORCE_NEW_PAGE));
+ } catch (Exception e) {
+ Trace.trace(Trace.SEVERE, "Error opening browser on file", e);
+ }
+ }
+
+ /**
+ * Notifies this action delegate that the selection in the workbench has changed.
+ * <p>
+ * Implementers can use this opportunity to change the availability of the
+ * action or to modify other presentation properties.
+ * </p>
+ *
+ * @param action the action proxy that handles presentation portion of the action
+ * @param selection the current selection in the workbench
+ */
+ public void selectionChanged(IAction action, ISelection sel) {
+ if (sel.isEmpty() || !(sel instanceof IStructuredSelection)) {
+ action.setEnabled(false);
+ return;
+ }
+
+ IStructuredSelection select = (IStructuredSelection) sel;
+ Iterator iterator = select.iterator();
+ Object selection = iterator.next();
+ if (iterator.hasNext()) { // more than one selection (should never happen)
+ action.setEnabled(false);
+ return;
+ }
+
+ if (!(selection instanceof IResource)) {
+ action.setEnabled(false);
+ return;
+ }
+
+ resource = (IResource) selection;
+ action.setEnabled(true);
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.eclipse.webbrowser.internal;
+/**********************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. Â This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+import java.util.List;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.*;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Item;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+/**
+ * Dialog to manage the favorites list.
+ */
+public class OrganizeFavoritesDialog extends Dialog {
+ protected List favorites = WebBrowserPreference.getInternalWebBrowserFavorites();
+
+ public class FavoriteContentProvider implements IStructuredContentProvider {
+ public FavoriteContentProvider() {
+ super();
+ }
+
+ public void dispose() { }
+
+ public Object[] getElements(Object inputElement) {
+ return favorites.toArray();
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
+ }
+
+ public class FavoriteLabelProvider implements ITableLabelProvider {
+ public FavoriteLabelProvider() {
+ super();
+ }
+
+ public void addListener(ILabelProviderListener listener) { }
+
+ public void dispose() { }
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ if (columnIndex == 0)
+ return ImageResource.getImage(ImageResource.IMG_FAVORITE);
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ Favorite favorite = (Favorite) element;
+ if (columnIndex == 0)
+ return favorite.getName();
+ else
+ return favorite.getURL();
+ }
+
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+
+ public void removeListener(ILabelProviderListener listener) { }
+ }
+
+ /**
+ * ManageFavoritesDialog constructor comment.
+ * @param parentShell org.eclipse.swt.widgets.Shell
+ * @
+ */
+ public OrganizeFavoritesDialog(Shell parentShell) {
+ super(parentShell);
+
+ setBlockOnOpen(true);
+ }
+
+ /**
+ *
+ */
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText(WebBrowserUIPlugin.getResource("%dialogOrganizeFavoritesTitle"));
+ }
+
+ /**
+ *
+ */
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
+ layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
+ layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
+ layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
+ composite.setLayout(layout);
+ composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+ composite.setFont(parent.getFont());
+ //WorkbenchHelp.setHelp(composite, ContextIds.TERMINATE_SERVER_DIALOG);
+
+ Label label = new Label(composite, SWT.NONE);
+ label.setText(WebBrowserUIPlugin.getResource("%dialogOrganizeFavoritesMessage"));
+ GridData data = new GridData();
+ data.horizontalSpan = 2;
+ label.setLayoutData(data);
+
+ final Table table = new Table(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE);
+ data = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
+ data.widthHint = 300;
+ data.heightHint = 150;
+ table.setLayoutData(data);
+ table.setLinesVisible(true);
+
+ TableLayout tableLayout = new TableLayout();
+ table.setLayout(tableLayout);
+ table.setHeaderVisible(true);
+
+ tableLayout.addColumnData(new ColumnWeightData(5, 50, true));
+ TableColumn col = new TableColumn(table, SWT.NONE);
+ col.setText(WebBrowserUIPlugin.getResource("%dialogOrganizeFavoritesName"));
+
+ tableLayout.addColumnData(new ColumnWeightData(6, 60, true));
+ col = new TableColumn(table, SWT.NONE);
+ col.setText(WebBrowserUIPlugin.getResource("%dialogOrganizeFavoritesURL"));
+ table.setLayout(tableLayout);
+
+ final TableViewer tableViewer = new TableViewer(table);
+ tableViewer.setContentProvider(new FavoriteContentProvider());
+ tableViewer.setLabelProvider(new FavoriteLabelProvider());
+ tableViewer.setInput("root");
+ tableViewer.setColumnProperties(new String[] {"name", "url"});
+
+ tableViewer.setCellEditors(new CellEditor[] {new TextCellEditor(table), new TextCellEditor(table)});
+
+ ICellModifier cellModifier = new ICellModifier() {
+ public Object getValue(Object element, String property) {
+ Favorite f = (Favorite) element;
+ if ("name".equals(property))
+ return f.getName();
+ else
+ return f.getURL();
+ }
+
+ public boolean canModify(Object element, String property) {
+ return true;
+ }
+
+ public void modify(Object element, String property, Object value) {
+ if (element instanceof Item)
+ element = ((Item) element).getData();
+
+ try {
+ Favorite f = (Favorite) element;
+ String s = (String) value;
+ if ("name".equals(property))
+ f.setName(s);
+ else
+ f.setURL(s);
+ tableViewer.refresh(f);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ };
+ tableViewer.setCellModifier(cellModifier);
+
+ final Button remove = SWTUtil.createButton(composite, WebBrowserUIPlugin.getResource("%remove"));
+ remove.setEnabled(false);
+
+ tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ remove.setEnabled(!event.getSelection().isEmpty());
+ }
+ });
+
+ remove.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ int index = table.getSelectionIndex();
+ if (index < 0 || index >= favorites.size())
+ return;
+
+ tableViewer.remove(favorites.get(index));
+ favorites.remove(index);
+ }
+ });
+
+ Dialog.applyDialogFont(composite);
+
+ return composite;
+ }
+
+ protected void okPressed() {
+ WebBrowserPreference.setInternalWebBrowserFavorites(favorites);
+ super.okPressed();
+ }
+}
\ No newline at end of file
--- /dev/null
+/**********************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. Â This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.webbrowser.internal;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.FontMetrics;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+/**
+ * SWT Utility class.
+ */
+public class SWTUtil {
+ private static FontMetrics fontMetrics;
+
+ protected static void initializeDialogUnits(Control testControl) {
+ // Compute and store a font metric
+ GC gc = new GC(testControl);
+ gc.setFont(JFaceResources.getDialogFont());
+ fontMetrics = gc.getFontMetrics();
+ gc.dispose();
+ }
+
+ /**
+ * Returns a width hint for a button control.
+ */
+ protected static int getButtonWidthHint(Button button) {
+ int widthHint = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH);
+ return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
+ }
+
+ public static Button createButton(Composite comp, String label) {
+ Button b = new Button(comp, SWT.PUSH);
+ b.setText(label);
+ if (fontMetrics == null)
+ initializeDialogUnits(comp);
+ GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
+ data.widthHint = getButtonWidthHint(b);
+ data.heightHint = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_HEIGHT);
+ b.setLayoutData(data);
+ return b;
+ }
+
+ public static Button createCheckbox(Composite comp, String txt, boolean isSelected){
+ Button button = new Button(comp, SWT.CHECK);
+ button.setText(txt);
+ GridLayout layout = new GridLayout();
+ comp.setLayout(layout);
+ GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
+ data.horizontalIndent = 10;
+ button.setLayoutData(data);
+ button.setSelection(isSelected);
+ return button;
+ }
+
+ public static Label createLabel(Composite comp, String txt) {
+ Label label = new Label(comp, SWT.NONE);
+ label.setText(txt);
+ label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING));
+ return label;
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ */
+package org.eclipse.webbrowser.internal;
+
+import org.eclipse.webbrowser.IURLMap;
+/**
+ * Standard URL mappings.
+ */
+public class StandardURLMap implements IURLMap {
+ /**
+ * @see IURLMap#getMappedURL(String)
+ */
+ public String getMappedURL(String url) {
+ if (url.equalsIgnoreCase("eclipse"))
+ return "http://www.eclipse.org";
+ else if (url.equalsIgnoreCase("webtools"))
+ return "http://www.eclipse.org/webtools/";
+ else
+ return null;
+ }
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ */
+package org.eclipse.webbrowser.internal;
+
+import java.util.Iterator;
+
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.swt.events.MenuAdapter;
+import org.eclipse.swt.events.MenuEvent;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.ui.*;
+import org.eclipse.webbrowser.IWebBrowser;
+/**
+ * Action to open the Web broswer.
+ */
+public class SwitchBrowserWorkbenchAction implements IWorkbenchWindowPulldownDelegate2 {
+ /**
+ * The menu created by this action
+ */
+ private Menu fMenu;
+
+ protected boolean recreateMenu = false;
+
+ /**
+ * SwitchBrowserWorkbenchAction constructor comment.
+ */
+ public SwitchBrowserWorkbenchAction() {
+ super();
+ }
+
+ public void dispose() {
+ setMenu(null);
+ }
+
+ /**
+ * Sets this action's drop-down menu, disposing the previous menu.
+ *
+ * @param menu the new menu
+ */
+ private void setMenu(Menu menu) {
+ if (fMenu != null) {
+ fMenu.dispose();
+ }
+ fMenu = menu;
+ }
+
+ public void init(IWorkbenchWindow window) { }
+
+ /**
+ * Adds the given action to the specified menu with an accelerator specified
+ * by the given number.
+ *
+ * @param menu the menu to add the action to
+ * @param action the action to add
+ * @param accelerator the number that should appear as an accelerator
+ */
+ protected void addToMenu(Menu menu, IAction action, int accelerator) {
+ StringBuffer label= new StringBuffer();
+ if (accelerator >= 0 && accelerator < 10) {
+ //add the numerical accelerator
+ label.append('&');
+ label.append(accelerator);
+ label.append(' ');
+ }
+ label.append(action.getText());
+ action.setText(label.toString());
+ ActionContributionItem item= new ActionContributionItem(action);
+ item.fill(menu, -1);
+ }
+
+ /**
+ * Fills the drop-down menu with favorites and launch history,
+ * launch shortcuts, and an action to open the launch configuration dialog.
+ *
+ * @param menu the menu to fill
+ */
+ protected void fillMenu(Menu menu) {
+ IWebBrowser current = BrowserManager.getInstance().getCurrentWebBrowser();
+ Iterator iterator = BrowserManager.getInstance().getWebBrowsers().iterator();
+ int i = 0;
+ while (iterator.hasNext()) {
+ IWebBrowser browser = (IWebBrowser) iterator.next();
+ addToMenu(menu, new SwitchDefaultBrowserAction(browser, browser.equals(current)), i++);
+ }
+ }
+
+ /**
+ * Creates the menu for the action
+ */
+ private void initMenu() {
+ // Add listener to repopulate the menu each time
+ // it is shown because of dynamic history list
+ fMenu.addMenuListener(new MenuAdapter() {
+ public void menuShown(MenuEvent e) {
+ //if (recreateMenu) {
+ Menu m = (Menu) e.widget;
+ MenuItem[] items = m.getItems();
+ for (int i = 0; i < items.length; i++) {
+ items[i].dispose();
+ }
+ fillMenu(m);
+ recreateMenu = false;
+ //}
+ }
+ });
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) { }
+
+ public void run(IAction action) { }
+
+ public Menu getMenu(Menu parent) {
+ setMenu(new Menu(parent));
+ //fillMenu(fMenu);
+ initMenu();
+ return fMenu;
+ }
+
+ public Menu getMenu(Control parent) {
+ setMenu(new Menu(parent));
+ //fillMenu(fMenu);
+ initMenu();
+ return fMenu;
+ }
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ */
+package org.eclipse.webbrowser.internal;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.webbrowser.IInternalWebBrowser;
+import org.eclipse.webbrowser.IWebBrowser;
+/**
+ * Action to open the Web browser.
+ */
+public class SwitchDefaultBrowserAction extends Action {
+ protected IWebBrowser webbrowser;
+
+ /**
+ * SwitchDefaultBrowserAction constructor comment.
+ */
+ public SwitchDefaultBrowserAction(IWebBrowser webbrowser, boolean current) {
+ super();
+
+ this.webbrowser = webbrowser;
+ setText(webbrowser.getName());
+ if (webbrowser instanceof IInternalWebBrowser)
+ setImageDescriptor(ImageResource.getImageDescriptor(ImageResource.IMG_INTERNAL_BROWSER));
+ else
+ setImageDescriptor(ImageResource.getImageDescriptor(ImageResource.IMG_EXTERNAL_BROWSER));
+
+ if (current)
+ setChecked(true);
+ }
+
+ /**
+ * Implementation of method defined on <code>IAction</code>.
+ */
+ public void run() {
+ BrowserManager.getInstance().setCurrentWebBrowser(webbrowser);
+ }
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. Â This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ */
+package org.eclipse.webbrowser.internal;
+
+import org.eclipse.swt.SWTError;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.dnd.*;
+import org.eclipse.webbrowser.internal.WebBrowser;
+import org.eclipse.jface.action.Action;
+/**
+ * Text actions (cut, copy, paste) for the Web browser.
+ */
+public class TextAction extends Action {
+ protected WebBrowser browser;
+ protected byte type;
+
+ public static final byte CUT = 0;
+ public static final byte COPY = 1;
+ public static final byte PASTE = 2;
+
+ /**
+ * TextAction constructor comment.
+ */
+ protected TextAction(WebBrowser browser, byte type) {
+ super(type + "!");
+ this.browser = browser;
+ this.type = type;
+ }
+
+ /**
+ * Copies the selected text to the clipboard. The text will be put in the
+ * clipboard in plain text format.
+ * <p>
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+ public void copy() {
+ Point selection = browser.combo.getSelection();
+
+ int length = selection.y - selection.x;
+ if (length > 0) {
+ TextTransfer plainTextTransfer = TextTransfer.getInstance();
+ try {
+ browser.clipboard.setContents(
+ new String[] { browser.combo.getText().substring(selection.x, selection.y) },
+ new Transfer[] { plainTextTransfer });
+ } catch (SWTError error) {
+ // Copy to clipboard failed. This happens when another application
+ // is accessing the clipboard while we copy. Ignore the error.
+ // Fixes 1GDQAVN
+ }
+ }
+ }
+
+ /**
+ * Moves the selected text to the clipboard. The text will be put in the
+ * clipboard in plain text format and RTF format.
+ * <p>
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+ public void cut(){
+ Point selection = browser.combo.getSelection();
+
+ if (selection.y > selection.x) {
+ copy();
+ delete();
+ }
+ }
+
+ /**
+ * Deletes the character to the right of the caret. Delete the selected text if any.
+ */
+ public void delete() {
+ Point selection = browser.combo.getSelection();
+ String text = browser.combo.getText();
+
+ if (selection.x != selection.y) {
+ text = text.substring(0, selection.x) + text.substring(selection.y);
+ browser.combo.setText(text);
+ browser.combo.setSelection(new Point(selection.x, selection.x));
+ }
+ }
+
+ /**
+ * Replaces the selection with the clipboard text or insert the text at
+ * the current caret offset if there is no selection.
+ * If the widget has the SWT.SINGLE style and the clipboard text contains
+ * more than one line, only the first line without line delimiters is
+ * inserted in the widget.
+ * <p>
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+ public void paste() {
+ TextTransfer transfer = TextTransfer.getInstance();
+ Point selection = browser.combo.getSelection();
+ String text = browser.combo.getText();
+
+ String newText = (String) browser.clipboard.getContents(transfer);
+ if (newText != null && newText.length() > 0) {
+ text = text.substring(0, selection.x) + newText + text.substring(selection.y);
+ browser.combo.setText(text);
+
+ // set the selection to the end of the paste
+ int x = selection.x + newText.length();
+ browser.combo.setSelection(new Point(x, x));
+ }
+ }
+
+ /**
+ * Implementation of method defined on <code>IAction</code>.
+ */
+ public void run() {
+ if (browser == null || browser.combo == null)
+ return;
+ if (type == CUT)
+ cut();
+ else if (type == COPY)
+ copy();
+ else if (type == PASTE)
+ paste();
+ }
+
+ /**
+ *
+ */
+ protected void update() { }
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. Â This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ */
+package org.eclipse.webbrowser.internal;
+/**
+ * Helper class to route trace output.
+ */
+public class Trace {
+ public static int CONFIG = 0;
+ public static int WARNING = 2;
+ public static int SEVERE = 3;
+ public static int FINER = 4;
+ public static int FINEST = 5;
+
+ /**
+ * Trace constructor comment.
+ */
+ private Trace() {
+ super();
+ }
+
+ /**
+ * Trace the given text.
+ *
+ * @param s java.lang.String
+ */
+ public static void trace(int level, String s) {
+ Trace.trace(level, s, null);
+ }
+
+ /**
+ * Trace the given message and exception.
+ *
+ * @param s java.lang.String
+ * @param t java.lang.Throwable
+ */
+ public static void trace(int level, String s, Throwable t) {
+ if (!WebBrowserUIPlugin.getInstance().isDebugging())
+ return;
+
+ System.out.println(s);
+ if (t != null)
+ t.printStackTrace();
+ }
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. Â This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ */
+
+//TODO 1. Handle the sizing of a popup running in shelled out secondary window.
+//TODO 2. Support printing: waiting on eclipse bug 47937/44823.
+
+package org.eclipse.webbrowser.internal;
+
+import java.util.*;
+import org.eclipse.webbrowser.IURLMap;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.ui.help.WorkbenchHelp;
+import org.eclipse.swt.browser.*;
+
+public class WebBrowser extends Composite {
+ protected Composite toolbarComp;
+ protected Composite statusComp;
+ protected Combo combo;
+ protected Clipboard clipboard;
+ protected boolean showToolbar;
+ protected ToolItem back;
+ protected ToolItem forward;
+ protected ToolItem stop;
+ protected ToolItem favorites;
+ protected ToolItem refresh;
+ protected BusyIndicator busy;
+ protected boolean showStatusbar;
+ protected ProgressBar progress;
+ protected Label status;
+ private static int MAX_HISTORY = 50;
+ protected static java.util.List history;
+ protected Browser browser;
+ protected Shell shell;
+ protected WebBrowserEditor editor;
+ protected String title;
+
+ public WebBrowser(Composite parent, final boolean showToolbar, final boolean showStatusbar) {
+ super(parent, SWT.NONE);
+
+ this.showToolbar = showToolbar;
+ this.showStatusbar = showStatusbar;
+
+ GridLayout layout = new GridLayout();
+ layout.marginHeight = 3;
+ layout.marginWidth = 3;
+ layout.horizontalSpacing = 3;
+ layout.verticalSpacing = 3;
+ layout.numColumns = 1;
+ setLayout(layout);
+ setLayoutData(new GridData(GridData.FILL_BOTH));
+ clipboard = new Clipboard(parent.getDisplay());
+ WorkbenchHelp.setHelp(this, ContextIds.WEB_BROWSER);
+
+ if (showToolbar) {
+ toolbarComp = new Composite(this, SWT.NONE);
+ GridLayout outerLayout = new GridLayout();
+ outerLayout.numColumns = 2;
+ outerLayout.marginWidth = 0;
+ outerLayout.marginHeight = 0;
+ toolbarComp.setLayout(outerLayout);
+ toolbarComp.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL));
+
+ // create the top line, with a combo box for history and a "go" button
+ Composite top = new Composite(toolbarComp, SWT.NONE);
+ GridLayout topLayout = new GridLayout();
+ topLayout.numColumns = 2;
+ topLayout.marginWidth = 0;
+ topLayout.marginHeight = 0;
+ top.setLayout(topLayout);
+ top.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER | GridData.FILL_HORIZONTAL));
+
+ combo = new Combo(top, SWT.DROP_DOWN);
+
+ updateHistory();
+
+ combo.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent we) {
+ try {
+ if (combo.getSelectionIndex() != -1)
+ setURL(combo.getItem(combo.getSelectionIndex()));
+ } catch (Exception e) { }
+ }
+ });
+ combo.addListener(SWT.DefaultSelection, new Listener() {
+ public void handleEvent(Event e) {
+ setURL(combo.getText());
+ }
+ });
+ combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ WorkbenchHelp.setHelp(combo, ContextIds.WEB_BROWSER_URL);
+
+ ToolBar toolbar = new ToolBar(top, SWT.FLAT);
+ fillToolBar(toolbar);
+
+ new ToolItem(toolbar, SWT.SEPARATOR);
+
+ busy = new BusyIndicator(toolbarComp, SWT.NONE);
+ busy.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
+ }
+
+ // create a new SWT Web browser widget, checking once again to make sure we can use it in this environment
+ if (WebBrowserUtil.canUseInternalWebBrowser() & WebBrowserUtil.isInternalBrowserOperational())
+ this.browser = new Browser(this, SWT.NONE);
+ else {
+ WebBrowserUtil.openError(WebBrowserUIPlugin.getResource("%errorCouldNotLaunchInternalWebBrowser"));
+ return;
+ }
+
+ if (showToolbar) {
+ back.setEnabled(browser.isBackEnabled());
+ forward.setEnabled(browser.isForwardEnabled());
+ }
+
+ WorkbenchHelp.setHelp(browser, ContextIds.WEB_BROWSER_WEB);
+ GridData data = new GridData();
+ data.horizontalAlignment = GridData.FILL;
+ data.verticalAlignment = GridData.FILL;
+ data.horizontalSpan = 3;
+ data.grabExcessHorizontalSpace = true;
+ data.grabExcessVerticalSpace = true;
+ browser.setLayoutData(data);
+
+ if (showStatusbar)
+ createStatusArea(this);
+
+ addBrowserListeners();
+ }
+ /**
+ *
+ */
+ protected void addBrowserListeners() {
+ if (showStatusbar) {
+ // respond to Browser StatusTextEvents events by updating the status Text label
+ browser.addStatusTextListener(new StatusTextListener() {
+ public void changed(StatusTextEvent event) {
+ status.setText(event.text);
+ }
+ });
+ }
+
+ /** Add listener for new window creation so that we can instead of opening a separate
+ * new window in which the session is lost, we can instead open a new window in a new
+ * shell within the browser area thereby maintaining the session.
+ */
+ browser.addOpenWindowListener(new OpenWindowListener() {
+ public void open(WindowEvent event) {
+ Shell shell2 = new Shell(getDisplay());
+ shell2.setLayout(new FillLayout());
+ shell2.setText(WebBrowserUIPlugin.getResource("%viewWebBrowserTitle"));
+ shell2.setImage(getShell().getImage());
+ WebBrowser browser2 = new WebBrowser(shell2, showToolbar, showStatusbar);
+ browser2.shell = shell2;
+ event.browser = browser2.browser;
+ shell2.open();
+ }
+ });
+
+ browser.addCloseWindowListener(new CloseWindowListener(){
+ public void close(WindowEvent event) {
+ // if shell is not null, it must be a secondary popup window, else its an editor window
+ if (shell != null)
+ shell.dispose();
+ else
+ editor.closeEditor();
+ }
+ });
+
+ browser.addProgressListener(new ProgressListener() {
+ public void changed(ProgressEvent event) {
+ if (event.total == 0)
+ return;
+
+ boolean done = (event.current == event.total);
+
+ int percentProgress = event.current * 100 / event.total;
+ if (showStatusbar) {
+ if (done)
+ progress.setSelection(0);
+ else
+ progress.setSelection(percentProgress);
+ }
+
+ if (showToolbar) {
+ if (!busy.isBusy() && (percentProgress > 0 && percentProgress < 100)) {
+ busy.setBusy(true);
+ }
+ // Once the progress hits 100 percent, done, set busy to false
+ else if (busy.isBusy() && done) {
+ busy.setBusy(false);
+ }
+ }
+ }
+
+ public void completed(ProgressEvent event) {
+ if (showStatusbar)
+ progress.setSelection(0);
+ if (showToolbar) {
+ busy.setBusy(false);
+ back.setEnabled(browser.isBackEnabled());
+ forward.setEnabled(browser.isForwardEnabled());
+ }
+ }
+ });
+
+ if (showToolbar) {
+ browser.addLocationListener(new LocationListener() {
+ public void changed(LocationEvent event) {
+ if (!event.top)
+ return;
+ if (!isHome()) {
+ combo.setText(event.location);
+ addToHistory(event.location);
+ updateHistory();
+ } else
+ combo.setText("");
+ }
+
+ public void changing(LocationEvent event) { }
+ });
+ }
+
+ browser.addTitleListener(new TitleListener() {
+ public void changed(TitleEvent event) {
+ title = event.title;
+ }
+ });
+ }
+
+ /**
+ * Return the underlying browser control.
+ *
+ * @return org.eclipse.swt.browser.Browser
+ */
+ public Browser getBrowser() {
+ return browser;
+ }
+
+ /**
+ *
+ */
+ protected void forward() {
+ browser.forward();
+ }
+
+ /**
+ *
+ */
+ protected void back() {
+ browser.back();
+ }
+
+ /**
+ *
+ */
+ protected void stop() {
+ browser.stop();
+ }
+
+ /**
+ *
+ */
+ protected void navigate(String url) {
+ Trace.trace(Trace.FINER, "Navigate: " + url);
+ if (url != null && url.equals(getURL())) {
+ refresh();
+ return;
+ }
+ browser.setUrl(url);
+ }
+
+ /**
+ * Refresh the currently viewed page.
+ */
+ public void refresh() {
+ browser.refresh();
+ }
+
+ protected void setURL(String url, boolean browse) {
+ Trace.trace(Trace.FINEST, "setURL: " + url + " " + browse);
+ if (url == null) {
+ home();
+ return;
+ }
+
+ if (url.endsWith(WebBrowserPreference.getHomePageURL().substring(9)))
+ return;
+
+ // check URL maps
+ Iterator iterator = WebBrowserUtil.getURLMaps().iterator();
+ String newURL = null;
+ while (iterator.hasNext() && newURL == null) {
+ try {
+ IURLMap map = (IURLMap) iterator.next();
+ newURL = map.getMappedURL(url);
+ } catch (Exception e) { }
+ }
+ if (newURL != null)
+ url = newURL;
+
+ if (browse)
+ navigate(url);
+
+ addToHistory(url);
+ updateHistory();
+ }
+
+ protected void addToHistory(String url) {
+ if (history == null)
+ history = WebBrowserPreference.getInternalWebBrowserHistory();
+ int found = -1;
+ int size = history.size();
+ for (int i = 0; i < size; i++){
+ String s = (String) history.get(i);
+ if (s.equals(url)) {
+ found = i;
+ break;
+ }
+ }
+
+ if (found == -1) {
+ if (size >= MAX_HISTORY)
+ history.remove(size - 1);
+ history.add(0, url);
+ WebBrowserPreference.setInternalWebBrowserHistory(history);
+ } else if (found != 0) {
+ history.remove(found);
+ history.add(0, url);
+ WebBrowserPreference.setInternalWebBrowserHistory(history);
+ }
+ }
+
+ public void setURL(String url) {
+ setURL(url, true);
+ }
+
+ /**
+ * Creates the Web browser status area.
+ */
+ private void createStatusArea(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ layout.horizontalSpacing = 4;
+ layout.verticalSpacing = 0;
+ composite.setLayout(layout);
+ composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ // Add a label for displaying status messages as they are received from the control
+ status = new Label(composite, SWT.SINGLE | SWT.READ_ONLY);
+ GridData gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
+ gridData.horizontalIndent = 2;
+ status.setLayoutData(gridData);
+
+ // Add a progress bar to display downloading progress information
+ progress = new ProgressBar(composite, SWT.BORDER);
+ gridData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_FILL);
+ gridData.widthHint = 100;
+ gridData.heightHint = 10;
+ progress.setLayoutData(gridData);
+ }
+
+ /**
+ *
+ */
+ public void dispose() {
+ super.dispose();
+
+ showStatusbar = false;
+ showToolbar = false;
+
+ if (busy != null)
+ busy.dispose();
+ busy = null;
+
+ browser = null;
+ }
+
+ /**
+ * Populate the toolbar.
+ * @param toolbar org.eclipse.swt.widgets.ToolBar
+ */
+ private void fillToolBar(final ToolBar toolbar) {
+ ToolItem go = new ToolItem(toolbar, SWT.NONE);
+ go.setImage(ImageResource.getImage(ImageResource.IMG_ELCL_NAV_GO));
+ go.setHotImage(ImageResource.getImage(ImageResource.IMG_CLCL_NAV_GO));
+ go.setDisabledImage(ImageResource.getImage(ImageResource.IMG_DLCL_NAV_GO));
+ go.setToolTipText(WebBrowserUIPlugin.getResource("%actionWebBrowserGo"));
+ go.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ setURL(combo.getText());
+ }
+ });
+
+ new ToolItem(toolbar, SWT.SEPARATOR);
+
+ favorites = new ToolItem(toolbar, SWT.DROP_DOWN);
+ favorites.setImage(ImageResource.getImage(ImageResource.IMG_ELCL_NAV_FAVORITES));
+ favorites.setHotImage(ImageResource.getImage(ImageResource.IMG_CLCL_NAV_FAVORITES));
+ favorites.setDisabledImage(ImageResource.getImage(ImageResource.IMG_DLCL_NAV_FAVORITES));
+ favorites.setToolTipText(WebBrowserUIPlugin.getResource("%actionWebBrowserFavorites"));
+
+ favorites.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ if (event.detail == SWT.ARROW) {
+ Rectangle r = favorites.getBounds();
+ showFavorites(toolbar, toolbar.toDisplay(r.x, r.y + r.height));
+ } else
+ addFavorite();
+ }
+ });
+
+ // create back and forward actions
+ back = new ToolItem(toolbar, SWT.NONE);
+ back.setImage(ImageResource.getImage(ImageResource.IMG_ELCL_NAV_BACKWARD));
+ back.setHotImage(ImageResource.getImage(ImageResource.IMG_CLCL_NAV_BACKWARD));
+ back.setDisabledImage(ImageResource.getImage(ImageResource.IMG_DLCL_NAV_BACKWARD));
+ back.setToolTipText(WebBrowserUIPlugin.getResource("%actionWebBrowserBack"));
+ back.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ back();
+ }
+ });
+
+ forward = new ToolItem(toolbar, SWT.NONE);
+ forward.setImage(ImageResource.getImage(ImageResource.IMG_ELCL_NAV_FORWARD));
+ forward.setHotImage(ImageResource.getImage(ImageResource.IMG_CLCL_NAV_FORWARD));
+ forward.setDisabledImage(ImageResource.getImage(ImageResource.IMG_DLCL_NAV_FORWARD));
+ forward.setToolTipText(WebBrowserUIPlugin.getResource("%actionWebBrowserForward"));
+ forward.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ forward();
+ }
+ });
+
+ // create refresh, stop, and print actions
+ stop = new ToolItem(toolbar, SWT.NONE);
+ stop.setImage(ImageResource.getImage(ImageResource.IMG_ELCL_NAV_STOP));
+ stop.setHotImage(ImageResource.getImage(ImageResource.IMG_CLCL_NAV_STOP));
+ stop.setDisabledImage(ImageResource.getImage(ImageResource.IMG_DLCL_NAV_STOP));
+ stop.setToolTipText(WebBrowserUIPlugin.getResource("%actionWebBrowserStop"));
+ stop.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ stop();
+ }
+ });
+
+ refresh = new ToolItem(toolbar, SWT.NONE);
+ refresh.setImage(ImageResource.getImage(ImageResource.IMG_ELCL_NAV_REFRESH));
+ refresh.setHotImage(ImageResource.getImage(ImageResource.IMG_CLCL_NAV_REFRESH));
+ refresh.setDisabledImage(ImageResource.getImage(ImageResource.IMG_DLCL_NAV_REFRESH));
+ refresh.setToolTipText(WebBrowserUIPlugin.getResource("%actionWebBrowserRefresh"));
+ refresh.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ refresh();
+ }
+ });
+ }
+
+ protected void addFavorite() {
+ java.util.List list = WebBrowserPreference.getInternalWebBrowserFavorites();
+ Favorite f = new Favorite(title, browser.getUrl());
+ if (!list.contains(f)) {
+ list.add(f);
+ WebBrowserPreference.setInternalWebBrowserFavorites(list);
+ }
+ }
+
+ protected void showFavorites(Control parent, Point p) {
+ Menu perspectiveBarMenu = null;
+ if (perspectiveBarMenu == null) {
+ Menu menu = new Menu(parent);
+
+ // locked favorites
+ Iterator iterator = WebBrowserUtil.getLockedFavorites().iterator();
+ if (iterator.hasNext()) {
+ while (iterator.hasNext()) {
+ final Favorite f = (Favorite) iterator.next();
+ MenuItem item = new MenuItem(menu, SWT.NONE);
+ item.setText(f.getName());
+ item.setImage(ImageResource.getImage(ImageResource.IMG_FAVORITE));
+ item.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ setURL(f.getURL());
+ }
+ });
+ }
+
+ new MenuItem(menu, SWT.SEPARATOR);
+ }
+
+ iterator = WebBrowserPreference.getInternalWebBrowserFavorites().iterator();
+ if (!iterator.hasNext()) {
+ MenuItem item = new MenuItem(menu, SWT.NONE);
+ item.setText(WebBrowserUIPlugin.getResource("%actionWebBrowserNoFavorites"));
+ }
+ while (iterator.hasNext()) {
+ final Favorite f = (Favorite) iterator.next();
+ MenuItem item = new MenuItem(menu, SWT.NONE);
+ item.setText(f.getName());
+ item.setImage(ImageResource.getImage(ImageResource.IMG_FAVORITE));
+ item.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ setURL(f.getURL());
+ }
+ });
+ }
+
+ new MenuItem(menu, SWT.SEPARATOR);
+
+ MenuItem item = new MenuItem(menu, SWT.NONE);
+ item.setText(WebBrowserUIPlugin.getResource("%actionWebBrowserOrganizeFavorites"));
+ item.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ OrganizeFavoritesDialog dialog = new OrganizeFavoritesDialog(shell);
+ dialog.open();
+ }
+ });
+
+ perspectiveBarMenu = menu;
+ }
+
+ if (perspectiveBarMenu != null) {
+ perspectiveBarMenu.setLocation(p.x, p.y);
+ perspectiveBarMenu.setVisible(true);
+ }
+ }
+
+ public void home() {
+ navigate(WebBrowserPreference.getHomePageURL());
+ }
+
+ /**
+ * Returns true if the homepage is currently being displayed.
+ * @return boolean
+ */
+ protected boolean isHome() {
+ return getURL() != null && getURL().endsWith(WebBrowserPreference.getHomePageURL().substring(9));
+ }
+
+ protected String getURL() {
+ return browser.getUrl();
+ }
+
+ /**
+ * Update the history list to the global copy.
+ */
+ protected void updateHistory() {
+ if (combo == null)
+ return;
+
+ String temp = combo.getText();
+ if (history == null)
+ history = WebBrowserPreference.getInternalWebBrowserHistory();
+
+ String[] historyList = new String[history.size()];
+ history.toArray(historyList);
+ combo.setItems(historyList);
+
+ combo.setText(temp);
+ }
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. Â This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ */
+package org.eclipse.webbrowser.internal;
+
+import java.net.URL;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.core.runtime.*;
+import org.eclipse.core.resources.*;
+import org.eclipse.ui.*;
+import org.eclipse.ui.part.*;
+import org.eclipse.webbrowser.*;
+/**
+ * An integrated Web browser, defined as an editor to make
+ * better use of the desktop.
+ */
+public class WebBrowserEditor extends EditorPart {
+ public static final String WEB_BROWSER_EDITOR_ID = "org.eclipse.webbrowser";
+ protected WebBrowser webBrowser;
+ protected String initialURL;
+ protected Image image;
+
+ protected TextAction cutAction;
+ protected TextAction copyAction;
+ protected TextAction pasteAction;
+
+ protected IResourceChangeListener resourceListener;
+
+ /**
+ * WebBrowserEditor constructor comment.
+ */
+ public WebBrowserEditor() {
+ super();
+ }
+
+ /**
+ * Creates the SWT controls for this workbench part.
+ * <p>
+ * Clients should not call this method (the workbench calls this method at
+ * appropriate times).
+ * </p>
+ * <p>
+ * For implementors this is a multi-step process:
+ * <ol>
+ * <li>Create one or more controls within the parent.</li>
+ * <li>Set the parent layout as needed.</li>
+ * <li>Register any global actions with the <code>IActionService</code>.</li>
+ * <li>Register any popup menus with the <code>IActionService</code>.</li>
+ * <li>Register a selection provider with the <code>ISelectionService</code>
+ * (optional). </li>
+ * </ol>
+ * </p>
+ *
+ * @param parent the parent control
+ */
+ public void createPartControl(Composite parent) {
+ IWebBrowserEditorInput input = getWebBrowserEditorInput();
+
+
+ if (input == null || input.isToolbarVisible() == false)
+ webBrowser = new WebBrowser(parent, false, input.isStatusbarVisible());
+ else {
+ webBrowser = new WebBrowser(parent, true, input.isStatusbarVisible());
+ cutAction = new TextAction(webBrowser, TextAction.CUT);
+ copyAction = new TextAction(webBrowser, TextAction.COPY);
+ pasteAction = new TextAction(webBrowser, TextAction.PASTE);
+ }
+
+ webBrowser.setURL(initialURL);
+ webBrowser.editor = this;
+ }
+
+ public void dispose() {
+ if (image != null && !image.isDisposed())
+ image.dispose();
+ image = null;
+
+ if (resourceListener != null)
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener(resourceListener);
+ }
+
+ /* (non-Javadoc)
+ * Saves the contents of this editor.
+ * <p>
+ * Subclasses must override this method to implement the open-save-close lifecycle
+ * for an editor. For greater details, see <code>IEditorPart</code>
+ * </p>
+ *
+ * @see IEditorPart
+ */
+ public void doSave(IProgressMonitor monitor) { }
+
+ /* (non-Javadoc)
+ * Saves the contents of this editor to another object.
+ * <p>
+ * Subclasses must override this method to implement the open-save-close lifecycle
+ * for an editor. For greater details, see <code>IEditorPart</code>
+ * </p>
+ *
+ * @see IEditorPart
+ */
+ public void doSaveAs() { }
+
+ /**
+ * Returns the copy action.
+ *
+ * @return org.eclipse.jface.action.IAction
+ */
+ public IAction getCopyAction() {
+ return copyAction;
+ }
+
+ /**
+ * Returns the cut action.
+ *
+ * @return org.eclipse.jface.action.IAction
+ */
+ public IAction getCutAction() {
+ return cutAction;
+ }
+
+ /**
+ * Returns the paste action.
+ *
+ * @return org.eclipse.jface.action.IAction
+ */
+ public IAction getPasteAction() {
+ return pasteAction;
+ }
+
+ /**
+ * Returns the web editor input, if available.
+ *
+ * @return org.eclipse.webbrowser.IWebBrowserEditorInput
+ */
+ protected IWebBrowserEditorInput getWebBrowserEditorInput() {
+ IEditorInput input = getEditorInput();
+ if (input instanceof IWebBrowserEditorInput)
+ return (IWebBrowserEditorInput) input;
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * Sets the cursor and selection state for this editor to the passage defined
+ * by the given marker.
+ * <p>
+ * Subclasses may override. For greater details, see <code>IEditorPart</code>
+ * </p>
+ *
+ * @see IEditorPart
+ */
+ public void gotoMarker(IMarker marker) { }
+
+ /* (non-Javadoc)
+ * Initializes the editor part with a site and input.
+ * <p>
+ * Subclasses of <code>EditorPart</code> must implement this method. Within
+ * the implementation subclasses should verify that the input type is acceptable
+ * and then save the site and input. Here is sample code:
+ * </p>
+ * <pre>
+ * if (!(input instanceof IFileEditorInput))
+ * throw new PartInitException("Invalid Input: Must be IFileEditorInput");
+ * setSite(site);
+ * setInput(editorInput);
+ * </pre>
+ */
+ public void init(IEditorSite site, IEditorInput input) {
+ Trace.trace(Trace.FINEST, "Opening browser: " + input);
+ if (input instanceof IFileEditorInput) {
+ IFileEditorInput fei = (IFileEditorInput) input;
+ IFile file = fei.getFile();
+ URL url = null;
+ try {
+ if (file != null && file.exists())
+ url = file.getLocation().toFile().toURL();
+ } catch (Exception e) {
+ Trace.trace(Trace.SEVERE, "Error getting URL to file");
+ }
+ addResourceListener(file);
+ input = new WebBrowserEditorInput(url, WebBrowserEditorInput.SHOW_ALL | WebBrowserEditorInput.SAVE_URL);
+ }
+ if (input instanceof IWebBrowserEditorInput) {
+ IWebBrowserEditorInput wbei = (IWebBrowserEditorInput) input;
+ initialURL = null;
+ if (wbei.getURL() != null)
+ initialURL = wbei.getURL().toExternalForm();
+ if (webBrowser != null) {
+ webBrowser.setURL(initialURL);
+ site.getWorkbenchWindow().getActivePage().bringToTop(this);
+ }
+
+ setPartName(wbei.getName());
+ setTitleToolTip(wbei.getToolTipText());
+
+ Image oldImage = image;
+ ImageDescriptor id = wbei.getImageDescriptor();
+ image = id.createImage();
+
+ setTitleImage(image);
+ if (oldImage != null && !oldImage.isDisposed())
+ oldImage.dispose();
+ }
+ setSite(site);
+ setInput(input);
+ }
+
+ /* (non-Javadoc)
+ * Returns whether the contents of this editor have changed since the last save
+ * operation.
+ * <p>
+ * Subclasses must override this method to implement the open-save-close lifecycle
+ * for an editor. For greater details, see <code>IEditorPart</code>
+ * </p>
+ *
+ * @see IEditorPart
+ */
+ public boolean isDirty() {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * Returns whether the "save as" operation is supported by this editor.
+ * <p>
+ * Subclasses must override this method to implement the open-save-close lifecycle
+ * for an editor. For greater details, see <code>IEditorPart</code>
+ * </p>
+ *
+ * @see IEditorPart
+ */
+ public boolean isSaveAsAllowed() {
+ return false;
+ }
+
+ /**
+ * Returns true if this editor has a toolbar.
+ *
+ * @return boolean
+ */
+ public boolean isToolbarVisible() {
+ IWebBrowserEditorInput input = getWebBrowserEditorInput();
+ if (input == null || input.isToolbarVisible())
+ return true;
+ else
+ return false;
+ }
+
+ /**
+ * Open the input in the internal Web browser.
+ */
+ public static void open(IWebBrowserEditorInput input) {
+ IWorkbenchWindow workbenchWindow = WebBrowserUIPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow();
+ IWorkbenchPage page = workbenchWindow.getActivePage();
+
+ try {
+ IEditorReference[] editors = page.getEditorReferences();
+ int size = editors.length;
+ for (int i = 0; i < size; i++) {
+ if (WEB_BROWSER_EDITOR_ID.equals(editors[i].getId())) {
+ IEditorPart editor = editors[i].getEditor(true);
+ if (editor != null && editor instanceof WebBrowserEditor) {
+ WebBrowserEditor webEditor = (WebBrowserEditor) editor;
+ if (input.canReplaceInput(webEditor.getWebBrowserEditorInput())) {
+ editor.init(editor.getEditorSite(), input);
+ return;
+ }
+ }
+ }
+ }
+
+ page.openEditor(input, WebBrowserEditor.WEB_BROWSER_EDITOR_ID);
+ } catch (Exception e) {
+ Trace.trace(Trace.SEVERE, "Error opening Web browser", e);
+ }
+ }
+
+ /**
+ * Asks this part to take focus within the workbench.
+ * <p>
+ * Clients should not call this method (the workbench calls this method at
+ * appropriate times).
+ * </p>
+ */
+ public void setFocus() {
+ if (webBrowser != null) {
+ if (webBrowser.combo != null)
+ webBrowser.combo.setFocus();
+ else
+ webBrowser.browser.setFocus();
+ webBrowser.updateHistory();
+ }
+ }
+
+ /**
+ * Update the actions.
+ */
+ protected void updateActions() {
+ if (cutAction != null)
+ cutAction.update();
+ if (copyAction != null)
+ copyAction.update();
+ if (pasteAction != null)
+ pasteAction.update();
+ }
+
+ /**
+ * Close the editor correctly.
+ */
+ protected void closeEditor() {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ getEditorSite().getPage().closeEditor(WebBrowserEditor.this, false);
+ }
+ });
+ }
+
+ /**
+ * Adds a resource change listener to see if the file is deleted.
+ */
+ protected void addResourceListener(final IResource resource) {
+ if (resource == null)
+ return;
+
+ resourceListener = new IResourceChangeListener() {
+ public void resourceChanged(IResourceChangeEvent event) {
+ try {
+ event.getDelta().accept(new IResourceDeltaVisitor() {
+ public boolean visit(IResourceDelta delta) {
+ IResource res = delta.getResource();
+
+ if (res == null || !res.equals(resource))
+ return true;
+
+ if (delta.getKind() != IResourceDelta.REMOVED)
+ return true;
+
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ String title = WebBrowserUIPlugin.getResource("%dialogResourceDeletedTitle");
+ String message = WebBrowserUIPlugin.getResource("%dialogResourceDeletedMessage", resource.getName());
+ String[] labels = new String[] {WebBrowserUIPlugin.getResource("%dialogResourceDeletedIgnore"), IDialogConstants.CLOSE_LABEL};
+ MessageDialog dialog = new MessageDialog(getEditorSite().getShell(), title, null, message, MessageDialog.INFORMATION, labels, 0);
+
+ if (dialog.open() != 0)
+ closeEditor();
+ }
+ });
+ return false;
+ }
+ });
+ } catch (Exception e) {
+ Trace.trace(Trace.SEVERE, "Error listening for resource deletion", e);
+ }
+ }
+ };
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceListener);
+ }
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. Â This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ */
+package org.eclipse.webbrowser.internal;
+
+import org.eclipse.ui.*;
+import org.eclipse.ui.actions.ActionFactory;
+/**
+ * ActionBarContributor for the Web browser.
+ * Just adds cut, copy, paste actions.
+ */
+public class WebBrowserEditorActionBarContributor implements IEditorActionBarContributor {
+ protected IActionBars actionBars;
+
+ /**
+ * WebBrowserEditorActionBarContributor constructor comment.
+ */
+ public WebBrowserEditorActionBarContributor() {
+ super();
+ }
+
+ /**
+ * Initializes this contributor, which is expected to add contributions as
+ * required to the given action bars and global action handlers.
+ *
+ * @param bars the action bars
+ */
+ public void init(IActionBars bars, IWorkbenchPage page) {
+ this.actionBars = bars;
+ }
+
+ /**
+ * Sets the active editor for the contributor.
+ * Implementors should disconnect from the old editor, connect to the
+ * new editor, and update the actions to reflect the new editor.
+ *
+ * @param targetEditor the new editor target
+ */
+ public void setActiveEditor(IEditorPart targetEditor) {
+ if (targetEditor instanceof WebBrowserEditor) {
+ WebBrowserEditor editor = (WebBrowserEditor) targetEditor;
+
+ actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), editor.getCopyAction());
+ actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(), editor.getCutAction());
+ actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), editor.getPasteAction());
+
+ editor.updateActions();
+ }
+ }
+
+ /**
+ * Disposes this contributor.
+ */
+ public void dispose() { }
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. Â This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ */
+package org.eclipse.webbrowser.internal;
+
+import java.util.*;
+import java.net.URL;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.preference.IPreferenceStore;
+/**
+ * Preferences for the Web browser.
+ */
+public class WebBrowserPreference {
+ protected static final String PREF_BROWSER_HISTORY = "webBrowserHistory";
+ protected static final String PREF_INTERNAL_WEB_BROWSER_HISTORY = "internalWebBrowserHistory";
+ protected static final String PREF_INTERNAL_WEB_BROWSER_FAVORITES = "internalWebBrowserFavorites";
+ protected static final String PREF_INTERNAL_WEB_BROWSER_OLD_FAVORITES = "internalWebBrowserOldFavorites";
+ protected static final String URL_PARAMETER = "%URL%";
+
+ /**
+ * WebBrowserPreference constructor comment.
+ */
+ private WebBrowserPreference() {
+ super();
+ }
+
+ /**
+ * Returns the URL to the homepage.
+ *
+ * @return java.lang.String
+ */
+ public static String getHomePageURL() {
+ try {
+ // get the default home page
+ URL url = WebBrowserUIPlugin.getInstance().getBundle().getEntry("home/home.html");
+ url = Platform.resolve(url);
+ return url.toExternalForm();
+ } catch (Exception e) {
+ return "http://www.eclipse.org";
+ }
+ }
+
+ /**
+ * Returns the preference store.
+ *
+ * @return org.eclipse.jface.preference.IPreferenceStore
+ */
+ protected static IPreferenceStore getPreferenceStore() {
+ return WebBrowserUIPlugin.getInstance().getPreferenceStore();
+ }
+
+ /**
+ * Returns the Web browser history list.
+ *
+ * @return java.util.List
+ */
+ public static List getInternalWebBrowserHistory() {
+ String temp = getPreferenceStore().getString(PREF_INTERNAL_WEB_BROWSER_HISTORY);
+ StringTokenizer st = new StringTokenizer(temp, "|*|");
+ List l = new ArrayList();
+ while (st.hasMoreTokens()) {
+ String s = st.nextToken();
+ l.add(s);
+ }
+ return l;
+ }
+
+ /**
+ * Returns the Web browser favorites.
+ *
+ * @return java.util.List
+ */
+ public static List getInternalWebBrowserFavorites() {
+ String temp = getPreferenceStore().getString(PREF_INTERNAL_WEB_BROWSER_FAVORITES);
+ StringTokenizer st = new StringTokenizer(temp, "|*|");
+ List l = new ArrayList();
+ while (st.hasMoreTokens()) {
+ l.add(new Favorite(st.nextToken(), st.nextToken()));
+ }
+ return l;
+ }
+
+ /**
+ * Initialize the default preferences.
+ */
+ public static void initializeDefaultPreferences() {
+ IPreferenceStore store = getPreferenceStore();
+
+ String temp = store.getString(PREF_INTERNAL_WEB_BROWSER_OLD_FAVORITES);
+ StringTokenizer st = new StringTokenizer(temp, "|*|");
+ List def = new ArrayList();
+ while (st.hasMoreTokens()) {
+ def.add(new Favorite(st.nextToken(), st.nextToken()));
+ }
+
+ List list = getInternalWebBrowserFavorites();
+ Iterator iterator = WebBrowserUtil.getUnlockedFavorites().iterator();
+ while (iterator.hasNext()) {
+ Favorite f = (Favorite) iterator.next();
+ if (!def.contains(f))
+ list.add(f);
+ }
+ setInternalWebBrowserFavorites(list);
+
+ StringBuffer sb = new StringBuffer();
+ iterator = WebBrowserUtil.getUnlockedFavorites().iterator();
+ while (iterator.hasNext()) {
+ Favorite f = (Favorite) iterator.next();
+ sb.append(f.getName());
+ sb.append("|*|");
+ sb.append(f.getURL());
+ sb.append("|*|");
+ }
+ store.setValue(PREF_INTERNAL_WEB_BROWSER_OLD_FAVORITES, sb.toString());
+ WebBrowserUIPlugin.getInstance().savePluginPreferences();
+ }
+
+ /**
+ * Sets the Web browser history.
+ *
+ * @param java.util.List
+ */
+ public static void setInternalWebBrowserHistory(List list) {
+ StringBuffer sb = new StringBuffer();
+ if (list != null) {
+ Iterator iterator = list.iterator();
+ while (iterator.hasNext()) {
+ String s = (String) iterator.next();
+ sb.append(s);
+ sb.append("|*|");
+ }
+ }
+ getPreferenceStore().setValue(PREF_INTERNAL_WEB_BROWSER_HISTORY, sb.toString());
+ WebBrowserUIPlugin.getInstance().savePluginPreferences();
+ }
+
+ /**
+ * Sets the Web browser favorites.
+ *
+ * @param java.util.List
+ */
+ public static void setInternalWebBrowserFavorites(List list) {
+ StringBuffer sb = new StringBuffer();
+ if (list != null) {
+ Iterator iterator = list.iterator();
+ while (iterator.hasNext()) {
+ Favorite f = (Favorite) iterator.next();
+ sb.append(f.getName());
+ sb.append("|*|");
+ sb.append(f.getURL());
+ sb.append("|*|");
+ }
+ }
+ getPreferenceStore().setValue(PREF_INTERNAL_WEB_BROWSER_FAVORITES, sb.toString());
+ WebBrowserUIPlugin.getInstance().savePluginPreferences();
+ }
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. Â This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ */
+package org.eclipse.webbrowser.internal;
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.help.WorkbenchHelp;
+/**
+ * The preference page that holds webbrowser preferences.
+ */
+public class WebBrowserPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
+ /**
+ * WebBrowserPreferencePage constructor comment.
+ */
+ public WebBrowserPreferencePage() {
+ super();
+ noDefaultAndApplyButton();
+ }
+
+ /**
+ * Create the preference options.
+ *
+ * @param parent org.eclipse.swt.widgets.Composite
+ * @return org.eclipse.swt.widgets.Control
+ */
+ protected Control createContents(Composite parent) {
+ initializeDialogUnits(parent);
+
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 1;
+ layout.horizontalSpacing = convertHorizontalDLUsToPixels(4);
+ layout.verticalSpacing = convertVerticalDLUsToPixels(4);
+ layout.marginWidth = 0;
+ layout.marginHeight = 0;
+ composite.setLayout(layout);
+ GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
+ composite.setLayoutData(data);
+ WorkbenchHelp.setHelp(composite, ContextIds.PREF_BROWSER);
+
+ Label label = new Label(composite, SWT.WRAP);
+ label.setText(WebBrowserUIPlugin.getResource("%preferenceWebBrowserDescription"));
+ data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
+ label.setLayoutData(data);
+
+ BrowserTableComposite browserComposite = new BrowserTableComposite(composite, SWT.NONE);
+
+ data = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
+ browserComposite.setLayoutData(data);
+
+ Dialog.applyDialogFont(composite);
+
+ return composite;
+ }
+
+ /**
+ * Initializes this preference page using the passed desktop.
+ *
+ * @param desktop the current desktop
+ */
+ public void init(IWorkbench workbench) { }
+
+ /**
+ *
+ */
+ public void setVisible(boolean visible) {
+ super.setVisible(visible);
+ if (visible)
+ setTitle(WebBrowserUIPlugin.getResource("%preferenceWebBrowserTitleLong"));
+ }
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. Â This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ */
+package org.eclipse.webbrowser.internal;
+
+import java.text.MessageFormat;
+
+import org.eclipse.core.runtime.*;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+/**
+ * The main web browser plugin class.
+ */
+public class WebBrowserUIPlugin extends AbstractUIPlugin {
+ // Web browser plugin id
+ public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.webbrowser";
+
+ // singleton instance of this class
+ private static WebBrowserUIPlugin singleton;
+
+ /**
+ * Create the WebBrowserUIPlugin
+ */
+ public WebBrowserUIPlugin() {
+ super();
+ singleton = this;
+ }
+
+ /**
+ * Returns the singleton instance of this plugin.
+ *
+ * @return org.eclipse.webbrowser.WebBrowserPlugin
+ */
+ public static WebBrowserUIPlugin getInstance() {
+ return singleton;
+ }
+
+ /**
+ * Returns the translated String found with the given key.
+ *
+ * @param key java.lang.String
+ * @return java.lang.String
+ */
+ public static String getResource(String key) {
+ try {
+ return Platform.getResourceString(getInstance().getBundle(), key);
+ } catch (Exception e) {
+ return key;
+ }
+ }
+
+ /**
+ * Returns the translated String found with the given key,
+ * and formatted with the given arguments using java.text.MessageFormat.
+ *
+ * @param key java.lang.String
+ * @param arg java.lang.String
+ * @return java.lang.String
+ */
+ public static String getResource(String key, String arg) {
+ try {
+ String text = getResource(key);
+ return MessageFormat.format(text, new String[] { arg });
+ } catch (Exception e) {
+ return key;
+ }
+ }
+
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ WebBrowserPreference.initializeDefaultPreferences();
+ }
+
+ /**
+ * Shuts down this plug-in and saves all plug-in state.
+ *
+ * @exception Exception
+ */
+ public void stop(BundleContext context) throws Exception {
+ super.stop(context);
+ BrowserManager.getInstance().dispose();
+ }
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. Â This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+Â *
+ * Contributors:
+ * IBM - Initial API and implementation
+ */
+package org.eclipse.webbrowser.internal;
+
+import java.io.File;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.XMLMemento;
+import org.eclipse.webbrowser.IExternalWebBrowser;
+import org.eclipse.webbrowser.IExternalWebBrowserWorkingCopy;
+import org.eclipse.webbrowser.IURLMap;
+import org.eclipse.webbrowser.IWebBrowser;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.core.runtime.*;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.browser.Browser;
+/**
+ * Utility class for the Web browser tooling.
+ */
+public class WebBrowserUtil {
+ private static List urlMaps;
+ private static List lockedFavorites;
+ private static List unlockedFavorites;
+ private static final String BROWSER_PACKAGE_NAME = "org.eclipse.swt.browser.Browser";
+ public static Boolean isInternalBrowserOperational;
+
+ private static List defaultBrowsers2;
+
+ static class DefaultBrowser {
+ String name;
+ String params;
+ String executable;
+ String[] locations;
+
+ public DefaultBrowser(String name, String executable, String params, String[] locations) {
+ if (name == null)
+ name = "<unknown>";
+ else if (name.startsWith("%"))
+ name = WebBrowserUIPlugin.getResource(name);
+
+ this.name = name;
+ this.executable = executable;
+ this.params = params;
+ this.locations = locations;
+ }
+
+ public String toString() {
+ String s = "Browser: " + name + ", " + executable + ", " + params + ", ";
+ if (locations != null) {
+ int size = locations.length;
+ for (int i = 0; i < size; i++) {
+ s += locations[i] + ";";
+ }
+ }
+ return s;
+ }
+ }
+
+ /**
+ * WebBrowserUtil constructor comment.
+ */
+ public WebBrowserUtil() {
+ super();
+ }
+
+ /**
+ * Returns true if we're running on Windows.
+ *
+ * @return boolean
+ */
+ public static boolean isWindows() {
+ String os = System.getProperty("os.name");
+ if (os != null && os.toLowerCase().indexOf("win") >= 0)
+ return true;
+ else
+ return false;
+ }
+
+ /**
+ * Returns true if we're running on linux.
+ *
+ * @return boolean
+ */
+ public static boolean isLinux() {
+ String os = System.getProperty("os.name");
+ if (os != null && os.toLowerCase().indexOf("lin") >= 0)
+ return true;
+ else
+ return false;
+ }
+
+ /**
+ * Open a dialog window.
+ *
+ * @param title java.lang.String
+ * @param message java.lang.String
+ */
+ public static void openError(String message) {
+ Display d = Display.getCurrent();
+ if (d == null)
+ d = Display.getDefault();
+
+ Shell shell = d.getActiveShell();
+ MessageDialog.openError(shell, WebBrowserUIPlugin.getResource("%errorDialogTitle"), message);
+ }
+
+ /**
+ * Open a dialog window.
+ *
+ * @param title java.lang.String
+ * @param message java.lang.String
+ */
+ public static void openMessage(String message) {
+ Display d = Display.getCurrent();
+ if (d == null)
+ d = Display.getDefault();
+
+ Shell shell = d.getActiveShell();
+ MessageDialog.openInformation(shell, WebBrowserUIPlugin.getResource("%searchingTaskName"), message);
+ }
+
+ /**
+ * Returns a List of all URL maps.
+ *
+ * @return java.util.List
+ */
+ public static List getURLMaps() {
+ if (urlMaps == null)
+ loadURLMaps();
+ return urlMaps;
+ }
+
+ /**
+ * Load the url map extension point.
+ */
+ private static void loadURLMaps() {
+ Trace.trace(Trace.FINEST, "->- Loading .urlMap extension point ->-");
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IConfigurationElement[] cf = registry.getConfigurationElementsFor(WebBrowserUIPlugin.PLUGIN_ID, "urlMap");
+
+ int size = cf.length;
+ urlMaps = new ArrayList(size);
+ for (int i = 0; i < size; i++) {
+ try {
+ IURLMap mapper = (IURLMap) cf[i].createExecutableExtension("class");
+ urlMaps.add(mapper);
+ Trace.trace(Trace.FINEST, " Loaded url map: " + cf[i].getAttribute("id"));
+ } catch (Throwable t) {
+ Trace.trace(Trace.SEVERE, " Could not load url map: " + cf[i].getAttribute("id"), t);
+ }
+ }
+
+ Trace.trace(Trace.FINEST, "-<- Done loading .urlMap extension point -<-");
+ }
+
+ /**
+ * Returns a List of all unlocked favorites.
+ *
+ * @return java.util.List
+ */
+ public static List getUnlockedFavorites() {
+ if (unlockedFavorites == null)
+ loadFavorites();
+ return unlockedFavorites;
+ }
+
+ /**
+ * Returns a List of all locked favorites.
+ *
+ * @return java.util.List
+ */
+ public static List getLockedFavorites() {
+ if (lockedFavorites == null)
+ loadFavorites();
+ return lockedFavorites;
+ }
+
+ /**
+ * Load the favorites extension point.
+ */
+ private static void loadFavorites() {
+ Trace.trace(Trace.FINEST, "->- Loading .favorites extension point ->-");
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IConfigurationElement[] cf = registry.getConfigurationElementsFor(WebBrowserUIPlugin.PLUGIN_ID, "favorites");
+
+ int size = cf.length;
+ unlockedFavorites = new ArrayList(size);
+ lockedFavorites = new ArrayList(size);
+ for (int i = 0; i < size; i++) {
+ try {
+ Favorite f = new Favorite(cf[i].getAttribute("name"), cf[i].getAttribute("url"));
+ String locked = cf[i].getAttribute("locked");
+ if (!"true".equals(locked))
+ unlockedFavorites.add(f);
+ else
+ lockedFavorites.add(f);
+ Trace.trace(Trace.FINEST, " Loaded favorite: " + cf[i].getAttribute("id"));
+ } catch (Throwable t) {
+ Trace.trace(Trace.SEVERE, " Could not load favorite: " + cf[i].getAttribute("id"), t);
+ }
+ }
+
+ Trace.trace(Trace.FINEST, "-<- Done loading .favorites extension point -<-");
+ }
+
+ /**
+ * Returns whether it should be possible to use the internal browser or not, based on whether or not
+ * the org.eclipse.swt.Browser class can be found/loaded. If it can it means is is supported on the platform in which
+ * this plugin is running. If not, disable the ability to use the internal browser.
+ *
+ * @return boolean
+ */
+ public static boolean canUseInternalWebBrowser() {
+ try {
+ Class clazz = Class.forName(BROWSER_PACKAGE_NAME);
+ if (clazz != null)
+ return true;
+ } catch (ClassNotFoundException e) { }
+ return false;
+ }
+
+ /**
+ * This method checks to see if it can new up a new Browser. If the SWT widget can not be bound
+ * to the particular operating system it throws an SWTException. We catch that and set a boolean
+ * flag which represents whether or not we were successfully able to create a Browser instance or not.
+ * If not, don't bother adding the Internal Web Browser that uses this widget. Designed to be attemped
+ * only once and the flag set used throughout.
+ *
+ * @return boolean
+ */
+ protected static boolean isInternalBrowserOperational() {
+ // if we have already figured this out, don't do it again.
+ if (isInternalBrowserOperational != null)
+ return isInternalBrowserOperational.booleanValue();
+
+ try {
+ new Browser(new Shell(Display.getCurrent()), SWT.NONE);
+ isInternalBrowserOperational = new Boolean(true);
+ } catch (Throwable t) {
+ WebBrowserUIPlugin.getInstance().getLog().log(new Status(IStatus.WARNING,
+ WebBrowserUIPlugin.PLUGIN_ID, 0, "Internal browser is not operational", t));
+ isInternalBrowserOperational = new Boolean(false);
+ }
+ return isInternalBrowserOperational.booleanValue();
+ }
+
+ public static List getExternalBrowserPaths() {
+ List paths = new ArrayList();
+ Iterator iterator = BrowserManager.getInstance().getWebBrowsers().iterator();
+ while (iterator.hasNext()) {
+ IWebBrowser wb = (IWebBrowser) iterator.next();
+ if (wb instanceof IExternalWebBrowser) {
+ IExternalWebBrowser ext = (IExternalWebBrowser) wb;
+ paths.add(ext.getLocation().toLowerCase());
+ }
+ }
+ return paths;
+ }
+
+ // Add any supported EXTERNAL web browsers found after an arbitrary check in specific paths
+ public static void addFoundBrowsers(List list) {
+ List paths = getExternalBrowserPaths();
+
+ Iterator iterator = getDefaultBrowsers().iterator();
+ while (iterator.hasNext()) {
+ DefaultBrowser browser2 = (DefaultBrowser) iterator.next();
+ if (browser2.locations != null) {
+ int size = browser2.locations.length;
+ for (int j = 0; j < size; j++) {
+ String location = browser2.locations[j];
+ if (!paths.contains(location.toLowerCase())) {
+ try {
+ File f = new File(location);
+ if (f.exists()) {
+ ExternalWebBrowser browser = new ExternalWebBrowser();
+ browser.name = browser2.name;
+ browser.location = location;
+ browser.parameters = browser2.params;
+ list.add(browser);
+ //Add browser here so that it get added to the table
+ BrowserManager.getInstance().addBrowser(browser);
+ j += size;
+ }
+ } catch (Exception e) { }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Create an external Web browser if the file matches the default (known) browsers.
+ * @param file
+ * @return
+ */
+ public static IExternalWebBrowserWorkingCopy createExternalBrowser(File file) {
+ if (file == null || !file.isFile())
+ return null;
+
+ String executable = file.getName();
+ Iterator iterator = getDefaultBrowsers().iterator();
+ while (iterator.hasNext()) {
+ DefaultBrowser db = (DefaultBrowser) iterator.next();
+ if (executable.equals(db.executable)) {
+ IExternalWebBrowserWorkingCopy browser = BrowserManager.getInstance().createExternalWebBrowser();
+ browser.setName(db.name);
+ browser.setLocation(file.getAbsolutePath());
+ browser.setParameters(db.params);
+ return browser;
+ }
+ }
+
+ return null;
+ }
+
+ protected static List getDefaultBrowsers() {
+ if (defaultBrowsers2 != null)
+ return defaultBrowsers2;
+
+ Reader reader = null;
+ defaultBrowsers2 = new ArrayList();
+ try {
+ URL url = WebBrowserUIPlugin.getInstance().getBundle().getEntry("defaultBrowsers.xml");
+ URL url2 = Platform.resolve(url);
+ reader = new InputStreamReader(url2.openStream());
+ IMemento memento = XMLMemento.createReadRoot(reader);
+ IMemento[] children = memento.getChildren("browser");
+ if (children != null) {
+ int size = children.length;
+ for (int i = 0; i < size; i++) {
+ IMemento child = children[i];
+ String name = child.getString("name");
+ String executable = child.getString("executable");
+ String params = child.getString("params");
+ List locations = new ArrayList();
+
+ IMemento[] locat = child.getChildren("location");
+ if (locat != null) {
+ int size2 = locat.length;
+ for (int j = 0; j < size2; j++)
+ locations.add(locat[j].getTextData());
+ }
+
+ String[] loc = new String[locations.size()];
+ locations.toArray(loc);
+ DefaultBrowser db = new DefaultBrowser(name, executable, params, loc);
+ Trace.trace(Trace.CONFIG, "Default browser: " + db);
+ defaultBrowsers2.add(db);
+ }
+ }
+ } catch (Exception e) {
+ Trace.trace(Trace.SEVERE, "Error loading default browsers", e);
+ } finally {
+ try {
+ reader.close();
+ } catch (Exception e) { }
+ }
+ return defaultBrowsers2;
+ }
+}
\ No newline at end of file
* IBM Corporation - initial API and implementation
*******************************************************************************/
package net.sourceforge.phpeclipse.views.browser;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
+import org.eclipse.webbrowser.internal.WebBrowser;
+import org.eclipse.webbrowser.internal.WebBrowserUIPlugin;
+import org.eclipse.webbrowser.internal.WebBrowserUtil;
/**
* <code>BrowserView</code> is a simple demonstration of the SWT Browser
* widget. It consists of a workbench view and tab folder where each tab in the
*/
public class BrowserView extends ViewPart {
public final static String ID_BROWSER = "net.sourceforge.phpeclipse.views.browser";
- PHPBrowser instance = null;
+ WebBrowser instance = null;
/**
* Create the example
*
*/
public void createPartControl(Composite frame) {
try {
- instance = new PHPBrowser(frame);
- if (instance.browser==null) {
- instance = null;
+ if (WebBrowserUtil.canUseInternalWebBrowser() ) {
+ instance = new WebBrowser(frame, true, true);
}
} catch(Exception e) {
instance = null;
}
public void setUrl(String url) {
if (instance!=null) {
- instance.browser.setUrl(url);
+ instance.setURL(url);
}
}
public void refresh() {
if (instance!=null) {
- instance.browser.refresh();
+ instance.refresh();
}
}
}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package net.sourceforge.phpeclipse.views.browser;
-import java.text.MessageFormat;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTError;
-import org.eclipse.swt.browser.Browser;
-import org.eclipse.swt.browser.CloseWindowListener;
-import org.eclipse.swt.browser.LocationEvent;
-import org.eclipse.swt.browser.LocationListener;
-import org.eclipse.swt.browser.OpenWindowListener;
-import org.eclipse.swt.browser.ProgressEvent;
-import org.eclipse.swt.browser.ProgressListener;
-import org.eclipse.swt.browser.StatusTextEvent;
-import org.eclipse.swt.browser.StatusTextListener;
-import org.eclipse.swt.browser.TitleEvent;
-import org.eclipse.swt.browser.TitleListener;
-import org.eclipse.swt.browser.VisibilityWindowListener;
-import org.eclipse.swt.browser.WindowEvent;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.ImageData;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.layout.FormAttachment;
-import org.eclipse.swt.layout.FormData;
-import org.eclipse.swt.layout.FormLayout;
-import org.eclipse.swt.widgets.Canvas;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.ProgressBar;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.swt.widgets.ToolBar;
-import org.eclipse.swt.widgets.ToolItem;
-
-public class PHPBrowser {
- static ResourceBundle resourceBundle = ResourceBundle
- .getBundle("net.sourceforge.phpeclipse.views.browser.browser");
- int index;
- boolean busy;
- Image images[];
- Text location;
- Browser browser;
- static final String[] imageLocations = {"eclipse01.bmp", "eclipse02.bmp",
- "eclipse03.bmp", "eclipse04.bmp", "eclipse05.bmp", "eclipse06.bmp",
- "eclipse07.bmp", "eclipse08.bmp", "eclipse09.bmp", "eclipse10.bmp",
- "eclipse11.bmp", "eclipse12.bmp",};
- static final String iconLocation = "document.gif";
- /**
- * Creates an instance of a ControlExample embedded inside the supplied
- * parent Composite.
- *
- * @param parent
- * the container of the example
- */
- public PHPBrowser(Composite parent) {
- initResources();
- final Display display = parent.getDisplay();
- FormLayout layout = new FormLayout();
- parent.setLayout(layout);
- ToolBar toolbar = new ToolBar(parent, SWT.NONE);
- final ToolItem itemBack = new ToolItem(toolbar, SWT.PUSH);
- itemBack.setText(getResourceString("Back"));
- final ToolItem itemForward = new ToolItem(toolbar, SWT.PUSH);
- itemForward.setText(getResourceString("Forward"));
- final ToolItem itemStop = new ToolItem(toolbar, SWT.PUSH);
- itemStop.setText(getResourceString("Stop"));
- final ToolItem itemRefresh = new ToolItem(toolbar, SWT.PUSH);
- itemRefresh.setText(getResourceString("Refresh"));
- final ToolItem itemGo = new ToolItem(toolbar, SWT.PUSH);
- itemGo.setText(getResourceString("Go"));
- location = new Text(parent, SWT.BORDER);
- final Canvas canvas = new Canvas(parent, SWT.NO_BACKGROUND);
- final Rectangle rect = images[0].getBounds();
- canvas.addListener(SWT.Paint, new Listener() {
- public void handleEvent(Event e) {
- Point pt = canvas.getSize();
- e.gc.drawImage(images[index], 0, 0, rect.width, rect.height, 0, 0,
- pt.x, pt.y);
- }
- });
- canvas.addListener(SWT.MouseDown, new Listener() {
- public void handleEvent(Event e) {
- browser.setUrl(getResourceString("Startup"));
- }
- });
- display.asyncExec(new Runnable() {
- public void run() {
- if (canvas.isDisposed())
- return;
- if (busy) {
- index++;
- if (index == images.length)
- index = 0;
- canvas.redraw();
- }
- display.timerExec(150, this);
- }
- });
- final Label status = new Label(parent, SWT.NONE);
- final ProgressBar progressBar = new ProgressBar(parent, SWT.NONE);
- FormData data = new FormData();
- data.top = new FormAttachment(0, 5);
- toolbar.setLayoutData(data);
- data = new FormData();
- data.left = new FormAttachment(0, 0);
- data.right = new FormAttachment(100, 0);
- data.top = new FormAttachment(canvas, 5, SWT.DEFAULT);
- data.bottom = new FormAttachment(status, -5, SWT.DEFAULT);
- try {
- browser = new Browser(parent, SWT.NONE);
- browser.setLayoutData(data);
- } catch (SWTError e) {
- /* Browser widget could not be instantiated */
- Label label = new Label(parent, SWT.CENTER | SWT.WRAP);
- label.setText(getResourceString("BrowserNotCreated"));
- label.setLayoutData(data);
- }
- data = new FormData();
- data.width = 24;
- data.height = 24;
- data.top = new FormAttachment(0, 5);
- data.right = new FormAttachment(100, -5);
- canvas.setLayoutData(data);
- data = new FormData();
- data.top = new FormAttachment(toolbar, 0, SWT.TOP);
- data.left = new FormAttachment(toolbar, 5, SWT.RIGHT);
- data.right = new FormAttachment(canvas, -5, SWT.DEFAULT);
- location.setLayoutData(data);
- data = new FormData();
- data.left = new FormAttachment(0, 5);
- data.right = new FormAttachment(progressBar, 0, SWT.DEFAULT);
- data.bottom = new FormAttachment(100, -5);
- status.setLayoutData(data);
- data = new FormData();
- data.right = new FormAttachment(100, -5);
- data.bottom = new FormAttachment(100, -5);
- progressBar.setLayoutData(data);
- if (browser != null) {
- itemBack.setEnabled(browser.isBackEnabled());
- itemForward.setEnabled(browser.isForwardEnabled());
- Listener listener = new Listener() {
- public void handleEvent(Event event) {
- ToolItem item = (ToolItem) event.widget;
- if (item == itemBack)
- browser.back();
- else if (item == itemForward)
- browser.forward();
- else if (item == itemStop)
- browser.stop();
- else if (item == itemRefresh)
- browser.refresh();
- else if (item == itemGo)
- browser.setUrl(location.getText());
- }
- };
- browser.addLocationListener(new LocationListener() {
- public void changed(LocationEvent event) {
- busy = true;
- if (event.top)
- location.setText(event.location);
- }
- public void changing(LocationEvent event) {
- }
- });
- browser.addProgressListener(new ProgressListener() {
- public void changed(ProgressEvent event) {
- if (event.total == 0)
- return;
- int ratio = event.current * 100 / event.total;
- progressBar.setSelection(ratio);
- busy = event.current != event.total;
- if (!busy) {
- index = 0;
- canvas.redraw();
- }
- }
- public void completed(ProgressEvent event) {
- itemBack.setEnabled(browser.isBackEnabled());
- itemForward.setEnabled(browser.isForwardEnabled());
- progressBar.setSelection(0);
- busy = false;
- index = 0;
- canvas.redraw();
- }
- });
- browser.addStatusTextListener(new StatusTextListener() {
- public void changed(StatusTextEvent event) {
- status.setText(event.text);
- }
- });
- if (parent instanceof Shell) {
- final Shell shell = (Shell) parent;
- browser.addTitleListener(new TitleListener() {
- public void changed(TitleEvent event) {
- shell.setText(event.title + " - "
- + getResourceString("window.title"));
- }
- });
- }
- itemBack.addListener(SWT.Selection, listener);
- itemForward.addListener(SWT.Selection, listener);
- itemStop.addListener(SWT.Selection, listener);
- itemRefresh.addListener(SWT.Selection, listener);
- itemGo.addListener(SWT.Selection, listener);
- location.addListener(SWT.DefaultSelection, new Listener() {
- public void handleEvent(Event e) {
- browser.setUrl(location.getText());
- }
- });
- initialize(display, browser);
- browser.setUrl(getResourceString("Startup"));
- }
- }
- /**
- * Gets a string from the resource bundle. We don't want to crash because of
- * a missing String. Returns the key if not found.
- */
- static String getResourceString(String key) {
- try {
- return resourceBundle.getString(key);
- } catch (MissingResourceException e) {
- return key;
- } catch (NullPointerException e) {
- return "!" + key + "!";
- }
- }
- /**
- * Gets a string from the resource bundle and binds it with the given
- * arguments. If the key is not found, return the key.
- */
- static String getResourceString(String key, Object[] args) {
- try {
- return MessageFormat.format(getResourceString(key), args);
- } catch (MissingResourceException e) {
- return key;
- } catch (NullPointerException e) {
- return "!" + key + "!";
- }
- }
- static void initialize(final Display display, Browser browser) {
- browser.addOpenWindowListener(new OpenWindowListener() {
- public void open(WindowEvent event) {
- Shell shell = new Shell(display);
- shell.setLayout(new FillLayout());
- Browser browser = new Browser(shell, SWT.NONE);
- initialize(display, browser);
- event.browser = browser;
- }
- });
- browser.addVisibilityWindowListener(new VisibilityWindowListener() {
- public void hide(WindowEvent event) {
- }
- public void show(WindowEvent event) {
- Browser browser = (Browser) event.widget;
- Shell shell = browser.getShell();
- if (event.location != null)
- shell.setLocation(event.location);
- if (event.size != null) {
- Point size = event.size;
- shell.setSize(shell.computeSize(size.x, size.y));
- }
- shell.open();
- }
- });
- browser.addCloseWindowListener(new CloseWindowListener() {
- public void close(WindowEvent event) {
- Browser browser = (Browser) event.widget;
- Shell shell = browser.getShell();
- shell.close();
- }
- });
- }
- /**
- * Disposes of all resources associated with a particular instance of the
- * BrowserExample.
- */
- public void dispose() {
- freeResources();
- }
- /**
- * Frees the resources
- */
- void freeResources() {
- if (images != null) {
- for (int i = 0; i < images.length; ++i) {
- final Image image = images[i];
- if (image != null)
- image.dispose();
- }
- images = null;
- }
- }
- /**
- * Grabs input focus.
- */
- public void setFocus() {
- location.setFocus();
- }
- /**
- * Loads the resources
- */
- void initResources() {
- final Class clazz = this.getClass();
- if (resourceBundle != null) {
- try {
- if (images == null) {
- images = new Image[imageLocations.length];
- for (int i = 0; i < imageLocations.length; ++i) {
- ImageData source = new ImageData(clazz
- .getResourceAsStream(imageLocations[i]));
- ImageData mask = source.getTransparencyMask();
- images[i] = new Image(null, source, mask);
- }
- }
- return;
- } catch (Throwable t) {
- }
- }
- String error = (resourceBundle != null)
- ? getResourceString("error.CouldNotLoadResources")
- : "Unable to load resources";
- freeResources();
- throw new RuntimeException(error);
- }
- public static void main(String[] args) {
- Display display = new Display();
- Shell shell = new Shell(display);
- shell.setLayout(new FillLayout());
- shell.setText(getResourceString("window.title"));
- PHPBrowser instance = new PHPBrowser(shell);
- Image icon = new Image(display, PHPBrowser.class
- .getResourceAsStream(iconLocation));
- shell.setImage(icon);
- shell.open();
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch())
- display.sleep();
- }
- icon.dispose();
- instance.dispose();
- display.dispose();
- }
-}
\ No newline at end of file
+++ /dev/null
-###############################################################################
-# Copyright (c) 2000, 2003 IBM Corporation and others.
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Common Public License v1.0
-# which accompanies this distribution, and is available at
-# http://www.eclipse.org/legal/cpl-v10.html
-#
-# Contributors:
-# IBM Corporation - initial API and implementation
-###############################################################################
-error.CouldNotLoadResources = Unable to load resources
-window.title = PHP Browser
-
-Back = Back
-BrowserNotCreated = Error - The Browser widget could not be instantiated. Please check the Browser widget is supported on this platform. Supported platforms and software requirements for the Browser widget are listed on the SWT FAQ web page.
-Forward = Forward
-Stop = Stop
-Refresh = Refresh
-Go = Go
-Startup = http://www.phpeclipse.de