fix NPE in factual data view
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / concept / ConceptContentProvider.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.editor.view.concept;
11
12 import java.util.HashMap;
13 import java.util.Map;
14
15 import org.eclipse.jface.viewers.IStructuredContentProvider;
16 import org.eclipse.jface.viewers.Viewer;
17
18 import eu.etaxonomy.cdm.model.taxon.Taxon;
19 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
20 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
21
22 /**
23 * @author n.hoffmann
24 * @created Jan 24, 2011
25 * @version 1.0
26 */
27 public class ConceptContentProvider implements IStructuredContentProvider {
28
29 @Override
30 public void dispose() {
31
32 }
33
34 @Override
35 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
36 }
37
38 @Override
39 public Object[] getElements(Object inputElement) {
40 Taxon taxon = null;
41 if(inputElement instanceof Taxon){
42 taxon = (Taxon) inputElement;
43 }
44 if(taxon!=null){
45 Map<TaxonRelationship, Taxon> taxonToTaxonRelationsMap = new HashMap<>();
46
47 for (TaxonRelationship relationship : taxon.getTaxonRelations()) {
48 if (! relationship.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR()) ||
49 relationship.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN())) {
50 taxonToTaxonRelationsMap.put(relationship, taxon);
51 }
52 }
53 return taxonToTaxonRelationsMap.entrySet().toArray();
54 }
55 return new Object[0];
56 }
57
58 }