1 /***********************************************************************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made
3 * available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at
4 * http://www.eclipse.org/legal/cpl-v10.html
6 * Contributors: IBM Corporation - initial API and implementation
7 **********************************************************************************************************************************/
8 package net.sourceforge.phpeclipse.wiki.editor;
10 import net.sourceforge.phpeclipse.wiki.editor.model.WikipediaSection;
12 import org.eclipse.jface.action.IAction;
13 import org.eclipse.jface.text.IDocument;
14 import org.eclipse.jface.text.source.ISourceViewer;
15 import org.eclipse.jface.text.source.IVerticalRuler;
16 import org.eclipse.jface.text.source.projection.ProjectionSupport;
17 import org.eclipse.jface.text.source.projection.ProjectionViewer;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;
20 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
21 import org.eclipse.ui.texteditor.TextOperationAction;
22 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
24 public class WikiEditor extends AbstractDecoratedTextEditor {
26 private WikiOutlinePage fOutlinePage;
28 private WikipediaSection fSection;
30 private ProjectionSupport fProjectionSupport;
32 private WikiOccurrencesUpdater fOccurrencesUpdater;
35 setSourceViewerConfiguration(new WikiSourceViewerConfiguration(this, getSharedColors()));
38 public WikipediaSection getSection() {
42 public void setSection(WikipediaSection section) {
44 if (fOutlinePage != null)
45 fOutlinePage.setWiki(section);
47 if (fOccurrencesUpdater != null)
48 fOccurrencesUpdater.update(getSourceViewer());
52 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
54 public Object getAdapter(Class required) {
55 if (IContentOutlinePage.class.equals(required)) {
56 if (fOutlinePage == null)
57 fOutlinePage = new WikiOutlinePage(this);
60 if (fProjectionSupport != null) {
61 Object adapter = fProjectionSupport.getAdapter(getSourceViewer(), required);
65 return super.getAdapter(required);
68 public void outlinePageClosed() {
73 * @see org.eclipse.ui.texteditor.AbstractTextEditor#createActions()
75 protected void createActions() {
76 super.createActions();
78 IAction action = new TextOperationAction(WikiEditorPlugin.getDefault().getResourceBundle(), "ContentAssistProposal.", this,
79 ISourceViewer.CONTENTASSIST_PROPOSALS);
80 action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
81 setAction("ContentAssist.", action);
82 markAsStateDependentAction("ContentAssist.", true);
86 * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createPartControl(org.eclipse.swt.widgets.Composite)
88 public void createPartControl(Composite parent) {
89 super.createPartControl(parent);
91 ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer();
92 fProjectionSupport = new ProjectionSupport(projectionViewer, getAnnotationAccess(), getSharedColors());
93 fProjectionSupport.install();
94 projectionViewer.doOperation(ProjectionViewer.TOGGLE);
96 fOccurrencesUpdater = new WikiOccurrencesUpdater(this);
100 * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createSourceViewer(org.eclipse.swt.widgets.Composite,
101 * org.eclipse.jface.text.source.IVerticalRuler, int)
103 protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
104 fAnnotationAccess = createAnnotationAccess();
105 fOverviewRuler = createOverviewRuler(getSharedColors());
107 ISourceViewer viewer = new ProjectionViewer(parent, ruler, fOverviewRuler, true, styles);
108 // ensure decoration support has been created and configured:
109 getSourceViewerDecorationSupport(viewer);
115 * @see org.eclipse.ui.IWorkbenchPart#dispose()
117 public void dispose() {
118 fOccurrencesUpdater.dispose();
122 public IDocument getDocument() {
123 IDocument doc = getDocumentProvider().getDocument(getEditorInput());
130 * @see org.eclipse.ui.texteditor.AbstractTextEditor#editorSaved()
132 protected void editorSaved() {
134 BrowserUtil.refreshBrowserPreview(this);