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.3 2006-10-21 23:14:14 pombredanne Exp $
14 package net.sourceforge.phpeclipse.xml.ui.internal.outline;
16 import java.util.List;
18 import net.sourceforge.phpeclipse.core.model.ISourceReference;
19 import net.sourceforge.phpeclipse.ui.views.outline.ProblemsLabelDecorator;
20 import net.sourceforge.phpeclipse.xml.core.model.IXMLDocument;
21 import net.sourceforge.phpeclipse.xml.ui.internal.editor.XMLDocumentProvider;
22 import net.sourceforge.phpeclipse.xml.ui.internal.editor.XMLEditor;
24 import org.eclipse.jface.viewers.DecoratingLabelProvider;
25 import org.eclipse.jface.viewers.ISelection;
26 import org.eclipse.jface.viewers.IStructuredSelection;
27 import org.eclipse.jface.viewers.StructuredSelection;
28 import org.eclipse.jface.viewers.TreeViewer;
29 import org.eclipse.swt.widgets.Composite;
30 import org.eclipse.swt.widgets.Control;
31 import org.eclipse.ui.texteditor.IDocumentProvider;
32 import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
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 ------------------------------------------------------------
52 * The associated text editor
54 public XMLOutlinePage(XMLEditor editor) {
58 // ContentOutlinePage Implementation ---------------------------------------
61 * @see org.eclipse.ui.part.IPage#createControl(Composite)
63 public void createControl(Composite parent) {
64 super.createControl(parent);
65 TreeViewer viewer = getTreeViewer();
66 viewer.setContentProvider(new XMLOutlineContentProvider());
67 viewer.setLabelProvider(new DecoratingLabelProvider(
68 new XMLOutlineLabelProvider(), new ProblemsLabelDecorator(
70 viewer.setInput(getDocument());
73 // Public Methods ----------------------------------------------------------
76 * Selects a specific element in the outline page.
79 * the element to select
81 public void select(ISourceReference element) {
82 TreeViewer viewer = getTreeViewer();
84 ISelection selection = viewer.getSelection();
85 if (selection instanceof IStructuredSelection) {
86 IStructuredSelection structuredSelection = (IStructuredSelection) selection;
87 List elements = structuredSelection.toList();
88 if (!elements.contains(element)) {
89 if (element == null) {
90 selection = StructuredSelection.EMPTY;
92 selection = new StructuredSelection(element);
94 viewer.setSelection(selection, true);
101 * Updates the outline page.
103 public void update() {
104 IXMLDocument document = getDocument();
105 if (document != null) {
106 TreeViewer viewer = getTreeViewer();
107 if (viewer != null) {
108 Control control = viewer.getControl();
109 if ((control != null) && !control.isDisposed()) {
110 control.setRedraw(false);
111 viewer.setInput(document);
113 control.setRedraw(true);
119 // Private Methods ---------------------------------------------------------
122 * Returns the parsed model of the XML document that is loaded into the
125 * @return the parsed XML document
127 private IXMLDocument getDocument() {
128 IDocumentProvider provider = editor.getDocumentProvider();
129 if (provider instanceof XMLDocumentProvider) {
130 XMLDocumentProvider xmlProvider = (XMLDocumentProvider) provider;
131 return xmlProvider.getModel(editor.getEditorInput());