5b565d57010606b472fdba052e9c10c3f5bf4c1c
[phpeclipse.git] / net.sourceforge.phpeclipse.smarty.ui / src / net / sourceforge / phpdt / smarty / ui / internal / editor / SmartyEditorActionContributor.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.phpdt.smarty.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 SmartyEditorActionContributor 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.SMARTY_TYPE);
49     }
50   }
51 }