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;
 
  13 public class BrowserUtil {
 
  15   public static void showPreview(IFile previewFile, boolean forceDBGPreview, String postFix) {
 
  16     if (previewFile == null) {
 
  17       // should never happen
 
  20     String extension = previewFile.getFileExtension().toLowerCase();
 
  21     boolean autoPreview = forceDBGPreview;
 
  22     boolean bringToTopPreview = true;
 
  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       bringToTopPreview = ProjectPrefUtil
 
  31           .getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_BRING_TO_TOP_PREVIEW_DEFAULT);
 
  32       showHTMLFilesLocal = ProjectPrefUtil.getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_SHOW_HTML_FILES_LOCAL);
 
  33       showXMLFilesLocal = ProjectPrefUtil.getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_SHOW_XML_FILES_LOCAL);
 
  34       isHTMLFileName = "html".equals(extension) || "htm".equals(extension) || "xhtml".equals(extension);
 
  35       isXMLFileName = "xml".equals(extension) || "xsd".equals(extension) || "dtd".equals(extension);
 
  39       if (showHTMLFilesLocal && isHTMLFileName) {
 
  40         localhostURL = previewFile.getLocation().toString();
 
  41       } else if (showXMLFilesLocal && isXMLFileName) {
 
  42         localhostURL = previewFile.getLocation().toString();
 
  43       } else if ((localhostURL = ShowExternalPreviewAction.getLocalhostURL(null, previewFile)) == null) {
 
  46       localhostURL += postFix;
 
  49         IWorkbenchPage page = WebUI.getActivePage();
 
  50         IViewPart part = page.findView(BrowserView.ID_BROWSER);
 
  52           part = page.showView(BrowserView.ID_BROWSER);
 
  54           if (bringToTopPreview) {
 
  55             page.bringToTop(part);
 
  58         ((BrowserView) part).setUrl(localhostURL);
 
  60       } catch (Exception e) {
 
  61 //        PHPeclipsePlugin.log(e);