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.ProgressListener;
18 import org.eclipse.swt.browser.StatusTextListener;
19 import org.eclipse.swt.browser.TitleListener;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.ui.part.IShowInTarget;
22 import org.eclipse.ui.part.ShowInContext;
23 import org.eclipse.ui.part.ViewPart;
26 * <code>BrowserView</code> is a simple demonstration of the SWT Browser
27 * widget. It consists of a workbench view and tab folder where each tab in the
28 * folder allows the user to interact with a control.
32 public class BrowserView extends ViewPart implements IShowInTarget {
33 public final static String ID_BROWSER = "net.sourceforge.phpeclipse.webbrowser.views";
35 WebBrowser fInstance = null;
42 * @see ViewPart#createPartControl
44 public void createPartControl(Composite frame) {
46 if (WebBrowserUtil.isInternalBrowserOperational()) {
47 fInstance = new WebBrowser(frame, true, true);
49 } catch (Exception e) {
55 * Called when we must grab focus.
57 * @see org.eclipse.ui.part.ViewPart#setFocus
59 public void setFocus() {
60 if (fInstance != null) {
66 * Called when the View is to be disposed
68 public void dispose() {
69 if (fInstance != null) {
76 public void setUrl(final String url) {
77 if (fInstance != null) {
79 fInstance.setURL(url);
81 // ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
82 // public void run(IProgressMonitor monitor) throws CoreException {
83 // instance.setURL(url);
86 // } catch (CoreException e) {
87 // // TODO Auto-generated catch block
88 // e.printStackTrace();
93 public void refresh() {
94 if (fInstance != null) {
97 // ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
98 // public void run(IProgressMonitor monitor) throws CoreException {
99 // instance.refresh();
102 // } catch (CoreException e) {
103 // // TODO Auto-generated catch block
104 // e.printStackTrace();
109 public void refresh(String url) {
110 if (fInstance != null) {
111 if (fUrl == null || !fUrl.equals(url)) {
119 public void addProgressListener(ProgressListener listener) {
120 if (fInstance != null) {
121 fInstance.addProgressListener(listener);
125 public void addStatusTextListener(StatusTextListener listener) {
126 if (fInstance != null) {
127 fInstance.addStatusTextListener(listener);
131 public void addTitleListener(TitleListener listener) {
132 if (fInstance != null) {
133 fInstance.addTitleListener(listener);
137 public boolean show(ShowInContext context) {
138 if (context instanceof ShowInContextBrowser) {
139 ShowInContextBrowser contextBrowser = (ShowInContextBrowser) context;
140 String localhostURL = contextBrowser.getLocalhostUrl();
141 if (localhostURL != null) {
142 setUrl(localhostURL);
146 if (context.getInput() instanceof IFile) {
147 IFile file = (IFile) context.getInput();
149 localhostURL = "file:///" + file.getLocation().toString();
150 setUrl(localhostURL);