misc changes
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.html.ui / src / net / sourceforge / phpeclipse / html / ui / internal / editor / HTMLEditorActionContributor.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpeclipse.html.ui.internal.editor;
12
13 import net.sourceforge.phpeclipse.ui.editor.ShowExternalPreviewAction;
14
15 import org.eclipse.core.resources.IFile;
16 import org.eclipse.ui.IEditorInput;
17 import org.eclipse.ui.IEditorPart;
18 import org.eclipse.ui.IFileEditorInput;
19 import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
20 import org.eclipse.ui.texteditor.ITextEditor;
21
22 /**
23  * Common base class for action contributors for Java editors.
24  */
25 public class HTMLEditorActionContributor extends BasicTextEditorActionContributor {
26         
27   /* (non-Javadoc)
28    * @see org.eclipse.ui.IEditorActionBarContributor#setActiveEditor(org.eclipse.ui.IEditorPart)
29    */
30   public void setActiveEditor(IEditorPart part) {
31     super.setActiveEditor(part);
32     ITextEditor textEditor = null;
33     if (part instanceof ITextEditor)
34       textEditor = (ITextEditor) part;
35
36     if (textEditor != null) {
37       IFile file = null;
38       IEditorInput editorInput = textEditor.getEditorInput();
39
40       if (editorInput instanceof IFileEditorInput) {
41         file = ((IFileEditorInput) editorInput).getFile();
42       }
43
44       ShowExternalPreviewAction fShowExternalPreviewAction = ShowExternalPreviewAction.getInstance();
45       fShowExternalPreviewAction.setEditor(textEditor);
46       fShowExternalPreviewAction.update();
47       if (fShowExternalPreviewAction != null)
48         fShowExternalPreviewAction.doRun(ShowExternalPreviewAction.HTML_TYPE);
49     }
50   }
51 }