intial source from ttp://www.sf.net/projects/wdte
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.css.ui / src / net / sourceforge / phpeclipse / css / ui / internal / outline / CssOutlineContentProvider.java
1 /*
2  * Copyright (c) 2003-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
7  * 
8  * Contributors:
9  *     Christopher Lenz - initial API and implementation
10  * 
11  * $Id: CssOutlineContentProvider.java,v 1.1 2004-09-02 18:11:49 jsurfer Exp $
12  */
13
14 package net.sourceforge.phpeclipse.css.ui.internal.outline;
15
16 import net.sourceforge.phpeclipse.css.core.model.IRule;
17 import net.sourceforge.phpeclipse.css.core.model.IStyleSheet;
18
19 import org.eclipse.jface.viewers.ITreeContentProvider;
20 import org.eclipse.jface.viewers.Viewer;
21
22 /**
23  * Content provider for the CSS outline page.
24  */
25 public class CssOutlineContentProvider implements ITreeContentProvider {
26
27         // Instance Variables ------------------------------------------------------
28
29         /**
30          * The parsed style sheet.
31          */
32         private IStyleSheet styleSheet;
33
34         // ITreeContentProvider Implementation -------------------------------------
35
36         /*
37          * ITreeContentProvider#getChildren(Object)
38          */
39         public Object[] getChildren(Object parentElement) {
40                 if (parentElement instanceof IRule) {
41                         return ((IRule) parentElement).getChildren();
42                 }
43                 return new Object[0];
44         }
45
46         /*
47          * @see ITreeContentProvider#getParent(Object)
48          */
49         public Object getParent(Object element) {
50                 if (element instanceof IRule) {
51                         return ((IRule) element).getParent();
52                 }
53                 return null;
54         }
55
56         /*
57          * @see ITreeContentProvider#hasChildren(Object)
58          */
59         public boolean hasChildren(Object element) {
60                 return getChildren(element).length > 0;
61         }
62
63         /*
64          * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(Object)
65          */
66         public Object[] getElements(Object inputElement) {
67                 if (styleSheet != null) {
68                         return styleSheet.getRules();
69                 }
70                 return new Object[0];
71         }
72
73         /*
74          * @see org.eclipse.jface.viewers.IContentProvider#dispose()
75          */
76         public void dispose() {
77                 styleSheet = null;
78         }
79
80         /*
81          * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(Viewer, Object, Object)
82          */
83         public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
84                 if (oldInput != newInput) {
85                         if (oldInput instanceof IStyleSheet) {
86                                 styleSheet = null;
87                         }
88                         if (newInput instanceof IStyleSheet) {
89                                 IStyleSheet newStyleSheet = (IStyleSheet) newInput;
90                                 styleSheet = newStyleSheet;
91                         }          
92                 }
93         }
94
95 }