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.overlaypages.Util;
15 import net.sourceforge.phpeclipse.views.browser.BrowserView;
17 import org.eclipse.core.resources.IFile;
18 import org.eclipse.ui.IEditorInput;
19 import org.eclipse.ui.IFileEditorInput;
20 import org.eclipse.ui.IViewPart;
21 import org.eclipse.ui.IWorkbenchPage;
22 import org.eclipse.ui.PartInitException;
23 import org.eclipse.ui.texteditor.ITextEditor;
24 import org.eclipse.ui.texteditor.TextEditorAction;
25 //import org.eclipse.update.internal.ui.UpdatePerspective;
26 //import org.eclipse.update.internal.ui.views.IEmbeddedWebBrowser;
28 * ClassDeclaration that defines the action for parsing the current PHP file
30 public class ShowExternalPreviewAction extends TextEditorAction {
31 private static ShowExternalPreviewAction instance = new ShowExternalPreviewAction();
33 * Constructs and updates the action.
35 private ShowExternalPreviewAction() {
36 super(PHPEditorMessages.getResourceBundle(), "ParserAction.", null); //$NON-NLS-1$
40 public static ShowExternalPreviewAction getInstance() {
44 * Code called when the action is fired.
47 IFile fileToParse = getFile();
48 if (fileToParse == null) {
49 // should never happen
52 boolean autoPreview = Util.getPreviewBooleanValue(fileToParse,
53 IPreferenceConstants.PHP_AUTO_PREVIEW_DEFAULT);
54 boolean bringToTopPreview = Util.getPreviewBooleanValue(fileToParse,
55 IPreferenceConstants.PHP_BRING_TO_TOP_PREVIEW_DEFAULT);
58 if ((localhostURL = PHPEclipseShowAction.getLocalhostURL(null,
59 fileToParse)) == null) {
62 IWorkbenchPage page = PHPeclipsePlugin.getActivePage();
64 IViewPart part = page.findView(BrowserView.ID_BROWSER);
66 part = page.showView(BrowserView.ID_BROWSER);
68 if (bringToTopPreview) {
69 page.bringToTop(part);
72 ((BrowserView) part).setUrl(localhostURL);
74 } catch (PartInitException e) {
75 PHPeclipsePlugin.log(e);
79 public void refresh() {
80 IFile fileToParse = getFile();
81 if (fileToParse == null) {
82 // should never happen
85 boolean autoPreview = Util.getPreviewBooleanValue(fileToParse,
86 IPreferenceConstants.PHP_AUTO_PREVIEW_DEFAULT);
87 boolean bringToTopPreview = Util.getPreviewBooleanValue(fileToParse,
88 IPreferenceConstants.PHP_BRING_TO_TOP_PREVIEW_DEFAULT);
90 IWorkbenchPage page = PHPeclipsePlugin.getActivePage();
92 IViewPart part = page.findView(BrowserView.ID_BROWSER);
94 part = page.showView(BrowserView.ID_BROWSER);
96 if (bringToTopPreview) {
97 page.bringToTop(part);
100 ((BrowserView) part).refresh();
102 } catch (PartInitException e) {
103 PHPeclipsePlugin.log(e);
108 * Finds the file that's currently opened in the PHP Text Editor
110 protected IFile getFile() {
111 ITextEditor editor = getTextEditor();
112 IEditorInput editorInput = null;
113 if (editor != null) {
114 editorInput = editor.getEditorInput();
116 if (editorInput instanceof IFileEditorInput)
117 return ((IFileEditorInput) editorInput).getFile();
118 // if nothing was found, which should never happen