1 package eu
.etaxonomy
.taxeditor
.editor
.view
.uses
;
3 import java
.util
.ArrayList
;
4 import java
.util
.HashSet
;
10 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
12 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
13 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
14 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
15 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
16 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
17 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
18 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
19 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
20 import eu
.etaxonomy
.taxeditor
.editor
.TaxonEditorInput
;
21 import eu
.etaxonomy
.taxeditor
.editor
.UsageTermCollection
;
22 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.DescriptiveContentProvider
;
23 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainerTree
;
24 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
25 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
26 import eu
.etaxonomy
.taxeditor
.store
.TermStore
;
29 * UsesContentProvider Class
31 * @created mar 13, 2012
34 public class UsesContentProvider
extends DescriptiveContentProvider
implements ITreeContentProvider
{
36 private static final Object
[] NO_CHILDREN
= new Object
[0];
37 private Map
<TaxonDescription
, FeatureNodeContainerTree
> featureNodeContainerCache
;
38 Set
<MarkerType
> markerTypes
= new HashSet
<MarkerType
>();
41 * <p>Constructor for DescriptiveContentProvider.</p>
43 * @param featureNodeContainerCache a {@link java.util.Map} object.
45 public UsesContentProvider(Map
<TaxonDescription
, FeatureNodeContainerTree
> featureNodeContainerCache
) {
46 super(featureNodeContainerCache
);
47 this.featureNodeContainerCache
= featureNodeContainerCache
;
51 private FeatureNodeContainerTree
getContainerTreeForDesription(TaxonDescription description
){
52 if(! featureNodeContainerCache
.containsKey(description
)){
53 FeatureNodeContainerTree containerTree
= new FeatureNodeContainerTree(description
, getFeatureTree(description
));
54 featureNodeContainerCache
.put(description
, containerTree
);
56 return featureNodeContainerCache
.get(description
);
60 * Retrieves the feature tree associated with the given description
62 * TODO as of now this is always the same thing because feature trees may not be associated
63 * to descriptions yet.
68 private FeatureTree
getFeatureTree(DescriptionBase description
){
69 FeatureTree featureTree
= null;
71 // TODO change this to the feature tree associated with this taxon description
72 if (description
.hasStructuredData()){
73 featureTree
= PreferencesUtil
.getDefaultFeatureTreeForStructuredDescription();
75 featureTree
= PreferencesUtil
.getDefaultFeatureTreeForTextualDescription();
78 // create a transient tree with all features if none was selected
79 if(featureTree
== null){
80 featureTree
= FeatureTree
.NewInstance(TermStore
.getTerms(Feature
.class));
87 * Get all descriptions associated with the given TaxonEditorInput
89 * @param parentElement
92 private List
<DescriptionBase
> getDescriptions(TaxonEditorInput parentElement
) {
93 this.markerTypes
.addAll(CdmStore
.getTermManager().getPreferredTerms(MarkerType
.class));
94 Taxon taxon
= parentElement
.getTaxon();
95 List
<DescriptionBase
> descriptions
= new ArrayList
<DescriptionBase
>();
97 for(DescriptionBase description
: taxon
.getDescriptions()){
98 if(! description
.isImageGallery()){
99 MarkerType useMarkertype
= (MarkerType
) CdmStore
.getService(ITermService
.class).find(UsageTermCollection
.uuidUseRecordFeature
);
100 Set
<Marker
> descriptionMarkers
= description
.getMarkers();
101 if(descriptionMarkers
!= null) {
102 for (Marker marker
: descriptionMarkers
) {
103 //TODO Use the GetbyUUID method
104 if(marker
.getMarkerType().equals(useMarkertype
)) {
105 descriptions
.add(description
);