ref #8234:avoid NPE
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / uses / UsesContentProvider.java
1 /**
2 * Copyright (C) 2011 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 package eu.etaxonomy.taxeditor.editor.view.uses;
10
11 import java.util.ArrayList;
12 import java.util.HashSet;
13 import java.util.List;
14 import java.util.Map;
15 import java.util.Set;
16
17 import eu.etaxonomy.cdm.model.common.Marker;
18 import eu.etaxonomy.cdm.model.common.MarkerType;
19 import eu.etaxonomy.cdm.model.description.DescriptionBase;
20 import eu.etaxonomy.cdm.model.description.IDescribable;
21 import eu.etaxonomy.cdm.model.taxon.Taxon;
22 import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveContentProvider;
23 import eu.etaxonomy.taxeditor.model.FeatureNodeContainerTree;
24 import eu.etaxonomy.taxeditor.store.CdmStore;
25 import eu.etaxonomy.taxeditor.store.UsageTermCollection;
26
27 /**
28 * The class provides the required content to the Uses View
29 * @author a.theys
30 * @created mar 13, 2012
31 * @version 1.0
32 */
33 public class UsesContentProvider extends DescriptiveContentProvider {
34
35 Set<MarkerType> markerTypes = new HashSet<MarkerType>();
36
37 /**
38 * <p>Constructor for DescriptiveContentProvider.</p>
39 *
40 * @param featureNodeContainerCache a {@link java.util.Map} object.
41 */
42 public UsesContentProvider(Map<DescriptionBase<?>, FeatureNodeContainerTree> featureNodeContainerCache) {
43 super(featureNodeContainerCache);
44 this.featureNodeContainerCache = featureNodeContainerCache;
45 }
46
47 /**
48 * Get all descriptions associated with the given TaxonEditorInput
49 *
50 * @param parentElement
51 * @return
52 */
53 @Override
54 protected List<DescriptionBase<?>> getDescriptions(IDescribable<?> parentElement) {
55 List<DescriptionBase<?>> descriptions = new ArrayList<DescriptionBase<?>>();
56 if(parentElement instanceof Taxon){
57 Taxon taxon = (Taxon) parentElement;
58 this.markerTypes.addAll(CdmStore.getTermManager().getPreferredTerms(MarkerType.class));
59 for(DescriptionBase<?> description : taxon.getDescriptions()){
60 if(! description.isImageGallery()){
61 Set<Marker> descriptionMarkers = description.getMarkers();
62 if(descriptionMarkers != null) {
63 for (Marker marker: descriptionMarkers) {
64 if(marker.getMarkerType() != null && marker.getMarkerType().getUuid().equals(UsageTermCollection.uuidUseMarkerType)) {
65 descriptions.add(description);
66 }
67 }
68 }
69 }
70 }
71 }
72 return descriptions;
73 }
74
75 }