automated build configuration is on its way
[taxeditor.git] / taxeditor-navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / SynonymContentProvider.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.cdm.model.taxon.TaxonNode;
24
25 /**
26 * <p>SynonymContentProvider class.</p>
27 *
28 * @author p.ciardelli
29 * @created 02.06.2009
30 * @version 1.0
31 */
32 public class SynonymContentProvider implements ITreeContentProvider {
33 private static final Logger logger = Logger
34 .getLogger(SynonymContentProvider.class);
35
36 private static final Object[] NO_CHILDREN = new Object[0];
37
38 /** {@inheritDoc} */
39 public Object[] getChildren(Object parentElement) {
40 Object[] children = null;
41 if (parentElement instanceof Synonym) {
42 children = NO_CHILDREN;
43 } else if (parentElement instanceof TaxonNode) {
44 List<TaxonBase> list = new ArrayList<TaxonBase>();
45
46 Taxon taxon = ((TaxonNode) parentElement).getTaxon();
47
48 for (TaxonBase taxonBase : new IterableSynonymyList(taxon)) {
49 if (taxonBase instanceof Synonym) {
50 list.add(taxonBase);
51 }
52 }
53 children = list.toArray();
54 }
55 return children != null ? children : NO_CHILDREN;
56 }
57
58 /** {@inheritDoc} */
59 public Object getParent(Object element) {
60 return null;
61 }
62
63 /** {@inheritDoc} */
64 public boolean hasChildren(Object element) {
65 return this.getChildren(element).length > 0;
66 }
67
68 /** {@inheritDoc} */
69 public Object[] getElements(Object inputElement) {
70 return this.getChildren(inputElement);
71 }
72
73 /**
74 * <p>dispose</p>
75 */
76 public void dispose() {
77 }
78
79 /** {@inheritDoc} */
80 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
81 }
82 }