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.CloseWindowListener;
18 import org.eclipse.swt.browser.ProgressListener;
19 import org.eclipse.swt.browser.StatusTextListener;
20 import org.eclipse.swt.browser.TitleListener;
21 import org.eclipse.swt.browser.WindowEvent;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.ui.part.IShowInTarget;
24 import org.eclipse.ui.part.ShowInContext;
25 import org.eclipse.ui.part.ViewPart;
28 * <code>BrowserView</code> is a simple demonstration of the SWT Browser
29 * widget. It consists of a workbench view and tab folder where each tab in the
30 * folder allows the user to interact with a control.
34 public class BrowserView extends ViewPart implements IShowInTarget {
35 public final static String ID_BROWSER = "net.sourceforge.phpeclipse.webbrowser.views";
37 WebBrowser fInstance = null;
44 * @see ViewPart#createPartControl
46 public void createPartControl(Composite frame) {
48 if (WebBrowserUtil.isInternalBrowserOperational()) {
49 fInstance = new WebBrowser(frame, true, true);
50 // #1365431 (toshihiro) start
51 fInstance.getBrowser().addCloseWindowListener(
52 new CloseWindowListener() {
53 public void close(WindowEvent event) {
54 getViewSite().getPage().hideView(
58 // #1365431 (toshihiro) end
60 } catch (Exception e) {
66 * Called when we must grab focus.
68 * @see org.eclipse.ui.part.ViewPart#setFocus
70 public void setFocus() {
71 if (fInstance != null) {
77 * Called when the View is to be disposed
79 public void dispose() {
80 if (fInstance != null) {
87 public void setUrl(final String url) {
88 if (fInstance != null) {
90 fInstance.setURL(url);
92 // ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
93 // public void run(IProgressMonitor monitor) throws CoreException {
94 // instance.setURL(url);
97 // } catch (CoreException e) {
98 // // TODO Auto-generated catch block
99 // e.printStackTrace();
104 public void refresh() {
105 if (fInstance != null) {
108 // ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
109 // public void run(IProgressMonitor monitor) throws CoreException {
110 // instance.refresh();
113 // } catch (CoreException e) {
114 // // TODO Auto-generated catch block
115 // e.printStackTrace();
120 public void refresh(String url) {
121 if (fInstance != null) {
122 if (fUrl == null || !fUrl.equals(url)) {
130 public void addProgressListener(ProgressListener listener) {
131 if (fInstance != null) {
132 fInstance.addProgressListener(listener);
136 public void addStatusTextListener(StatusTextListener listener) {
137 if (fInstance != null) {
138 fInstance.addStatusTextListener(listener);
142 public void addTitleListener(TitleListener listener) {
143 if (fInstance != null) {
144 fInstance.addTitleListener(listener);
148 public boolean show(ShowInContext context) {
149 if (context instanceof ShowInContextBrowser) {
150 ShowInContextBrowser contextBrowser = (ShowInContextBrowser) context;
151 String localhostURL = contextBrowser.getLocalhostUrl();
152 if (localhostURL != null) {
153 setUrl(localhostURL);
157 if (context.getInput() instanceof IFile) {
158 IFile file = (IFile) context.getInput();
160 localhostURL = "file:///" + file.getLocation().toString();
161 setUrl(localhostURL);