2 * Copyright (c) 2002-2004 Adrian Dinu and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * Adrian Dinu - initial implementation
10 * Alex Fitzpatrick - update outline while editing
11 * Christopher Lenz - use custom content and label providers
13 * $Id: JSOutlinePage.java,v 1.1 2004-09-02 18:23:49 jsurfer Exp $
16 package net.sourceforge.phpeclipse.js.ui.internal.outline;
18 import net.sourceforge.phpeclipse.js.core.model.JSElementList;
19 import net.sourceforge.phpeclipse.js.core.parser.JSSyntaxModelFactory;
20 import net.sourceforge.phpeclipse.js.ui.model.JSNameSorter;
22 import org.eclipse.jface.text.IDocument;
23 import org.eclipse.jface.viewers.TreeViewer;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.swt.widgets.Control;
26 import org.eclipse.ui.model.WorkbenchContentProvider;
27 import org.eclipse.ui.model.WorkbenchLabelProvider;
28 import org.eclipse.ui.texteditor.IDocumentProvider;
29 import org.eclipse.ui.texteditor.ITextEditor;
30 import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
33 * Implements an outline page for JavaScript files.
35 public class JSOutlinePage extends ContentOutlinePage {
37 // Instance Variables ------------------------------------------------------
39 /** The associated text editor. **/
40 protected ITextEditor editor;
42 // Constructors ------------------------------------------------------------
45 * Creates a new JSOutlinePage.
47 * @param editor the associated text editor
49 public JSOutlinePage(ITextEditor editor) {
53 // ContentOutlinePage Implementation ---------------------------------------
56 * @see org.eclipse.ui.part.IPage#createControl(Composite)
58 public void createControl(Composite parent) {
59 super.createControl(parent);
60 TreeViewer viewer = getTreeViewer();
61 viewer.setContentProvider(new WorkbenchContentProvider());
62 viewer.setLabelProvider(new WorkbenchLabelProvider());
63 // TODO Make sorting optional
64 viewer.setSorter(new JSNameSorter());
67 // Public Methods ----------------------------------------------------------
70 * Forces the outline page to update its contents.
72 public void update() {
73 IDocument document = getDocument();
74 JSSyntaxModelFactory factory = JSSyntaxModelFactory.getInstance();
75 JSElementList model = factory.getContentOutline(document);
77 TreeViewer viewer = getTreeViewer();
79 Control control = viewer.getControl();
80 if ((control != null) && !control.isDisposed()) {
81 control.setRedraw(false);
82 viewer.setInput(model);
84 control.setRedraw(true);
90 // Private Methods ---------------------------------------------------------
93 * Returns the document that is open in the associated text editor.
95 * @return the document being edited
97 private IDocument getDocument() {
98 IDocumentProvider provider = editor.getDocumentProvider();
99 return provider.getDocument(editor.getEditorInput());