Organized imports
[phpeclipse.git] / net.sourceforge.phpeclipse.webbrowser / src / net / sourceforge / phpeclipse / webbrowser / views / BrowserView.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpeclipse.webbrowser.views;
12
13 import net.sourceforge.phpeclipse.webbrowser.internal.WebBrowser;
14 import net.sourceforge.phpeclipse.webbrowser.internal.WebBrowserUtil;
15
16 import org.eclipse.swt.browser.ProgressListener;
17 import org.eclipse.swt.browser.StatusTextListener;
18 import org.eclipse.swt.browser.TitleListener;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.ui.part.ViewPart;
21
22 /**
23  * <code>BrowserView</code> is a simple demonstration of the SWT Browser widget. It consists of a workbench view and tab folder
24  * where each tab in the folder allows the user to interact with a control.
25  * 
26  * @see ViewPart
27  */
28 public class BrowserView extends ViewPart {
29   public final static String ID_BROWSER = "net.sourceforge.phpeclipse.webbrowser.views";
30
31   WebBrowser fInstance = null;
32   String fUrl = null;
33
34   /**
35    * Create the example
36    * 
37    * @see ViewPart#createPartControl
38    */
39   public void createPartControl(Composite frame) {
40     try {
41       if (WebBrowserUtil.isInternalBrowserOperational()) {
42         fInstance = new WebBrowser(frame, true, true);
43       } 
44     } catch (Exception e) {
45       fInstance = null;
46     }
47   }
48
49   /**
50    * Called when we must grab focus.
51    * 
52    * @see org.eclipse.ui.part.ViewPart#setFocus
53    */
54   public void setFocus() {
55     if (fInstance != null) {
56       fInstance.setFocus();
57     }
58   }
59
60   /**
61    * Called when the View is to be disposed
62    */
63   public void dispose() {
64     if (fInstance != null) {
65       fInstance.dispose();
66       fInstance = null;
67     }
68     super.dispose();
69   }
70
71   public void setUrl(final String url) {
72     if (fInstance != null) {
73       fUrl = url;
74       fInstance.setURL(url);
75       //      try {
76       //        ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
77       //          public void run(IProgressMonitor monitor) throws CoreException {
78       //            instance.setURL(url);
79       //          }
80       //        }, null);
81       //      } catch (CoreException e) {
82       //        // TODO Auto-generated catch block
83       //        e.printStackTrace();
84       //      }
85     }
86   }
87
88   public void refresh() {
89     if (fInstance != null) {
90       fInstance.refresh();
91       //      try {
92       //        ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
93       //          public void run(IProgressMonitor monitor) throws CoreException {
94       //            instance.refresh();
95       //          }
96       //        }, null);
97       //      } catch (CoreException e) {
98       //        // TODO Auto-generated catch block
99       //        e.printStackTrace();
100       //      }
101     }
102   }
103
104   public void refresh(String url) {
105     if (fInstance != null) {
106       if (fUrl==null || !fUrl.equals(url) ) {
107         setUrl(url);
108       } else {
109         refresh();
110       }
111     }
112   } 
113   
114   public void addProgressListener(ProgressListener listener) {
115     if (fInstance != null) {
116       fInstance.addProgressListener(listener);
117     }
118   }
119
120   public void addStatusTextListener(StatusTextListener listener) {
121     if (fInstance != null) {
122       fInstance.addStatusTextListener(listener);
123     }
124   }
125
126   public void addTitleListener(TitleListener listener) {
127     if (fInstance != null) {
128       fInstance.addTitleListener(listener);
129     }
130   }
131 }