Project

General

Profile

Download (2.1 KB) Statistics
| Branch: | Tag: | Revision:
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
import eu.etaxonomy.taxeditor.editor.name.IterableSynonymyList;
25

    
26
/**
27
 * <p>SynonymContentProvider class.</p>
28
 *
29
 * @author p.ciardelli
30
 * @created 02.06.2009
31
 * @version 1.0
32
 */
33
public class SynonymContentProvider implements ITreeContentProvider {
34
	private static final Logger logger = Logger
35
			.getLogger(SynonymContentProvider.class);
36

    
37
	private static final Object[] NO_CHILDREN = new Object[0];
38
	
39
	/** {@inheritDoc} */
40
	public Object[] getChildren(Object parentElement) {
41
		Object[] children = null;
42
		if (parentElement instanceof Synonym) {
43
			children = NO_CHILDREN;
44
		} else if (parentElement instanceof TaxonNode) {
45
			List<TaxonBase> list = new ArrayList<TaxonBase>();
46
			
47
			Taxon taxon = ((TaxonNode) parentElement).getTaxon();
48
			
49
			for (TaxonBase taxonBase : new IterableSynonymyList(taxon)) {
50
				if (taxonBase instanceof Synonym) {
51
					list.add(taxonBase);
52
				}
53
			}
54
			children = list.toArray();
55
		}
56
		return children != null ? children : NO_CHILDREN;
57
	}
58

    
59
	/** {@inheritDoc} */
60
	public Object getParent(Object element) {
61
		return null;
62
	}
63

    
64
	/** {@inheritDoc} */
65
	public boolean hasChildren(Object element) {
66
		return this.getChildren(element).length > 0;
67
	}
68

    
69
	/** {@inheritDoc} */
70
	public Object[] getElements(Object inputElement) {
71
		return this.getChildren(inputElement);
72
	}
73

    
74
	/**
75
	 * <p>dispose</p>
76
	 */
77
	public void dispose() {
78
	}
79

    
80
	/** {@inheritDoc} */
81
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
82
	}
83
}
(5-5/13)