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.PHPeclipsePlugin;
12 import net.sourceforge.phpeclipse.actions.PHPEclipseShowAction;
13 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 org.eclipse.update.internal.ui.UpdatePerspective;
24 //import org.eclipse.update.internal.ui.views.IEmbeddedWebBrowser;
26 * ClassDeclaration that defines the action for parsing the current PHP file
28 public class ShowExternalPreviewAction extends TextEditorAction {
29 private static ShowExternalPreviewAction instance = new ShowExternalPreviewAction();
30 protected IFile fileToParse;
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 fileToParse = getFile();
46 if (fileToParse == null) {
47 // should never happen
51 if ((localhostURL = PHPEclipseShowAction.getLocalhostURL(null, fileToParse)) == null) {
54 IWorkbenchPage page = PHPeclipsePlugin.getActivePage();
56 IViewPart part = page.findView(BrowserView.ID_BROWSER);
58 part = page.showView(BrowserView.ID_BROWSER);
60 page.bringToTop(part);
62 ((BrowserView) part).setUrl(localhostURL);
63 } catch (PartInitException e) {
64 PHPeclipsePlugin.log(e);
68 * Finds the file that's currently opened in the PHP Text Editor
70 protected IFile getFile() {
71 ITextEditor editor = getTextEditor();
72 IEditorInput editorInput = null;
74 editorInput = editor.getEditorInput();
76 if (editorInput instanceof IFileEditorInput)
77 return ((IFileEditorInput) editorInput).getFile();
78 // if nothing was found, which should never happen