1 package net.sourceforge.phpeclipse.ui.editor;
3 import net.sourceforge.phpeclipse.ui.IPreferenceConstants;
4 import net.sourceforge.phpeclipse.ui.WebUI;
5 import net.sourceforge.phpeclipse.ui.overlaypages.ProjectPrefUtil;
6 import net.sourceforge.phpeclipse.webbrowser.views.BrowserView;
8 import org.eclipse.core.resources.IFile;
9 import org.eclipse.ui.IViewPart;
10 import org.eclipse.ui.IWorkbenchPage;
12 public class BrowserUtil {
14 public static void showPreview(IFile previewFile, boolean forceDBGPreview, String postFix) {
15 if (previewFile == null) {
16 // should never happen
19 IWorkbenchPage page = WebUI.getActivePage();
20 if (page!=null && page.isEditorAreaVisible()) {
21 String extension = previewFile.getFileExtension().toLowerCase();
22 boolean autoPreview = forceDBGPreview;
23 boolean showHTMLFilesLocal = false;
24 boolean showXMLFilesLocal = false;
25 boolean isHTMLFileName = false;
26 boolean isXMLFileName = false;
27 if (!forceDBGPreview) {
28 autoPreview = ProjectPrefUtil.getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_AUTO_PREVIEW_DEFAULT);
30 showHTMLFilesLocal = ProjectPrefUtil.getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_SHOW_HTML_FILES_LOCAL);
31 showXMLFilesLocal = ProjectPrefUtil.getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_SHOW_XML_FILES_LOCAL);
32 isHTMLFileName = "html".equals(extension) || "htm".equals(extension) || "xhtml".equals(extension);
33 isXMLFileName = "xml".equals(extension) || "xsd".equals(extension) || "dtd".equals(extension);
37 if (showHTMLFilesLocal && isHTMLFileName) {
38 localhostURL = previewFile.getLocation().toString();
39 } else if (showXMLFilesLocal && isXMLFileName) {
40 localhostURL = previewFile.getLocation().toString();
41 } else if ((localhostURL = ShowExternalPreviewAction.getLocalhostURL(null, previewFile)) == null) {
44 localhostURL += postFix;
47 IViewPart part = page.showView(BrowserView.ID_BROWSER, null, IWorkbenchPage.VIEW_VISIBLE);
49 part = page.showView(BrowserView.ID_BROWSER);
51 page.bringToTop(part);
53 ((BrowserView) part).setUrl(localhostURL);
55 } catch (Exception e) {
56 // PHPeclipsePlugin.log(e);