Include icons in feature build.
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpeclipse / ui / editor / BrowserUtil.java
1 package net.sourceforge.phpeclipse.ui.editor;
2
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;
7
8 import org.eclipse.core.resources.IFile;
9 import org.eclipse.ui.IViewPart;
10 import org.eclipse.ui.IWorkbenchPage;
11
12 public class BrowserUtil {
13
14         public static void showPreview(IFile previewFile, boolean forceDBGPreview, String postFix) {
15                 if (previewFile == null) {
16                         // should never happen
17                         return;
18                 }
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);
29
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);
34                         }
35                         if (autoPreview) {
36                                 String localhostURL;
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) {
42                                         return;
43                                 }
44                                 localhostURL += postFix;
45
46                                 try {
47                                         IViewPart part = page.showView(BrowserView.ID_BROWSER, null, IWorkbenchPage.VIEW_VISIBLE);
48                                         if (part == null) {
49                                                 part = page.showView(BrowserView.ID_BROWSER);
50                                         } else {
51                                                 page.bringToTop(part);
52                                         }
53                                         ((BrowserView) part).setUrl(localhostURL);
54
55                                 } catch (Exception e) {
56                                         // PHPeclipsePlugin.log(e);
57                                 }
58                         }
59                 }
60         }
61
62 }