KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > eclipse > console > views > TreeNodeContentProvider


1 /*
2  * Created on 2004-10-30 by max
3  *
4  */

5 package org.hibernate.eclipse.console.views;
6
7 import javax.swing.tree.TreeNode JavaDoc;
8
9 import org.eclipse.jface.viewers.ITreeContentProvider;
10 import org.eclipse.jface.viewers.Viewer;
11
12 /**
13  * @author max
14  *
15  */

16 abstract public class TreeNodeContentProvider implements ITreeContentProvider {
17
18     public void inputChanged(Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput) {
19         
20     }
21
22     public void dispose() {
23     }
24
25     /**
26      * return roots elements!
27      */

28     public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
29         return getChildren(inputElement);
30     }
31
32     public boolean hasChildren(final Object JavaDoc element) {
33         if(element instanceof TreeNode JavaDoc) {
34             return !((TreeNode JavaDoc)element).isLeaf();
35         }
36         return false;
37     }
38
39     public Object JavaDoc getParent(Object JavaDoc element) {
40         if (element instanceof TreeNode JavaDoc) {
41             return ((TreeNode JavaDoc)element).getParent();
42         }
43         return null;
44     }
45
46     /**
47      * return children for the element
48      */

49     public Object JavaDoc[] getChildren(Object JavaDoc parentElement) {
50         if(parentElement instanceof TreeNode JavaDoc) {
51             final TreeNode JavaDoc t = (TreeNode JavaDoc) parentElement;
52             TreeNode JavaDoc[] children = new TreeNode JavaDoc[0];
53             if(!t.isLeaf()) {
54                 children = new TreeNode JavaDoc[t.getChildCount()];
55                 for(int i = 0; i < t.getChildCount(); i++) {
56                     children[i] = t.getChildAt(i);
57                 }
58             }
59             return children;
60         }
61         return EMPTY_CHILDREN;
62     }
63
64     private static final Object JavaDoc[] EMPTY_CHILDREN = new TreeNode JavaDoc[0];
65
66
67 }
68
Popular Tags