2 * Copyright (c) 2004 Christopher Lenz 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 * Christopher Lenz - initial API and implementation
11 * $Id: XMLOutlinePage.java,v 1.1 2004-09-02 18:28:05 jsurfer Exp $
14 package net.sourceforge.phpeclipse.xml.ui.internal.outline;
16 import java.util.List;
18 import org.eclipse.jface.viewers.DecoratingLabelProvider;
19 import org.eclipse.jface.viewers.ISelection;
20 import org.eclipse.jface.viewers.IStructuredSelection;
21 import org.eclipse.jface.viewers.StructuredSelection;
22 import org.eclipse.jface.viewers.TreeViewer;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.swt.widgets.Control;
25 import org.eclipse.ui.texteditor.IDocumentProvider;
26 import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
28 import net.sourceforge.phpeclipse.core.model.ISourceReference;
29 import net.sourceforge.phpeclipse.ui.views.outline.ProblemsLabelDecorator;
30 import net.sourceforge.phpeclipse.xml.core.model.IXMLDocument;
31 import net.sourceforge.phpeclipse.xml.ui.internal.editor.XMLDocumentProvider;
32 import net.sourceforge.phpeclipse.xml.ui.internal.editor.XMLEditor;
35 * Implements the outline page associated with the XML editor.
37 public class XMLOutlinePage extends ContentOutlinePage {
39 // Instance Variables ------------------------------------------------------
42 * The associated editor.
44 private XMLEditor editor;
46 // Constructors ------------------------------------------------------------
51 * @param editor The associated text editor
53 public XMLOutlinePage(XMLEditor editor) {
57 // ContentOutlinePage Implementation ---------------------------------------
60 * @see org.eclipse.ui.part.IPage#createControl(Composite)
62 public void createControl(Composite parent) {
63 super.createControl(parent);
64 TreeViewer viewer = getTreeViewer();
65 viewer.setContentProvider(new XMLOutlineContentProvider());
66 viewer.setLabelProvider(new DecoratingLabelProvider(
67 new XMLOutlineLabelProvider(),
68 new ProblemsLabelDecorator(editor)));
69 viewer.setInput(getDocument());
72 // Public Methods ----------------------------------------------------------
75 * Selects a specific element in the outline page.
77 * @param element the element to select
79 public void select(ISourceReference element) {
80 TreeViewer viewer = getTreeViewer();
82 ISelection selection = viewer.getSelection();
83 if (selection instanceof IStructuredSelection) {
84 IStructuredSelection structuredSelection =
85 (IStructuredSelection) selection;
86 List elements = structuredSelection.toList();
87 if (!elements.contains(element)) {
88 if (element == null) {
89 selection = StructuredSelection.EMPTY;
91 selection = new StructuredSelection(element);
93 viewer.setSelection(selection, true);
100 * Updates the outline page.
102 public void update() {
103 IXMLDocument document = getDocument();
104 if (document != null) {
105 TreeViewer viewer = getTreeViewer();
106 if (viewer != null) {
107 Control control = viewer.getControl();
108 if ((control != null) && !control.isDisposed()) {
109 control.setRedraw(false);
110 viewer.setInput(document);
112 control.setRedraw(true);
118 // Private Methods ---------------------------------------------------------
121 * Returns the parsed model of the XML document that is loaded into the
124 * @return the parsed XML document
126 private IXMLDocument getDocument() {
127 IDocumentProvider provider = editor.getDocumentProvider();
128 if (provider instanceof XMLDocumentProvider) {
129 XMLDocumentProvider xmlProvider = (XMLDocumentProvider) provider;
130 return xmlProvider.getModel(editor.getEditorInput());