1 package net.sourceforge.phpeclipse.phpeditor;
3 /**********************************************************************
4 Copyright (c) 2000, 2002 IBM Corp. and others.
5 All rights reserved. This program and the accompanying materials
6 are made available under the terms of the Common Public License v1.0
7 which accompanies this distribution, and is available at
8 http://www.eclipse.org/legal/cpl-v10.html
11 IBM Corporation - Initial implementation
12 Klaus Hartlage - www.eclipseproject.de
13 **********************************************************************/
15 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
16 import net.sourceforge.phpeclipse.actions.PHPEclipseShowAction;
18 import org.eclipse.core.resources.IFile;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.ui.IEditorInput;
21 import org.eclipse.ui.IFileEditorInput;
22 import org.eclipse.ui.IViewPart;
23 import org.eclipse.ui.IWorkbenchPage;
24 import org.eclipse.ui.PartInitException;
25 import org.eclipse.ui.texteditor.ITextEditor;
26 import org.eclipse.ui.texteditor.TextEditorAction;
27 import org.eclipse.update.internal.ui.UpdatePerspective;
28 import org.eclipse.update.internal.ui.views.IEmbeddedWebBrowser;
31 * ClassDeclaration that defines the action for parsing the current PHP file
33 public class ShowExternalPreviewAction extends TextEditorAction {
35 private static ShowExternalPreviewAction instance = new ShowExternalPreviewAction();
37 protected IFile fileToParse;
40 * Constructs and updates the action.
42 private ShowExternalPreviewAction() {
43 super(PHPEditorMessages.getResourceBundle(), "ParserAction.", null); //$NON-NLS-1$
47 public static ShowExternalPreviewAction getInstance() {
52 * Code called when the action is fired.
55 fileToParse = getFile();
56 if (fileToParse == null) {
57 // should never happen
61 if (SWT.getPlatform().equals("win32")) {
63 if ((localhostURL = PHPEclipseShowAction.getLocalhostURL(null, fileToParse)) == null) {
66 IWorkbenchPage page = PHPeclipsePlugin.getActivePage();
68 IViewPart part = page.findView(UpdatePerspective.ID_BROWSER);
70 part = page.showView(UpdatePerspective.ID_BROWSER);
72 page.bringToTop(part);
73 ((IEmbeddedWebBrowser) part).openTo(localhostURL);
74 } catch (PartInitException e) {
75 PHPeclipsePlugin.log(e);
82 * Finds the file that's currently opened in the PHP Text Editor
84 protected IFile getFile() {
85 ITextEditor editor = getTextEditor();
87 IEditorInput editorInput = null;
89 editorInput = editor.getEditorInput();
92 if (editorInput instanceof IFileEditorInput)
93 return ((IFileEditorInput) editorInput).getFile();
95 // if nothing was found, which should never happen