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