KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > cheatsheet > simple > SimpleCSContentProvider


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.pde.internal.ui.editor.cheatsheet.simple;
13
14 import java.util.List JavaDoc;
15
16 import org.eclipse.jface.viewers.ITreeContentProvider;
17 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSModel;
18 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject;
19 import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
20
21 /**
22  * SimpleCSContentProvider
23  *
24  */

25 public class SimpleCSContentProvider extends DefaultContentProvider implements
26         ITreeContentProvider {
27
28     /**
29      *
30      */

31     public SimpleCSContentProvider() {
32         // NO-OP
33
}
34
35     /* (non-Javadoc)
36      * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
37      */

38     public Object JavaDoc[] getChildren(Object JavaDoc parentElement) {
39         if (parentElement instanceof ISimpleCSModel) {
40             return new Object JavaDoc[]{((ISimpleCSModel)parentElement).getSimpleCS()};
41         } else if (parentElement instanceof ISimpleCSObject) {
42             List JavaDoc list = ((ISimpleCSObject)parentElement).getChildren();
43             // List is never null
44
if (list.size() > 0) {
45                 return list.toArray();
46             }
47         }
48         return new Object JavaDoc[0];
49     }
50
51     /* (non-Javadoc)
52      * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
53      */

54     public Object JavaDoc getParent(Object JavaDoc element) {
55         if (element instanceof ISimpleCSObject) {
56             return ((ISimpleCSObject)element).getParent();
57         }
58         return null;
59     }
60
61     /* (non-Javadoc)
62      * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
63      */

64     public boolean hasChildren(Object JavaDoc element) {
65         return (getChildren(element).length > 0);
66     }
67
68     /* (non-Javadoc)
69      * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
70      */

71     public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
72         return getChildren(inputElement);
73     }
74
75 }
76
Popular Tags