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.1 2004-09-02 18:28:05 jsurfer Exp $
14 package net.sourceforge.phpeclipse.xml.ui.internal.outline;
16 import org.eclipse.jface.viewers.ITreeContentProvider;
17 import org.eclipse.jface.viewers.Viewer;
19 import net.sourceforge.phpeclipse.xml.core.model.IXMLDocument;
20 import net.sourceforge.phpeclipse.xml.core.model.IXMLElement;
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, Object, Object)
83 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
84 if (oldInput != newInput) {
85 if (oldInput instanceof IXMLDocument) {
88 if (newInput instanceof IXMLDocument) {
89 document = (IXMLDocument) newInput;