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;
11 import net.sourceforge.phpeclipse.wiki.editor.model.WikipediaText;
12 import net.sourceforge.phpeclipse.wiki.preferences.Util;
14 import org.eclipse.jface.action.IAction;
15 import org.eclipse.jface.text.IDocument;
16 import org.eclipse.jface.text.source.ISourceViewer;
17 import org.eclipse.jface.text.source.IVerticalRuler;
18 import org.eclipse.jface.text.source.projection.ProjectionSupport;
19 import org.eclipse.jface.text.source.projection.ProjectionViewer;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;
22 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
23 import org.eclipse.ui.texteditor.TextOperationAction;
24 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
26 public class WikiEditor extends AbstractDecoratedTextEditor {
28 private WikiOutlinePage fOutlinePage;
30 private WikipediaSection fSection;
32 private ProjectionSupport fProjectionSupport;
34 private WikiOccurrencesUpdater fOccurrencesUpdater;
37 setSourceViewerConfiguration(new WikiSourceViewerConfiguration(this, getSharedColors()));
40 public WikipediaSection getSection() {
44 public void setSection(WikipediaSection section) {
46 if (fOutlinePage != null)
47 fOutlinePage.setWiki(section);
49 if (fOccurrencesUpdater != null)
50 fOccurrencesUpdater.update(getSourceViewer());
54 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
56 public Object getAdapter(Class required) {
57 if (IContentOutlinePage.class.equals(required)) {
58 if (fOutlinePage == null)
59 fOutlinePage = new WikiOutlinePage(this);
62 if (fProjectionSupport != null) {
63 Object adapter = fProjectionSupport.getAdapter(getSourceViewer(), required);
67 return super.getAdapter(required);
70 public void outlinePageClosed() {
75 * @see org.eclipse.ui.texteditor.AbstractTextEditor#createActions()
77 protected void createActions() {
78 super.createActions();
80 IAction action = new TextOperationAction(WikiEditorPlugin.getDefault().getResourceBundle(), "ContentAssistProposal.", this,
81 ISourceViewer.CONTENTASSIST_PROPOSALS);
82 action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
83 setAction("ContentAssist.", action);
84 markAsStateDependentAction("ContentAssist.", true);
88 * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createPartControl(org.eclipse.swt.widgets.Composite)
90 public void createPartControl(Composite parent) {
91 super.createPartControl(parent);
93 ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer();
94 fProjectionSupport = new ProjectionSupport(projectionViewer, getAnnotationAccess(), getSharedColors());
95 fProjectionSupport.install();
96 projectionViewer.doOperation(ProjectionViewer.TOGGLE);
98 fOccurrencesUpdater = new WikiOccurrencesUpdater(this);
102 * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createSourceViewer(org.eclipse.swt.widgets.Composite,
103 * org.eclipse.jface.text.source.IVerticalRuler, int)
105 protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
106 fAnnotationAccess = createAnnotationAccess();
107 fOverviewRuler = createOverviewRuler(getSharedColors());
109 ISourceViewer viewer = new ProjectionViewer(parent, ruler, fOverviewRuler, true, styles);
110 // ensure decoration support has been created and configured:
111 getSourceViewerDecorationSupport(viewer);
117 * @see org.eclipse.ui.IWorkbenchPart#dispose()
119 public void dispose() {
120 fOccurrencesUpdater.dispose();
124 public IDocument getDocument() {
125 IDocument doc = getDocumentProvider().getDocument(getEditorInput());
132 * @see org.eclipse.ui.texteditor.AbstractTextEditor#editorSaved()
134 protected void editorSaved() {
136 BrowserUtil.refreshBrowserPreview(this);