automated build configuration is on its way
[taxeditor.git] / taxeditor-navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / TaxonNodeContentProvider.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.navigation.navigator;
12
13 import org.apache.log4j.Logger;
14 import org.eclipse.jface.viewers.ITreeContentProvider;
15 import org.eclipse.jface.viewers.Viewer;
16
17 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
18 import eu.etaxonomy.cdm.model.taxon.ITreeNode;
19 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
20
21 /**
22 * <p>TaxonNodeContentProvider class.</p>
23 *
24 * @author p.ciardelli
25 * @created 02.06.2009
26 * @version 1.0
27 */
28 public class TaxonNodeContentProvider implements ITreeContentProvider {
29 private static final Logger logger = Logger
30 .getLogger(TaxonNodeContentProvider.class);
31
32 private static final Object[] NO_CHILDREN = new Object[0];
33
34 /** {@inheritDoc} */
35 public Object[] getChildren(Object parentElement) {
36 Object[] children = null;
37
38 if(parentElement instanceof ITreeNode){
39 ITreeNode treeNode = (ITreeNode) HibernateProxyHelper.deproxy(parentElement);
40 children = treeNode.getChildNodes().toArray();
41 }
42
43 return children != null ? children : NO_CHILDREN;
44 }
45
46 /** {@inheritDoc} */
47 public Object getParent(Object element) {
48 if(element instanceof TaxonNode){
49 return ((TaxonNode) element).getParent();
50 }
51 return null;
52 }
53
54 /** {@inheritDoc} */
55 public boolean hasChildren(Object element) {
56 if(element instanceof TaxonNode){
57 return ((TaxonNode) element).getCountChildren() > 0;
58 }
59 return getChildren(element).length > 0;
60 }
61
62 /** {@inheritDoc} */
63 public Object[] getElements(Object inputElement) {
64 return this.getChildren(inputElement);
65 }
66
67 /**
68 * <p>dispose</p>
69 */
70 public void dispose() {
71 }
72
73 /** {@inheritDoc} */
74 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
75 }
76 }