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);
 
  71       } catch (PartInitException e) {
 
  72         PHPeclipsePlugin.log(e);
 
  77    * Finds the file that's currently opened in the PHP Text Editor
 
  79   protected IFile getFile() {
 
  80     ITextEditor editor = getTextEditor();
 
  81     IEditorInput editorInput = null;
 
  83       editorInput = editor.getEditorInput();
 
  85     if (editorInput instanceof IFileEditorInput)
 
  86       return ((IFileEditorInput) editorInput).getFile();
 
  87     // if nothing was found, which should never happen