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