1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpeclipse.webbrowser.views;
13 import java.io.UnsupportedEncodingException;
14 import java.net.URLDecoder;
16 import net.sourceforge.phpeclipse.webbrowser.internal.WebBrowser;
17 import net.sourceforge.phpeclipse.webbrowser.internal.WebBrowserUtil;
19 import org.eclipse.swt.browser.Browser;
20 import org.eclipse.swt.browser.CloseWindowListener;
21 //import org.eclipse.swt.browser.ProgressListener;
22 //import org.eclipse.swt.browser.StatusTextListener;
23 //import org.eclipse.swt.browser.TitleListener;
24 import org.eclipse.swt.browser.WindowEvent;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.ui.part.IShowInTarget;
27 import org.eclipse.ui.part.ShowInContext;
28 import org.eclipse.ui.part.ViewPart;
31 * <code>BrowserView</code> is a simple demonstration of the SWT Browser
32 * widget. It consists of a workbench view and tab folder where each tab in the
33 * folder allows the user to interact with a control.
37 public class BrowserView extends ViewPart implements IShowInTarget {
38 public final static String ID_BROWSER = "net.sourceforge.phpeclipse.webbrowser.views";
40 WebBrowser fInstance = null;
47 * @see ViewPart#createPartControl
49 public void createPartControl(Composite frame) {
51 if (WebBrowserUtil.isInternalBrowserOperational()) {
52 fInstance = new WebBrowser(frame, true, true);
53 // #1365431 (toshihiro) start
54 fInstance.getBrowser().addCloseWindowListener(
55 new CloseWindowListener() {
56 public void close(WindowEvent event) {
57 getViewSite().getPage().hideView(
61 // #1365431 (toshihiro) end
63 } catch (Exception e) {
69 * Called when we must grab focus.
71 * @see org.eclipse.ui.part.ViewPart#setFocus
73 public void setFocus() {
74 if (fInstance != null) {
80 * Called when the View is to be disposed
82 public void dispose() {
83 if (fInstance != null) {
90 public String getUrl() {
91 if (fInstance != null) {
92 return fInstance.getURL();
98 public void setUrl(final String url) {
99 if (fInstance != null) {
101 fInstance.setURL(url);
103 // ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
104 // public void run(IProgressMonitor monitor) throws CoreException {
105 // instance.setURL(url);
108 // } catch (CoreException e) {
109 // // TO DO Auto-generated catch block
110 // e.printStackTrace();
115 public void refresh() {
116 if (fInstance != null) {
119 // ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
120 // public void run(IProgressMonitor monitor) throws CoreException {
121 // instance.refresh();
124 // } catch (CoreException e) {
125 // // TO DO Auto-generated catch block
126 // e.printStackTrace();
133 public void refresh(String url) {
134 if (fInstance != null && url != null) {
138 Browser browser = fInstance.getBrowser();
139 if (browser != null) {
140 String browserUrl = browser.getUrl();
142 browserUrl = URLDecoder.decode(browserUrl, J5CharsetEmulator.defaultCharset().name());
143 } catch (UnsupportedEncodingException e) {
144 // e.printStackTrace();
146 if (!url.equals(browserUrl)) {
154 // public void addProgressListener(ProgressListener listener) {
155 // if (fInstance != null) {
156 // fInstance.addProgressListener(listener);
160 // public void addStatusTextListener(StatusTextListener listener) {
161 // if (fInstance != null) {
162 // fInstance.addStatusTextListener(listener);
166 // public void addTitleListener(TitleListener listener) {
167 // if (fInstance != null) {
168 // fInstance.addTitleListener(listener);
172 public boolean show(ShowInContext context) {
173 if (context instanceof ShowInContextBrowser) {
174 ShowInContextBrowser contextBrowser = (ShowInContextBrowser) context;
175 String localhostURL = contextBrowser.getLocalhostUrl();
176 if (localhostURL != null) {
177 setUrl(localhostURL);
182 // This causes unexpected behaviour such as downloading (save file).
183 // It depends on mime-types setting and native browser, it isn't under control of eclipse.
184 // (IE shows script as plain text since .php is unknown type by default.
185 // Mozilla downloads script file since .php is defined in mimeTypes.rdf as such.)
187 //if (context.getInput() instanceof IFile) {
188 // IFile file = (IFile) context.getInput();
189 // String localhostURL;
190 // localhostURL = "file:///" + file.getLocation().toString();
191 // setUrl(localhostURL);