2  * Copyright (c) 2004 Christopher Lenz 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
 
   9  *     Christopher Lenz - initial implementation
 
  11  * $Id: HTMLEditor.java,v 1.1 2004-09-02 18:25:05 jsurfer Exp $
 
  14 package net.sourceforge.phpdt.smarty.ui.internal.editor;
 
  16 import java.net.MalformedURLException;
 
  19 import net.sourceforge.phpdt.smarty.ui.internal.preview.HTMLPreviewPage;
 
  20 import net.sourceforge.phpdt.smarty.ui.internal.text.HTMLConfiguration;
 
  21 import net.sourceforge.phpeclipse.ui.views.preview.IBrowserPreviewPage;
 
  22 import net.sourceforge.phpeclipse.xml.ui.XMLPlugin;
 
  23 import net.sourceforge.phpeclipse.xml.ui.internal.editor.XMLDocumentProvider;
 
  24 import net.sourceforge.phpeclipse.xml.ui.internal.editor.XMLEditor;
 
  25 import net.sourceforge.phpeclipse.xml.ui.text.XMLTextTools;
 
  27 import org.eclipse.core.resources.IFile;
 
  28 import org.eclipse.jface.action.IAction;
 
  29 import org.eclipse.ui.IEditorInput;
 
  30 import org.eclipse.ui.IFileEditorInput;
 
  31 import org.eclipse.ui.texteditor.ContentAssistAction;
 
  32 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
 
  36  * HTML editor implementation.
 
  38 public class HTMLEditor extends XMLEditor {
 
  40         // Instance Variables ------------------------------------------------------
 
  42         /** The associated preview page. */
 
  43         private HTMLPreviewPage previewPage;
 
  45         // XMLEditor Implementation ------------------------------------------------
 
  48          * @see org.eclipse.ui.texteditor.AbstractTextEditor#editorSaved()
 
  50         protected void editorSaved() {
 
  51                 if (previewPage != null) {
 
  57          * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class)
 
  59         public Object getAdapter(Class adapter) {
 
  60                 if (adapter == IBrowserPreviewPage.class) {
 
  61                         if (previewPage == null) {
 
  62                                 previewPage = createPreviewPage();
 
  66                 return super.getAdapter(adapter);
 
  69         // Private Methods ---------------------------------------------------------
 
  72          * Creates the HTML preview page.
 
  74         private HTMLPreviewPage createPreviewPage() {
 
  75                 IEditorInput input = getEditorInput();
 
  76                 if (input instanceof IFileEditorInput) {
 
  77                         IFile file = ((IFileEditorInput) input).getFile();
 
  79                                 URL location = file.getLocation().toFile().toURL();
 
  80                                 return new HTMLPreviewPage(location);
 
  81                         } catch (MalformedURLException e) { }
 
  85         protected void createActions() {
 
  86                 super.createActions();
 
  88                 IAction action = new ContentAssistAction(HTMLEditorMessages.getResourceBundle(),
 
  89                 "ContentAssistProposal.", this); //$NON-NLS-1$
 
  91                 .setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
 
  92             setAction("ContentAssistProposal", action); //$NON-NLS-1$
 
  93             markAsStateDependentAction("ContentAssistProposal", true); //$NON-NLS-1$
 
  95 //              IAction action= new TextOperationAction(
 
  96 //                              TemplateMessages.getResourceBundle(),
 
  97 //                              "Editor." + TEMPLATE_PROPOSALS + ".", //$NON-NLS-1$ //$NON-NLS-2$
 
  99 //                              ISourceViewer.CONTENTASSIST_PROPOSALS);
 
 100 //              action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
 
 101 //              setAction(TEMPLATE_PROPOSALS, action);
 
 102 //              markAsStateDependentAction(TEMPLATE_PROPOSALS, true);
 
 105          * @see org.eclipse.ui.editors.text.TextEditor#initializeEditor()
 
 107         protected void initializeEditor() {
 
 108                 super.initializeEditor();
 
 110                 XMLTextTools xmlTextTools = XMLPlugin.getDefault().getXMLTextTools();
 
 111                 setSourceViewerConfiguration(new HTMLConfiguration(xmlTextTools, this));
 
 112                 setDocumentProvider(new XMLDocumentProvider());