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) {
21 IWorkbenchPage page = WikiEditorPlugin.getDefault().getActivePage();
23 IViewPart part = page.findView(BrowserView.ID_BROWSER);
25 part = page.showView(BrowserView.ID_BROWSER);
27 // if (bringToTopPreview) {
28 // page.bringToTop(part);
31 IEditorInput editorInput = null;
33 editorInput = editor.getEditorInput();
35 if (editorInput instanceof IFileEditorInput) {
36 IFile file = ((IFileEditorInput) editorInput).getFile();
37 String srcBasePath = Util.getWikiTextsPath(file);
38 String binBasePath = Util.getProjectsWikiOutputPath(file.getProject(), WikiEditorPlugin.HTML_OUTPUT_PATH);
39 String htmlName = Util.getHTMLFileName(file, binBasePath, srcBasePath);
41 if (htmlName != null) {
42 java.io.File htmlFile = new java.io.File(htmlName);
43 if (htmlFile.exists()) {
44 ((BrowserView) part).setUrl(htmlName);
48 } catch (Exception e) {
55 public static void refreshBrowserPreview(WikiEditor editor) {
57 IWorkbenchPage page = WikiEditorPlugin.getDefault().getActivePage();
59 IViewPart part = page.findView(BrowserView.ID_BROWSER);
61 part = page.showView(BrowserView.ID_BROWSER);
63 IEditorInput editorInput = null;
64 editorInput = editor.getEditorInput();
65 if (editorInput instanceof IFileEditorInput) {
66 IFile file = ((IFileEditorInput) editorInput).getFile();
67 CreatePageAction.createPage(file);
69 String srcBasePath = Util.getWikiTextsPath(file);
70 String binBasePath = Util.getProjectsWikiOutputPath(file.getProject(), WikiEditorPlugin.HTML_OUTPUT_PATH);
71 String htmlName = Util.getHTMLFileName(file, binBasePath, srcBasePath);
72 if (htmlName != null) {
73 java.io.File htmlFile = new java.io.File(htmlName);
74 if (htmlFile.exists()) {
75 ((BrowserView) part).refresh(htmlName);
81 } catch (Exception e) {