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$
38 public static ShowExternalPreviewAction getInstance() {
42 * Code called when the action is fired.
45 IFile fileToParse = getFile();
46 if (fileToParse == null) {
47 // should never happen
50 boolean autoPreview = Util.getPreviewBooleanValue(fileToParse,
51 IPreferenceConstants.PHP_AUTO_PREVIEW_DEFAULT);
52 boolean bringToTopPreview = Util.getPreviewBooleanValue(fileToParse,
53 IPreferenceConstants.PHP_BRING_TO_TOP_PREVIEW_DEFAULT);
56 if ((localhostURL = PHPEclipseShowAction.getLocalhostURL(null,
57 fileToParse)) == null) {
60 IWorkbenchPage page = PHPeclipsePlugin.getActivePage();
62 IViewPart part = page.findView(BrowserView.ID_BROWSER);
64 part = page.showView(BrowserView.ID_BROWSER);
66 if (bringToTopPreview) {
67 page.bringToTop(part);
70 ((BrowserView) part).setUrl(localhostURL);
72 } catch (PartInitException e) {
73 PHPeclipsePlugin.log(e);
77 public void refresh() {
78 IFile fileToParse = getFile();
79 if (fileToParse == null) {
80 // should never happen
83 boolean autoPreview = Util.getPreviewBooleanValue(fileToParse,
84 IPreferenceConstants.PHP_AUTO_PREVIEW_DEFAULT);
85 boolean bringToTopPreview = Util.getPreviewBooleanValue(fileToParse,
86 IPreferenceConstants.PHP_BRING_TO_TOP_PREVIEW_DEFAULT);
88 IWorkbenchPage page = PHPeclipsePlugin.getActivePage();
90 IViewPart part = page.findView(BrowserView.ID_BROWSER);
92 part = page.showView(BrowserView.ID_BROWSER);
94 if (bringToTopPreview) {
95 page.bringToTop(part);
98 ((BrowserView) part).refresh();
100 } catch (PartInitException e) {
101 PHPeclipsePlugin.log(e);
106 * Finds the file that's currently opened in the PHP Text Editor
108 protected IFile getFile() {
109 ITextEditor editor = getTextEditor();
110 IEditorInput editorInput = null;
111 if (editor != null) {
112 editorInput = editor.getEditorInput();
114 if (editorInput instanceof IFileEditorInput)
115 return ((IFileEditorInput) editorInput).getFile();
116 // if nothing was found, which should never happen