1
|
package eu.etaxonomy.taxeditor.editor.view.uses;
|
2
|
|
3
|
import java.util.ArrayList;
|
4
|
import java.util.HashSet;
|
5
|
import java.util.List;
|
6
|
import java.util.Map;
|
7
|
import java.util.Set;
|
8
|
import java.util.UUID;
|
9
|
|
10
|
import org.eclipse.jface.viewers.ITreeContentProvider;
|
11
|
|
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.view.descriptive.DescriptiveContentProvider;
|
22
|
import eu.etaxonomy.taxeditor.model.FeatureNodeContainerTree;
|
23
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
24
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
25
|
import eu.etaxonomy.taxeditor.store.TermStore;
|
26
|
|
27
|
/**
|
28
|
* UsesContentProvider Class
|
29
|
* @author a.theys
|
30
|
* @created mar 13, 2012
|
31
|
* @version 1.0
|
32
|
*/
|
33
|
public class UsesContentProvider extends DescriptiveContentProvider implements ITreeContentProvider {
|
34
|
|
35
|
private static final Object[] NO_CHILDREN = new Object[0];
|
36
|
private Map<TaxonDescription, FeatureNodeContainerTree> featureNodeContainerCache;
|
37
|
Set<MarkerType> markerTypes = new HashSet<MarkerType>();
|
38
|
|
39
|
/**
|
40
|
* <p>Constructor for DescriptiveContentProvider.</p>
|
41
|
*
|
42
|
* @param featureNodeContainerCache a {@link java.util.Map} object.
|
43
|
*/
|
44
|
public UsesContentProvider(Map<TaxonDescription, FeatureNodeContainerTree> featureNodeContainerCache) {
|
45
|
super(featureNodeContainerCache);
|
46
|
this.featureNodeContainerCache = featureNodeContainerCache;
|
47
|
}
|
48
|
|
49
|
|
50
|
private FeatureNodeContainerTree getContainerTreeForDesription(TaxonDescription description){
|
51
|
if(! featureNodeContainerCache.containsKey(description)){
|
52
|
FeatureNodeContainerTree containerTree = new FeatureNodeContainerTree(description, getFeatureTree(description));
|
53
|
featureNodeContainerCache.put(description, containerTree);
|
54
|
}
|
55
|
return featureNodeContainerCache.get(description);
|
56
|
}
|
57
|
|
58
|
/**
|
59
|
* Retrieves the feature tree associated with the given description
|
60
|
*
|
61
|
* TODO as of now this is always the same thing because feature trees may not be associated
|
62
|
* to descriptions yet.
|
63
|
*
|
64
|
* @param description
|
65
|
* @return
|
66
|
*/
|
67
|
private FeatureTree getFeatureTree(DescriptionBase description){
|
68
|
FeatureTree featureTree = null;
|
69
|
|
70
|
// TODO change this to the feature tree associated with this taxon description
|
71
|
if (description.hasStructuredData()){
|
72
|
featureTree = PreferencesUtil.getDefaultFeatureTreeForStructuredDescription();
|
73
|
}else{
|
74
|
featureTree = PreferencesUtil.getDefaultFeatureTreeForTextualDescription();
|
75
|
}
|
76
|
|
77
|
// create a transient tree with all features if none was selected
|
78
|
if(featureTree == null){
|
79
|
featureTree = FeatureTree.NewInstance(TermStore.getTerms(Feature.class));
|
80
|
}
|
81
|
|
82
|
return featureTree;
|
83
|
}
|
84
|
|
85
|
/**
|
86
|
* Get all descriptions associated with the given TaxonEditorInput
|
87
|
*
|
88
|
* @param parentElement
|
89
|
* @return
|
90
|
*/
|
91
|
private List<DescriptionBase> getDescriptions(TaxonEditorInput parentElement) {
|
92
|
this.markerTypes.addAll(CdmStore.getTermManager().getPreferredTerms(MarkerType.class));
|
93
|
Taxon taxon = parentElement.getTaxon();
|
94
|
List<DescriptionBase> descriptions = new ArrayList<DescriptionBase>();
|
95
|
|
96
|
for(DescriptionBase description : taxon.getDescriptions()){
|
97
|
if(! description.isImageGallery()){
|
98
|
MarkerType useMarkertype = (MarkerType) CdmStore.getService(ITermService.class).find(UUID.fromString("2e6e42d9-e92a-41f4-899b-03c0ac64f039"));
|
99
|
Set<Marker> descriptionMarkers = description.getMarkers();
|
100
|
if(descriptionMarkers != null) {
|
101
|
for (Marker marker: descriptionMarkers) {
|
102
|
//TODO Use the GetbyUUID method
|
103
|
if(marker.getMarkerType().equals(useMarkertype)) {
|
104
|
descriptions.add(description);
|
105
|
}
|
106
|
}
|
107
|
}
|
108
|
}
|
109
|
}
|
110
|
return descriptions;
|
111
|
}
|
112
|
|
113
|
}
|