KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > model > AntModelContentProvider


1 /*******************************************************************************
2  * Copyright (c) 2003, 2005 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 package org.eclipse.ant.internal.ui.model;
12
13 import java.util.List JavaDoc;
14
15 import org.eclipse.jface.viewers.ITreeContentProvider;
16 import org.eclipse.jface.viewers.Viewer;
17
18
19 public class AntModelContentProvider implements ITreeContentProvider {
20
21     protected static final Object JavaDoc[] EMPTY_ARRAY= new Object JavaDoc[0];
22     
23     /**
24      * @see org.eclipse.jface.viewers.IContentProvider#dispose()
25      */

26     public void dispose() {
27     }
28     
29     /**
30      * do nothing
31      * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(Viewer, Object, Object)
32      */

33     public void inputChanged(Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput) {
34     }
35
36     /* (non-Javadoc)
37      * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(Object)
38      */

39     public Object JavaDoc[] getChildren(Object JavaDoc parentNode) {
40         if (parentNode instanceof AntElementNode) {
41             AntElementNode parentElement = (AntElementNode)parentNode;
42             if (parentElement.hasChildren()) {
43                 List JavaDoc children= parentElement.getChildNodes();
44                 return children.toArray();
45             }
46         } else if (parentNode instanceof IAntModel) {
47             return new Object JavaDoc[] {((IAntModel)parentNode).getProjectNode()};
48         }
49         return EMPTY_ARRAY;
50     }
51
52     /* (non-Javadoc)
53      * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(Object)
54      */

55     public Object JavaDoc getParent(Object JavaDoc aNode) {
56         AntElementNode tempElement = (AntElementNode)aNode;
57         return tempElement.getParentNode();
58     }
59
60     /* (non-Javadoc)
61      * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(Object)
62      */

63     public boolean hasChildren(Object JavaDoc aNode) {
64         return ((AntElementNode)aNode).hasChildren();
65     }
66
67     /* (non-Javadoc)
68      * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(Object)
69      */

70     public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
71         if (inputElement instanceof IAntModel ) {
72             AntProjectNode projectNode= ((IAntModel) inputElement).getProjectNode();
73             if (projectNode == null) {
74                 return new AntElementNode[0];
75             }
76             
77             return new Object JavaDoc[] {projectNode};
78         }
79         
80         if (inputElement instanceof Object JavaDoc[]) {
81             return (Object JavaDoc[])inputElement;
82         }
83         return EMPTY_ARRAY;
84     }
85 }
86
Popular Tags