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.UpdateUIPlugin;
29 import org.eclipse.update.internal.ui.views.IEmbeddedWebBrowser;
32 * ClassDeclaration that defines the action for parsing the current PHP file
34 public class ShowExternalPreviewAction extends TextEditorAction {
36 private static ShowExternalPreviewAction instance = new ShowExternalPreviewAction();
38 protected IFile fileToParse;
41 * Constructs and updates the action.
43 private ShowExternalPreviewAction() {
44 super(PHPEditorMessages.getResourceBundle(), "ParserAction.", null); //$NON-NLS-1$
48 public static ShowExternalPreviewAction getInstance() {
53 * Code called when the action is fired.
56 fileToParse = getFile();
57 if (fileToParse == null) {
58 // should never happen
62 if (SWT.getPlatform().equals("win32")) {
64 if ((localhostURL = PHPEclipseShowAction.getLocalhostURL(null, fileToParse)) == null) {
67 IWorkbenchPage page = PHPeclipsePlugin.getActivePage();
69 IViewPart part = page.findView(UpdatePerspective.ID_BROWSER);
71 part = page.showView(UpdatePerspective.ID_BROWSER);
73 page.bringToTop(part);
74 ((IEmbeddedWebBrowser) part).openTo(localhostURL);
75 } catch (PartInitException e) {
76 UpdateUIPlugin.logException(e);
83 * Finds the file that's currently opened in the PHP Text Editor
85 protected IFile getFile() {
86 ITextEditor editor = getTextEditor();
88 IEditorInput editorInput = null;
90 editorInput = editor.getEditorInput();
93 if (editorInput instanceof IFileEditorInput)
94 return ((IFileEditorInput) editorInput).getFile();
96 // if nothing was found, which should never happen