1 package net.sourceforge.phpeclipse.phpeditor;
2 /*******************************************************************************
3 * Copyright (c) 2000, 2002 IBM Corp. and others. All rights reserved. This
4 * program and the accompanying materials are made available under the terms of
5 * the Common Public License v1.0 which accompanies this distribution, and is
6 * available at http://www.eclipse.org/legal/cpl-v10.html
8 * Contributors: IBM Corporation - Initial implementation Klaus Hartlage -
9 * www.eclipseproject.de
10 ******************************************************************************/
11 import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
12 import net.sourceforge.phpeclipse.IPreferenceConstants;
13 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
14 import net.sourceforge.phpeclipse.actions.PHPEclipseShowAction;
15 import net.sourceforge.phpeclipse.overlaypages.Util;
16 import net.sourceforge.phpeclipse.views.browser.BrowserView;
18 import org.eclipse.core.resources.IFile;
19 import org.eclipse.ui.IEditorInput;
20 import org.eclipse.ui.IFileEditorInput;
21 import org.eclipse.ui.IViewPart;
22 import org.eclipse.ui.IWorkbenchPage;
23 import org.eclipse.ui.PartInitException;
24 import org.eclipse.ui.texteditor.ITextEditor;
25 import org.eclipse.ui.texteditor.TextEditorAction;
26 //import org.eclipse.update.internal.ui.UpdatePerspective;
27 //import org.eclipse.update.internal.ui.views.IEmbeddedWebBrowser;
29 * ClassDeclaration that defines the action for parsing the current PHP file
31 public class ShowExternalPreviewAction extends TextEditorAction {
32 private static ShowExternalPreviewAction instance = new ShowExternalPreviewAction();
34 * Constructs and updates the action.
36 private ShowExternalPreviewAction() {
37 super(PHPEditorMessages.getResourceBundle(), "ParserAction.", null); //$NON-NLS-1$
41 public static ShowExternalPreviewAction getInstance() {
45 * Code called when the action is fired.
48 IFile previewFile = getFile();
49 if (previewFile == null) {
50 // should never happen
53 boolean autoPreview = Util.getPreviewBooleanValue(previewFile,
54 IPreferenceConstants.PHP_AUTO_PREVIEW_DEFAULT);
55 boolean bringToTopPreview = Util.getPreviewBooleanValue(previewFile,
56 IPreferenceConstants.PHP_BRING_TO_TOP_PREVIEW_DEFAULT);
57 boolean showHTMLFilesLocal = Util.getPreviewBooleanValue(previewFile,
58 IPreferenceConstants.PHP_SHOW_HTML_FILES_LOCAL);
59 boolean isPHPFileName = PHPFileUtil.isPHPFileName(previewFile.getLocation().toString());
63 if (showHTMLFilesLocal && (!isPHPFileName)) {
64 localhostURL = previewFile.getLocation().toString();
65 } else if ((localhostURL = PHPEclipseShowAction.getLocalhostURL(null,
66 previewFile)) == null) {
69 IWorkbenchPage page = PHPeclipsePlugin.getActivePage();
71 IViewPart part = page.findView(BrowserView.ID_BROWSER);
73 part = page.showView(BrowserView.ID_BROWSER);
75 if (bringToTopPreview) {
76 page.bringToTop(part);
79 ((BrowserView) part).setUrl(localhostURL);
81 } catch (PartInitException e) {
82 PHPeclipsePlugin.log(e);
87 public void refresh() {
88 IFile fileToParse = getFile();
89 if (fileToParse == null) {
90 // should never happen
93 boolean autoPreview = Util.getPreviewBooleanValue(fileToParse,
94 IPreferenceConstants.PHP_AUTO_PREVIEW_DEFAULT);
95 boolean bringToTopPreview = Util.getPreviewBooleanValue(fileToParse,
96 IPreferenceConstants.PHP_BRING_TO_TOP_PREVIEW_DEFAULT);
98 IWorkbenchPage page = PHPeclipsePlugin.getActivePage();
100 IViewPart part = page.findView(BrowserView.ID_BROWSER);
102 part = page.showView(BrowserView.ID_BROWSER);
104 if (bringToTopPreview) {
105 page.bringToTop(part);
108 ((BrowserView) part).refresh();
110 } catch (PartInitException e) {
111 PHPeclipsePlugin.log(e);
116 * Finds the file that's currently opened in the PHP Text Editor
118 protected IFile getFile() {
119 ITextEditor editor = getTextEditor();
120 IEditorInput editorInput = null;
121 if (editor != null) {
122 editorInput = editor.getEditorInput();
124 if (editorInput instanceof IFileEditorInput)
125 return ((IFileEditorInput) editorInput).getFile();
126 // if nothing was found, which should never happen