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.webbrowser.views.BrowserView;
11 import net.sourceforge.phpeclipse.wiki.builder.CreatePageAction;
12 import net.sourceforge.phpeclipse.wiki.editor.model.WikipediaSection;
13 import net.sourceforge.phpeclipse.wiki.editor.model.WikipediaText;
14 import net.sourceforge.phpeclipse.wiki.preferences.Util;
16 import org.eclipse.jface.action.IAction;
17 import org.eclipse.jface.text.IDocument;
18 import org.eclipse.jface.text.source.ISourceViewer;
19 import org.eclipse.jface.text.source.IVerticalRuler;
20 import org.eclipse.jface.text.source.projection.ProjectionSupport;
21 import org.eclipse.jface.text.source.projection.ProjectionViewer;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.ui.IEditorInput;
24 import org.eclipse.ui.IFileEditorInput;
25 import org.eclipse.ui.IViewPart;
26 import org.eclipse.ui.IWorkbenchPage;
27 import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;
28 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
29 import org.eclipse.ui.texteditor.TextOperationAction;
30 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
32 public class WikiEditor extends AbstractDecoratedTextEditor {
34 private WikiOutlinePage fOutlinePage;
36 private WikipediaSection fSection;
38 private ProjectionSupport fProjectionSupport;
40 private WikiOccurrencesUpdater fOccurrencesUpdater;
43 setSourceViewerConfiguration(new WikiSourceViewerConfiguration(this, getSharedColors()));
46 public WikipediaSection getSection() {
50 public void setSection(WikipediaSection section) {
52 if (fOutlinePage != null)
53 fOutlinePage.setWiki(section);
55 if (fOccurrencesUpdater != null)
56 fOccurrencesUpdater.update(getSourceViewer());
60 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
62 public Object getAdapter(Class required) {
63 if (IContentOutlinePage.class.equals(required)) {
64 if (fOutlinePage == null)
65 fOutlinePage = new WikiOutlinePage(this);
68 if (fProjectionSupport != null) {
69 Object adapter = fProjectionSupport.getAdapter(getSourceViewer(), required);
73 return super.getAdapter(required);
76 public void outlinePageClosed() {
81 * @see org.eclipse.ui.texteditor.AbstractTextEditor#createActions()
83 protected void createActions() {
84 super.createActions();
86 IAction action = new TextOperationAction(WikiEditorPlugin.getDefault().getResourceBundle(), "ContentAssistProposal.", this,
87 ISourceViewer.CONTENTASSIST_PROPOSALS);
88 action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
89 setAction("ContentAssist.", action);
90 markAsStateDependentAction("ContentAssist.", true);
94 * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createPartControl(org.eclipse.swt.widgets.Composite)
96 public void createPartControl(Composite parent) {
97 super.createPartControl(parent);
99 ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer();
100 fProjectionSupport = new ProjectionSupport(projectionViewer, getAnnotationAccess(), getSharedColors());
101 fProjectionSupport.install();
102 projectionViewer.doOperation(ProjectionViewer.TOGGLE);
104 fOccurrencesUpdater = new WikiOccurrencesUpdater(this);
108 * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createSourceViewer(org.eclipse.swt.widgets.Composite,
109 * org.eclipse.jface.text.source.IVerticalRuler, int)
111 protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
112 fAnnotationAccess = createAnnotationAccess();
113 fOverviewRuler = createOverviewRuler(getSharedColors());
115 ISourceViewer viewer = new ProjectionViewer(parent, ruler, fOverviewRuler, true, styles);
116 // ensure decoration support has been created and configured:
117 getSourceViewerDecorationSupport(viewer);
123 * @see org.eclipse.ui.IWorkbenchPart#dispose()
125 public void dispose() {
126 fOccurrencesUpdater.dispose();
130 public IDocument getDocument() {
131 IDocument doc = getDocumentProvider().getDocument(getEditorInput());
138 * @see org.eclipse.ui.texteditor.AbstractTextEditor#editorSaved()
140 protected void editorSaved() {
142 // doesn't work here, wikibuilder has to be finished with generating html page
143 IWorkbenchPage page = WikiEditorPlugin.getDefault().getActivePage();
145 IViewPart part = page.findView(BrowserView.ID_BROWSER);
147 part = page.showView(BrowserView.ID_BROWSER);
149 // if (bringToTopPreview) {
150 // page.bringToTop(part);
153 IEditorInput editorInput = null;
154 editorInput = this.getEditorInput();
155 if (editorInput instanceof IFileEditorInput) {
156 CreatePageAction.createPage(((IFileEditorInput) editorInput).getFile());
157 ((BrowserView) part).refresh();
159 } catch (Exception e) {