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