--- /dev/null
+/*
+ * Copyright (c) 2003-2004 Christopher Lenz and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Christopher Lenz - initial API and implementation
+ *
+ * $Id: CssOutlineContentProvider.java,v 1.1 2004-09-02 18:11:49 jsurfer Exp $
+ */
+
+package net.sourceforge.phpeclipse.css.ui.internal.outline;
+
+import net.sourceforge.phpeclipse.css.core.model.IRule;
+import net.sourceforge.phpeclipse.css.core.model.IStyleSheet;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+/**
+ * Content provider for the CSS outline page.
+ */
+public class CssOutlineContentProvider implements ITreeContentProvider {
+
+ // Instance Variables ------------------------------------------------------
+
+ /**
+ * The parsed style sheet.
+ */
+ private IStyleSheet styleSheet;
+
+ // ITreeContentProvider Implementation -------------------------------------
+
+ /*
+ * ITreeContentProvider#getChildren(Object)
+ */
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof IRule) {
+ return ((IRule) parentElement).getChildren();
+ }
+ return new Object[0];
+ }
+
+ /*
+ * @see ITreeContentProvider#getParent(Object)
+ */
+ public Object getParent(Object element) {
+ if (element instanceof IRule) {
+ return ((IRule) element).getParent();
+ }
+ return null;
+ }
+
+ /*
+ * @see ITreeContentProvider#hasChildren(Object)
+ */
+ public boolean hasChildren(Object element) {
+ return getChildren(element).length > 0;
+ }
+
+ /*
+ * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(Object)
+ */
+ public Object[] getElements(Object inputElement) {
+ if (styleSheet != null) {
+ return styleSheet.getRules();
+ }
+ return new Object[0];
+ }
+
+ /*
+ * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+ */
+ public void dispose() {
+ styleSheet = null;
+ }
+
+ /*
+ * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(Viewer, Object, Object)
+ */
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ if (oldInput != newInput) {
+ if (oldInput instanceof IStyleSheet) {
+ styleSheet = null;
+ }
+ if (newInput instanceof IStyleSheet) {
+ IStyleSheet newStyleSheet = (IStyleSheet) newInput;
+ styleSheet = newStyleSheet;
+ }
+ }
+ }
+
+}