package net.sourceforge.phpeclipse.wiki.editor; import net.sourceforge.phpeclipse.webbrowser.views.BrowserView; import net.sourceforge.phpeclipse.wiki.builder.CreatePageAction; import net.sourceforge.phpeclipse.wiki.preferences.Util; import org.eclipse.core.resources.IFile; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IFileEditorInput; import org.eclipse.ui.IViewPart; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.texteditor.ITextEditor; /** * Set browser preview URL and refresh URL Utilities */ public class BrowserUtil { public static void setBrowserPreview(ITextEditor editor) { IWorkbenchPage page = WikiEditorPlugin.getDefault().getActivePage(); try { IViewPart part = page.findView(BrowserView.ID_BROWSER); if (part == null) { part = page.showView(BrowserView.ID_BROWSER); } else { // if (bringToTopPreview) { // page.bringToTop(part); // } } IEditorInput editorInput = null; if (editor != null) { editorInput = editor.getEditorInput(); } if (editorInput instanceof IFileEditorInput) { IFile file = ((IFileEditorInput) editorInput).getFile(); String srcBasePath = Util.getWikiTextsPath(file); String binBasePath = Util.getProjectsWikiOutputPath(file.getProject(), WikiEditorPlugin.HTML_OUTPUT_PATH); String htmlName = Util.getHTMLFileName(file, binBasePath, srcBasePath); if (htmlName != null) { java.io.File htmlFile = new java.io.File(htmlName); if (htmlFile.exists()) { ((BrowserView) part).setUrl(htmlName); } } } } catch (Exception e) { } } /** * */ public static void refreshBrowserPreview(WikiEditor editor) { IWorkbenchPage page = WikiEditorPlugin.getDefault().getActivePage(); try { IViewPart part = page.findView(BrowserView.ID_BROWSER); if (part == null) { part = page.showView(BrowserView.ID_BROWSER); } else { IEditorInput editorInput = null; editorInput = editor.getEditorInput(); if (editorInput instanceof IFileEditorInput) { IFile file = ((IFileEditorInput) editorInput).getFile(); CreatePageAction.createPage(file); String srcBasePath = Util.getWikiTextsPath(file); String binBasePath = Util.getProjectsWikiOutputPath(file.getProject(), WikiEditorPlugin.HTML_OUTPUT_PATH); String htmlName = Util.getHTMLFileName(file, binBasePath, srcBasePath); if (htmlName != null) { java.io.File htmlFile = new java.io.File(htmlName); if (htmlFile.exists()) { ((BrowserView) part).refresh(htmlName); } } } } } catch (Exception e) { } } }