Handle the new "wpEditToken" input parameter for upload
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.wiki / src / net / sourceforge / phpeclipse / wiki / editor / WikiEditor.java
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
5  * 
6  * Contributors: IBM Corporation - initial API and implementation
7  **********************************************************************************************************************************/
8 package net.sourceforge.phpeclipse.wiki.editor;
9
10 import net.sourceforge.phpeclipse.wiki.editor.model.WikipediaSection;
11
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;
23
24 public class WikiEditor extends AbstractDecoratedTextEditor {
25
26   private WikiOutlinePage fOutlinePage;
27
28   private WikipediaSection fSection;
29
30   private ProjectionSupport fProjectionSupport;
31
32   private WikiOccurrencesUpdater fOccurrencesUpdater;
33
34   public WikiEditor() {
35     setSourceViewerConfiguration(new WikiSourceViewerConfiguration(this, getSharedColors()));
36   }
37
38   public WikipediaSection getSection() {
39     return fSection;
40   }
41
42   public void setSection(WikipediaSection section) {
43     fSection = section;
44     if (fOutlinePage != null)
45       fOutlinePage.setWiki(section);
46
47     if (fOccurrencesUpdater != null)
48       fOccurrencesUpdater.update(getSourceViewer());
49   }
50
51   /*
52    * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
53    */
54   public Object getAdapter(Class required) {
55     if (IContentOutlinePage.class.equals(required)) {
56       if (fOutlinePage == null)
57         fOutlinePage = new WikiOutlinePage(this);
58       return fOutlinePage;
59     }
60     if (fProjectionSupport != null) {
61       Object adapter = fProjectionSupport.getAdapter(getSourceViewer(), required);
62       if (adapter != null)
63         return adapter;
64     }
65     return super.getAdapter(required);
66   }
67
68   public void outlinePageClosed() {
69     fOutlinePage = null;
70   }
71
72   /*
73    * @see org.eclipse.ui.texteditor.AbstractTextEditor#createActions()
74    */
75   protected void createActions() {
76     super.createActions();
77
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);
83   }
84
85   /*
86    * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createPartControl(org.eclipse.swt.widgets.Composite)
87    */
88   public void createPartControl(Composite parent) {
89     super.createPartControl(parent);
90
91     ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer();
92     fProjectionSupport = new ProjectionSupport(projectionViewer, getAnnotationAccess(), getSharedColors());
93     fProjectionSupport.install();
94     projectionViewer.doOperation(ProjectionViewer.TOGGLE);
95
96     fOccurrencesUpdater = new WikiOccurrencesUpdater(this);
97   }
98
99   /*
100    * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createSourceViewer(org.eclipse.swt.widgets.Composite,
101    *      org.eclipse.jface.text.source.IVerticalRuler, int)
102    */
103   protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
104     fAnnotationAccess = createAnnotationAccess();
105     fOverviewRuler = createOverviewRuler(getSharedColors());
106
107     ISourceViewer viewer = new ProjectionViewer(parent, ruler, fOverviewRuler, true, styles);
108     // ensure decoration support has been created and configured:
109     getSourceViewerDecorationSupport(viewer);
110
111     return viewer;
112   }
113
114   /*
115    * @see org.eclipse.ui.IWorkbenchPart#dispose()
116    */
117   public void dispose() {
118     fOccurrencesUpdater.dispose();
119     super.dispose();
120   }
121
122   public IDocument getDocument() {
123     IDocument doc = getDocumentProvider().getDocument(getEditorInput());
124     return doc;
125   }
126
127   /*
128    * (non-Javadoc)
129    * 
130    * @see org.eclipse.ui.texteditor.AbstractTextEditor#editorSaved()
131    */
132   protected void editorSaved() {
133     super.editorSaved();
134     BrowserUtil.refreshBrowserPreview(this);
135   }
136   
137   
138 }