4ccff01e3e9f5efb4feb0ea7db2fa3f4e1164d99
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.html.ui / src / net / sourceforge / phpeclipse / html / ui / internal / editor / HTMLEditor.java
1 /*
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
7  * 
8  * Contributors:
9  *     Christopher Lenz - initial implementation
10  * 
11  * $Id: HTMLEditor.java,v 1.1 2004-09-02 18:13:32 jsurfer Exp $
12  */
13
14 package net.sourceforge.phpeclipse.html.ui.internal.editor;
15
16 import java.net.MalformedURLException;
17 import java.net.URL;
18
19 import net.sourceforge.phpeclipse.html.ui.internal.preview.HTMLPreviewPage;
20 import net.sourceforge.phpeclipse.html.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;
26
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;
33
34
35 /**
36  * HTML editor implementation.
37  */
38 public class HTMLEditor extends XMLEditor {
39
40         // Instance Variables ------------------------------------------------------
41         
42         /** The associated preview page. */
43         private HTMLPreviewPage previewPage;
44
45         // XMLEditor Implementation ------------------------------------------------
46
47         /* 
48          * @see org.eclipse.ui.texteditor.AbstractTextEditor#editorSaved()
49          */
50         protected void editorSaved() {
51                 if (previewPage != null) {
52                         previewPage.update();
53                 }
54         }
55
56         /* 
57          * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class)
58          */
59         public Object getAdapter(Class adapter) {
60                 if (adapter == IBrowserPreviewPage.class) {
61                         if (previewPage == null) {
62                                 previewPage = createPreviewPage();
63                         }
64                         return previewPage;
65                 }
66                 return super.getAdapter(adapter);
67         }
68
69         // Private Methods ---------------------------------------------------------
70
71         /**
72          * Creates the HTML preview page.
73          */
74         private HTMLPreviewPage createPreviewPage() {
75                 IEditorInput input = getEditorInput();
76                 if (input instanceof IFileEditorInput) {
77                         IFile file = ((IFileEditorInput) input).getFile();
78                         try {
79                                 URL location = file.getLocation().toFile().toURL();
80                                 return new HTMLPreviewPage(location);
81                         } catch (MalformedURLException e) { }
82                 }
83                 return null;
84         }
85         protected void createActions() {
86                 super.createActions();
87
88                 IAction action = new ContentAssistAction(HTMLEditorMessages.getResourceBundle(),
89                 "ContentAssistProposal.", this); //$NON-NLS-1$
90             action
91                 .setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
92             setAction("ContentAssistProposal", action); //$NON-NLS-1$
93             markAsStateDependentAction("ContentAssistProposal", true); //$NON-NLS-1$
94             
95 //              IAction action= new TextOperationAction(
96 //                              TemplateMessages.getResourceBundle(),
97 //                              "Editor." + TEMPLATE_PROPOSALS + ".", //$NON-NLS-1$ //$NON-NLS-2$
98 //                              this,
99 //                              ISourceViewer.CONTENTASSIST_PROPOSALS);
100 //              action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
101 //              setAction(TEMPLATE_PROPOSALS, action);
102 //              markAsStateDependentAction(TEMPLATE_PROPOSALS, true);
103         }
104         /*
105          * @see org.eclipse.ui.editors.text.TextEditor#initializeEditor()
106          */
107         protected void initializeEditor() {
108                 super.initializeEditor();
109
110                 XMLTextTools xmlTextTools = XMLPlugin.getDefault().getXMLTextTools();
111                 setSourceViewerConfiguration(new HTMLConfiguration(xmlTextTools, this));
112                 setDocumentProvider(new XMLDocumentProvider());
113         }
114 }