1 5 package org.hibernate.eclipse.console.views; 6 7 import javax.swing.tree.TreeNode ; 8 9 import org.eclipse.jface.viewers.ITreeContentProvider; 10 import org.eclipse.jface.viewers.Viewer; 11 12 16 abstract public class TreeNodeContentProvider implements ITreeContentProvider { 17 18 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 19 20 } 21 22 public void dispose() { 23 } 24 25 28 public Object [] getElements(Object inputElement) { 29 return getChildren(inputElement); 30 } 31 32 public boolean hasChildren(final Object element) { 33 if(element instanceof TreeNode ) { 34 return !((TreeNode )element).isLeaf(); 35 } 36 return false; 37 } 38 39 public Object getParent(Object element) { 40 if (element instanceof TreeNode ) { 41 return ((TreeNode )element).getParent(); 42 } 43 return null; 44 } 45 46 49 public Object [] getChildren(Object parentElement) { 50 if(parentElement instanceof TreeNode ) { 51 final TreeNode t = (TreeNode ) parentElement; 52 TreeNode [] children = new TreeNode [0]; 53 if(!t.isLeaf()) { 54 children = new TreeNode [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 [] EMPTY_CHILDREN = new TreeNode [0]; 65 66 67 } 68 | Popular Tags |