2 * $RCSfile: JSEditor.java,v $
5 * CH-1700 Fribourg, Switzerland
8 *========================================================================
9 * Modifications history
10 *========================================================================
11 * $Log: not supported by cvs2svn $
12 * Revision 1.4 2004/02/27 17:12:48 cell
13 * Use the new outline page
15 * Revision 1.3 2004/02/26 02:25:57 agfitzp
16 * renamed packages to match xml & css
18 * Revision 1.2 2004/02/14 18:36:30 ayashi
19 * More UI-Core refactoring... still doesn't work though...
21 * Revision 1.1 2004/02/05 03:13:28 agfitzp
22 * Initial submission, outline view is broken due to refactoring
24 * Revision 1.5.2.1 2003/12/12 21:37:24 agfitzp
25 * Experimental work for Classes view
27 * Revision 1.5 2003/08/14 15:14:15 agfitzp
28 * Removed thread hack from automatic update
30 * Revision 1.4 2003/07/04 17:26:56 agfitzp
31 * New hack, update in a new thread only if we're not already in the middle of updating
33 * Revision 1.3 2003/06/21 03:48:51 agfitzp
34 * fixed global variables as functions bug
35 * fixed length calculation of instance variables
36 * Automatic outlining is now a preference
38 * Revision 1.2 2003/05/28 20:47:58 agfitzp
39 * Outline the document, not the file.
41 * Revision 1.1 2003/05/28 15:17:12 agfitzp
42 * net.sourceforge.phpeclipse.js.ui 0.0.1 code base
44 *========================================================================
47 package net.sourceforge.phpeclipse.js.ui.editors;
49 import net.sourceforge.phpeclipse.js.core.model.JSElement;
50 import net.sourceforge.phpeclipse.js.ui.internal.outline.JSOutlinePage;
52 import org.eclipse.core.runtime.IProgressMonitor;
53 import org.eclipse.jface.action.IAction;
54 import org.eclipse.jface.viewers.ISelectionChangedListener;
55 import org.eclipse.jface.viewers.IStructuredSelection;
56 import org.eclipse.jface.viewers.SelectionChangedEvent;
57 import org.eclipse.ui.editors.text.TextEditor;
58 import org.eclipse.ui.texteditor.ContentAssistAction;
59 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
60 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
65 * @version $Revision: 1.1 $
66 * @author $Author: jsurfer $, $Date: 2004-09-02 18:23:49 $
68 public class JSEditor extends TextEditor implements ISelectionChangedListener
70 protected JSColorManager colorManager = new JSColorManager();
71 protected JSOutlinePage outlinePage;
72 protected JSConfiguration configuration;
74 protected boolean updating = false;
77 * Constructor for SampleEditor.
82 configuration = new JSConfiguration(colorManager);
84 setSourceViewerConfiguration(configuration);
85 setDocumentProvider(new JSDocumentProvider());
87 protected void createActions() {
88 super.createActions();
90 IAction action = new ContentAssistAction(JSEditorMessages.getResourceBundle(),
91 "ContentAssistProposal.", this); //$NON-NLS-1$
93 .setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
94 setAction("ContentAssistProposal", action); //$NON-NLS-1$
95 markAsStateDependentAction("ContentAssistProposal", true); //$NON-NLS-1$
97 // IAction action= new TextOperationAction(
98 // TemplateMessages.getResourceBundle(),
99 // "Editor." + TEMPLATE_PROPOSALS + ".", //$NON-NLS-1$ //$NON-NLS-2$
101 // ISourceViewer.CONTENTASSIST_PROPOSALS);
102 // action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
103 // setAction(TEMPLATE_PROPOSALS, action);
104 // markAsStateDependentAction(TEMPLATE_PROPOSALS, true);
107 * Method declared on IEditorPart
110 public void doSave(IProgressMonitor monitor)
112 super.doSave(monitor);
114 if (outlinePage != null)
116 outlinePage.update();
123 public void dispose()
125 colorManager.dispose();
130 * @see org.eclipse.ui.texteditor.AbstractTextEditor#getAdapter(Class)
132 public Object getAdapter(Class key) {
133 if (key.equals(IContentOutlinePage.class)) {
134 outlinePage = new JSOutlinePage(this);
135 outlinePage.addSelectionChangedListener(this);
138 return super.getAdapter(key);
142 * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(SelectionChangedEvent)
144 public void selectionChanged(SelectionChangedEvent event)
148 if (event.getSelection() instanceof IStructuredSelection)
150 IStructuredSelection sel = (IStructuredSelection) event.getSelection();
153 JSElement fe = (JSElement) sel.getFirstElement();
156 selectAndReveal(fe.getStart(), fe.getLength());
164 * Updates all content dependent actions.
166 * This might be a hack: We're trapping this update to ensure that the
167 * outline is always up to date.
169 protected void updateContentDependentActions()
171 super.updateContentDependentActions();
175 if (configuration.getAutomaticOutliningPreference())
177 if (outlinePage != null)
181 outlinePage.update();