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
;
11 import org
.eclipse
.jface
.viewers
.Viewer
;
13 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
14 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
15 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
16 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
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
.cdm
.persistence
.dao
.common
.IDefinedTermDao
;
21 import eu
.etaxonomy
.taxeditor
.editor
.TaxonEditorInput
;
22 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
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
;
28 public class UsesContentProvider
implements ITreeContentProvider
{
30 private static final Object
[] NO_CHILDREN
= new Object
[0];
31 private Map
<TaxonDescription
, FeatureNodeContainerTree
> featureNodeContainerCache
;
32 Set
<MarkerType
> markerTypes
= new HashSet
<MarkerType
>();
35 * <p>Constructor for DescriptiveContentProvider.</p>
37 * @param featureNodeContainerCache a {@link java.util.Map} object.
39 public UsesContentProvider(Map
<TaxonDescription
, FeatureNodeContainerTree
> featureNodeContainerCache
) {
40 //MarkerType markerType = (MarkerType)this.definedTermDao.findByUuid(UUID.fromString("b4b1b2ab-89a8-4ce6-8110-d60b8b1bc433")); //Marker "complete"
41 //this.markerTypes.addAll(CdmStore.getTermManager().getPreferredMarkerTypes());
42 this.featureNodeContainerCache
= featureNodeContainerCache
;
48 * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
51 public Object
[] getChildren(Object parentElement
) {
52 if (parentElement
instanceof TaxonEditorInput
) {
53 return getDescriptions((TaxonEditorInput
) parentElement
).toArray();
55 else if (parentElement
instanceof TaxonDescription
) {
56 if ( ! ((TaxonDescription
) parentElement
).isImageGallery()) {
57 TaxonDescription description
= (TaxonDescription
) parentElement
;
59 FeatureNodeContainerTree containerTree
= getContainerTreeForDesription(description
);
61 return containerTree
.getRoot().getChildren().toArray();
64 else if (parentElement
instanceof FeatureNodeContainer
){
65 FeatureNodeContainer container
= (FeatureNodeContainer
) parentElement
;
66 if(container
.isLeaf()){
67 return container
.getDescriptionElements().toArray();
69 return container
.getChildren().toArray();
76 private FeatureNodeContainerTree
getContainerTreeForDesription(TaxonDescription description
){
77 if(! featureNodeContainerCache
.containsKey(description
)){
78 FeatureNodeContainerTree containerTree
= new FeatureNodeContainerTree(description
, getFeatureTree(description
));
79 featureNodeContainerCache
.put(description
, containerTree
);
81 return featureNodeContainerCache
.get(description
);
86 public boolean hasChildren(Object element
) {
87 if (element
instanceof TaxonDescription
){
88 TaxonDescription description
= (TaxonDescription
) element
;
89 FeatureNodeContainerTree containerTree
= featureNodeContainerCache
.get(description
);
90 if(containerTree
!= null && containerTree
.getRoot() != null){
91 return containerTree
.getRoot().getChildren().size() != 0;
94 return getChildren(element
).length
!= 0;
98 * Retrieves the feature tree associated with the given description
100 * TODO as of now this is always the same thing because feature trees may not be associated
101 * to descriptions yet.
106 private FeatureTree
getFeatureTree(DescriptionBase description
){
107 FeatureTree featureTree
= null;
109 // TODO change this to the feature tree associated with this taxon description
110 if (description
.hasStructuredData()){
111 featureTree
= PreferencesUtil
.getDefaultFeatureTreeForStructuredDescription();
113 featureTree
= PreferencesUtil
.getDefaultFeatureTreeForTextualDescription();
116 // create a transient tree with all features if none was selected
117 if(featureTree
== null){
118 featureTree
= FeatureTree
.NewInstance(TermStore
.getFeatures());
125 * Get all descriptions associated with the given TaxonEditorInput
127 * @param parentElement
130 //CdmStore.getService(IDescriptionService.class).listTaxonDescriptions(input.getTaxonNode().getTaxon(), null, null, null, null, null, null)
131 private List
<DescriptionBase
> getDescriptions(TaxonEditorInput parentElement
) {
132 this.markerTypes
.addAll(CdmStore
.getTermManager().getPreferredMarkerTypes());
133 Taxon taxon
= parentElement
.getTaxon();
134 Set
<MarkerType
> typesToDisdplay
= new HashSet
<MarkerType
>();
135 List
<DescriptionBase
> descriptions
= new ArrayList
<DescriptionBase
>();
136 List
<TaxonDescription
> usesDescriptions
= new ArrayList
<TaxonDescription
>();
138 /*for (MarkerType markerType : markerTypes) {
139 if (markerType.toString().equals("complete")) {
140 typesToDisdplay.add(markerType);
143 //usesDescriptions = CdmStore.getService(IDescriptionService.class).listTaxonDescriptions(taxon, null, null, typesToDisdplay, null, null, null);
144 //for(DescriptionBase description : CdmStore.getService(IDescriptionService.class).listTaxonDescriptions(taxon, null, null, typesToDisdplay, null, null, null)){
145 for(DescriptionBase description
: taxon
.getDescriptions()){
146 if(! description
.isImageGallery()){
147 Set
<Marker
> descriptionMarkers
= description
.getMarkers();
148 if(descriptionMarkers
!= null) {
149 for (Marker marker
: descriptionMarkers
) {
150 if(marker
.getMarkerType().getTitleCache().equals("use")) {
151 descriptions
.add(description
);
161 * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
164 public Object
getParent(Object element
) {
169 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
172 public Object
[] getElements(Object inputElement
) {
173 return getChildren(inputElement
);
177 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
182 public void dispose() {
183 featureNodeContainerCache
.clear();
187 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
190 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {}