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: XMLOutlineContentProvider.java,v 1.3 2006-10-21 23:14:14 pombredanne Exp $
14 package net.sourceforge.phpeclipse.xml.ui.internal.outline;
16 import net.sourceforge.phpeclipse.xml.core.model.IXMLDocument;
17 import net.sourceforge.phpeclipse.xml.core.model.IXMLElement;
19 import org.eclipse.jface.viewers.ITreeContentProvider;
20 import org.eclipse.jface.viewers.Viewer;
23 * Content provider for the XML outline page.
25 public class XMLOutlineContentProvider implements ITreeContentProvider {
27 // Instance Variables ------------------------------------------------------
30 * The parsed XML document.
32 private IXMLDocument document;
34 // ITreeContentProvider Implementation -------------------------------------
37 * ITreeContentProvider#getChildren(Object)
39 public Object[] getChildren(Object parentElement) {
40 if (parentElement instanceof IXMLElement) {
41 return ((IXMLElement) parentElement).getChildren();
47 * @see ITreeContentProvider#getParent(Object)
49 public Object getParent(Object element) {
50 if (element instanceof IXMLElement) {
51 return ((IXMLElement) element).getParent();
57 * @see ITreeContentProvider#hasChildren(Object)
59 public boolean hasChildren(Object element) {
60 return getChildren(element).length > 0;
64 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(Object)
66 public Object[] getElements(Object inputElement) {
67 if ((document != null) && (document.getRoot() != null)) {
68 return new Object[] { document.getRoot() };
74 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
76 public void dispose() {
81 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(Viewer,
84 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
85 if (oldInput != newInput) {
86 if (oldInput instanceof IXMLDocument) {
89 if (newInput instanceof IXMLDocument) {
90 document = (IXMLDocument) newInput;