Show browser preview only then editor area is visible
[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         /*
28          * (non-Javadoc)
29          * 
30          * @see org.eclipse.ui.IEditorActionBarContributor#setActiveEditor(org.eclipse.ui.IEditorPart)
31          */
32         public void setActiveEditor(IEditorPart part) {
33                 super.setActiveEditor(part);
34                 ITextEditor textEditor = null;
35                 if (part instanceof ITextEditor)
36                         textEditor = (ITextEditor) part;
37
38                 if (textEditor != null) {
39                         IFile file = null;
40                         IEditorInput editorInput = textEditor.getEditorInput();
41
42                         if (editorInput instanceof IFileEditorInput) {
43                                 file = ((IFileEditorInput) editorInput).getFile();
44                         }
45
46                         ShowExternalPreviewAction fShowExternalPreviewAction = ShowExternalPreviewAction.getInstance();
47                         fShowExternalPreviewAction.setEditor(textEditor);
48                         fShowExternalPreviewAction.update();
49                         if (fShowExternalPreviewAction != null)
50                                 fShowExternalPreviewAction.doRun(ShowExternalPreviewAction.SMARTY_TYPE);
51                 }
52         }
53 }