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.phpeclipse.IPreferenceConstants;
12 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
13 import net.sourceforge.phpeclipse.actions.PHPEclipseShowAction;
14 import net.sourceforge.phpeclipse.views.browser.BrowserView;
15 import org.eclipse.core.resources.IFile;
16 import org.eclipse.ui.IEditorInput;
17 import org.eclipse.ui.IFileEditorInput;
18 import org.eclipse.ui.IViewPart;
19 import org.eclipse.ui.IWorkbenchPage;
20 import org.eclipse.ui.PartInitException;
21 import org.eclipse.ui.texteditor.ITextEditor;
22 import org.eclipse.ui.texteditor.TextEditorAction;
23 import net.sourceforge.phpeclipse.overlaypages.Util;
24 //import org.eclipse.update.internal.ui.UpdatePerspective;
25 //import org.eclipse.update.internal.ui.views.IEmbeddedWebBrowser;
27 * ClassDeclaration that defines the action for parsing the current PHP file
29 public class ShowExternalPreviewAction extends TextEditorAction {
30 private static ShowExternalPreviewAction instance = new ShowExternalPreviewAction();
32 * Constructs and updates the action.
34 private ShowExternalPreviewAction() {
35 super(PHPEditorMessages.getResourceBundle(), "ParserAction.", null); //$NON-NLS-1$
39 public static ShowExternalPreviewAction getInstance() {
43 * Code called when the action is fired.
46 IFile fileToParse = getFile();
47 if (fileToParse == null) {
48 // should never happen
51 boolean autoPreview = Util.getPreviewBooleanValue(fileToParse,
52 IPreferenceConstants.PHP_AUTO_PREVIEW_DEFAULT);
53 boolean bringToTopPreview = Util.getPreviewBooleanValue(fileToParse,
54 IPreferenceConstants.PHP_BRING_TO_TOP_PREVIEW_DEFAULT);
57 if ((localhostURL = PHPEclipseShowAction.getLocalhostURL(null,
58 fileToParse)) == null) {
61 IWorkbenchPage page = PHPeclipsePlugin.getActivePage();
63 IViewPart part = page.findView(BrowserView.ID_BROWSER);
65 part = page.showView(BrowserView.ID_BROWSER);
67 if (bringToTopPreview) {
68 page.bringToTop(part);
71 ((BrowserView) part).setUrl(localhostURL);
73 } catch (PartInitException e) {
74 PHPeclipsePlugin.log(e);
78 public void refresh() {
79 IFile fileToParse = getFile();
80 if (fileToParse == null) {
81 // should never happen
84 boolean autoPreview = Util.getPreviewBooleanValue(fileToParse,
85 IPreferenceConstants.PHP_AUTO_PREVIEW_DEFAULT);
86 boolean bringToTopPreview = Util.getPreviewBooleanValue(fileToParse,
87 IPreferenceConstants.PHP_BRING_TO_TOP_PREVIEW_DEFAULT);
89 IWorkbenchPage page = PHPeclipsePlugin.getActivePage();
91 IViewPart part = page.findView(BrowserView.ID_BROWSER);
93 part = page.showView(BrowserView.ID_BROWSER);
95 if (bringToTopPreview) {
96 page.bringToTop(part);
99 ((BrowserView) part).refresh();
101 } catch (PartInitException e) {
102 PHPeclipsePlugin.log(e);
107 * Finds the file that's currently opened in the PHP Text Editor
109 protected IFile getFile() {
110 ITextEditor editor = getTextEditor();
111 IEditorInput editorInput = null;
112 if (editor != null) {
113 editorInput = editor.getEditorInput();
115 if (editorInput instanceof IFileEditorInput)
116 return ((IFileEditorInput) editorInput).getFile();
117 // if nothing was found, which should never happen