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 String extension = previewFile.getFileExtension().toLowerCase();
20 boolean autoPreview = forceDBGPreview;
21 boolean bringToTopPreview = true;
22 boolean showHTMLFilesLocal = false;
23 boolean showXMLFilesLocal = false;
24 boolean isHTMLFileName = false;
25 boolean isXMLFileName = false;
26 if (!forceDBGPreview) {
27 autoPreview = ProjectPrefUtil.getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_AUTO_PREVIEW_DEFAULT);
29 bringToTopPreview = ProjectPrefUtil
30 .getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_BRING_TO_TOP_PREVIEW_DEFAULT);
31 showHTMLFilesLocal = ProjectPrefUtil.getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_SHOW_HTML_FILES_LOCAL);
32 showXMLFilesLocal = ProjectPrefUtil.getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_SHOW_XML_FILES_LOCAL);
33 isHTMLFileName = "html".equals(extension) || "htm".equals(extension) || "xhtml".equals(extension);
34 isXMLFileName = "xml".equals(extension) || "xsd".equals(extension) || "dtd".equals(extension);
38 if (showHTMLFilesLocal && isHTMLFileName) {
39 localhostURL = previewFile.getLocation().toString();
40 } else if (showXMLFilesLocal && isXMLFileName) {
41 localhostURL = previewFile.getLocation().toString();
42 } else if ((localhostURL = ShowExternalPreviewAction.getLocalhostURL(null, previewFile)) == null) {
45 localhostURL += postFix;
48 IWorkbenchPage page = WebUI.getActivePage();
49 IViewPart part = page.showView(BrowserView.ID_BROWSER, null, IWorkbenchPage.VIEW_VISIBLE);
50 // if (part == null) {
51 // part = page.showView(BrowserView.ID_BROWSER);
54 if (bringToTopPreview) {
55 page.bringToTop(part);
57 ((BrowserView) part).setUrl(localhostURL);
61 } catch (Exception e) {
62 // PHPeclipsePlugin.log(e);