Re-implemented taxonomic tree using Common Navigator Framework.
[taxeditor.git] / taxeditor-navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / NavigatorSynonymContentProvider.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 java.util.ArrayList;
14 import java.util.List;
15
16 import org.apache.log4j.Logger;
17 import org.eclipse.jface.viewers.ITreeContentProvider;
18 import org.eclipse.jface.viewers.Viewer;
19
20 import eu.etaxonomy.cdm.model.taxon.Synonym;
21 import eu.etaxonomy.cdm.model.taxon.Taxon;
22 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
23 import eu.etaxonomy.taxeditor.editor.name.IterableSynonymyList;
24
25 /**
26 * @author p.ciardelli
27 * @created 02.06.2009
28 * @version 1.0
29 */
30 public class NavigatorSynonymContentProvider implements ITreeContentProvider {
31 private static final Logger logger = Logger
32 .getLogger(NavigatorSynonymContentProvider.class);
33
34 private static final Object[] NO_CHILDREN = new Object[0];
35
36 public Object[] getChildren(Object parentElement) {
37 Object[] children = null;
38 if (parentElement instanceof Synonym) {
39 children = NO_CHILDREN;
40 } else if (parentElement instanceof Taxon) {
41 List<TaxonBase> list = new ArrayList<TaxonBase>();
42
43 for (TaxonBase taxonBase : new IterableSynonymyList((Taxon) parentElement)) {
44 if (taxonBase instanceof Synonym) {
45 list.add(taxonBase);
46 }
47 }
48 children = list.toArray();
49 }
50 return children != null ? children : NO_CHILDREN;
51 }
52
53 public Object getParent(Object element) {
54 return null;
55 }
56
57 public boolean hasChildren(Object element) {
58 return this.getChildren(element).length > 0;
59 }
60
61 public Object[] getElements(Object inputElement) {
62 return this.getChildren(inputElement);
63 }
64
65 public void dispose() {
66 }
67
68 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
69 }
70 }