1 package net.sourceforge.phpeclipse.wiki.editor;
3 import net.sourceforge.phpeclipse.webbrowser.views.BrowserView;
4 import net.sourceforge.phpeclipse.wiki.builder.CreatePageAction;
5 import net.sourceforge.phpeclipse.wiki.preferences.Util;
7 import org.eclipse.core.resources.IFile;
8 import org.eclipse.ui.IEditorInput;
9 import org.eclipse.ui.IFileEditorInput;
10 import org.eclipse.ui.IViewPart;
11 import org.eclipse.ui.IWorkbenchPage;
12 import org.eclipse.ui.texteditor.ITextEditor;
15 * Set browser preview URL and refresh URL Utilities
17 public class BrowserUtil {
19 public static void setBrowserPreview(ITextEditor editor) {
20 IWorkbenchPage page = WikiEditorPlugin.getDefault().getActivePage();
22 IViewPart part = page.findView(BrowserView.ID_BROWSER);
24 part = page.showView(BrowserView.ID_BROWSER);
26 // if (bringToTopPreview) {
27 // page.bringToTop(part);
30 IEditorInput editorInput = null;
32 editorInput = editor.getEditorInput();
34 if (editorInput instanceof IFileEditorInput) {
35 IFile file = ((IFileEditorInput) editorInput).getFile();
36 String srcBasePath = Util.getWikiTextsPath(file);
37 String binBasePath = Util.getProjectsWikiOutputPath(file.getProject(), WikiEditorPlugin.HTML_OUTPUT_PATH);
38 String htmlName = Util.getHTMLFileName(file, binBasePath, srcBasePath);
40 if (htmlName != null) {
41 java.io.File htmlFile = new java.io.File(htmlName);
42 if (htmlFile.exists()) {
43 ((BrowserView) part).setUrl(htmlName);
47 } catch (Exception e) {
54 public static void refreshBrowserPreview(WikiEditor editor) {
56 IWorkbenchPage page = WikiEditorPlugin.getDefault().getActivePage();
58 IViewPart part = page.findView(BrowserView.ID_BROWSER);
60 part = page.showView(BrowserView.ID_BROWSER);
62 IEditorInput editorInput = null;
63 editorInput = editor.getEditorInput();
64 if (editorInput instanceof IFileEditorInput) {
65 IFile file = ((IFileEditorInput) editorInput).getFile();
66 CreatePageAction.createPage(file);
68 String srcBasePath = Util.getWikiTextsPath(file);
69 String binBasePath = Util.getProjectsWikiOutputPath(file.getProject(), WikiEditorPlugin.HTML_OUTPUT_PATH);
70 String htmlName = Util.getHTMLFileName(file, binBasePath, srcBasePath);
71 if (htmlName != null) {
72 java.io.File htmlFile = new java.io.File(htmlName);
73 if (htmlFile.exists()) {
74 ((BrowserView) part).refresh(htmlName);
80 } catch (Exception e) {