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 net.sourceforge.phpeclipse.webbrowser.internal.WebBrowser;
14 import net.sourceforge.phpeclipse.webbrowser.internal.WebBrowserUtil;
16 import org.eclipse.core.resources.IFile;
17 import org.eclipse.swt.browser.Browser;
18 import org.eclipse.swt.browser.CloseWindowListener;
19 import org.eclipse.swt.browser.ProgressListener;
20 import org.eclipse.swt.browser.StatusTextListener;
21 import org.eclipse.swt.browser.TitleListener;
22 import org.eclipse.swt.browser.WindowEvent;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.ui.part.IShowInTarget;
25 import org.eclipse.ui.part.ShowInContext;
26 import org.eclipse.ui.part.ViewPart;
29 * <code>BrowserView</code> is a simple demonstration of the SWT Browser
30 * widget. It consists of a workbench view and tab folder where each tab in the
31 * folder allows the user to interact with a control.
35 public class BrowserView extends ViewPart implements IShowInTarget {
36 public final static String ID_BROWSER = "net.sourceforge.phpeclipse.webbrowser.views";
38 WebBrowser fInstance = null;
45 * @see ViewPart#createPartControl
47 public void createPartControl(Composite frame) {
49 if (WebBrowserUtil.isInternalBrowserOperational()) {
50 fInstance = new WebBrowser(frame, true, true);
51 // #1365431 (toshihiro) start
52 fInstance.getBrowser().addCloseWindowListener(
53 new CloseWindowListener() {
54 public void close(WindowEvent event) {
55 getViewSite().getPage().hideView(
59 // #1365431 (toshihiro) end
61 } catch (Exception e) {
67 * Called when we must grab focus.
69 * @see org.eclipse.ui.part.ViewPart#setFocus
71 public void setFocus() {
72 if (fInstance != null) {
78 * Called when the View is to be disposed
80 public void dispose() {
81 if (fInstance != null) {
88 public void setUrl(final String url) {
89 if (fInstance != null) {
91 fInstance.setURL(url);
93 // ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
94 // public void run(IProgressMonitor monitor) throws CoreException {
95 // instance.setURL(url);
98 // } catch (CoreException e) {
99 // // TO DO Auto-generated catch block
100 // e.printStackTrace();
105 public void refresh() {
106 if (fInstance != null) {
109 // ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
110 // public void run(IProgressMonitor monitor) throws CoreException {
111 // instance.refresh();
114 // } catch (CoreException e) {
115 // // TO DO Auto-generated catch block
116 // e.printStackTrace();
121 public void refresh(String url) {
122 if (fInstance != null && url != null) {
126 Browser browser = fInstance.getBrowser();
127 if (browser != null && !browser.getUrl().equals(url)) {
134 public void addProgressListener(ProgressListener listener) {
135 if (fInstance != null) {
136 fInstance.addProgressListener(listener);
140 public void addStatusTextListener(StatusTextListener listener) {
141 if (fInstance != null) {
142 fInstance.addStatusTextListener(listener);
146 public void addTitleListener(TitleListener listener) {
147 if (fInstance != null) {
148 fInstance.addTitleListener(listener);
152 public boolean show(ShowInContext context) {
153 if (context instanceof ShowInContextBrowser) {
154 ShowInContextBrowser contextBrowser = (ShowInContextBrowser) context;
155 String localhostURL = contextBrowser.getLocalhostUrl();
156 if (localhostURL != null) {
157 setUrl(localhostURL);
161 if (context.getInput() instanceof IFile) {
162 IFile file = (IFile) context.getInput();
164 localhostURL = "file:///" + file.getLocation().toString();
165 setUrl(localhostURL);