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
.Feature
;
18 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
19 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
21 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.IDefinedTermDao
;
22 import eu
.etaxonomy
.taxeditor
.editor
.TaxonEditorInput
;
23 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
24 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainerTree
;
25 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
26 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
27 import eu
.etaxonomy
.taxeditor
.store
.TermStore
;
29 public class UsesContentProvider
implements ITreeContentProvider
{
31 private static final Object
[] NO_CHILDREN
= new Object
[0];
32 private Map
<TaxonDescription
, FeatureNodeContainerTree
> featureNodeContainerCache
;
33 Set
<MarkerType
> markerTypes
= new HashSet
<MarkerType
>();
36 * <p>Constructor for DescriptiveContentProvider.</p>
38 * @param featureNodeContainerCache a {@link java.util.Map} object.
40 public UsesContentProvider(Map
<TaxonDescription
, FeatureNodeContainerTree
> featureNodeContainerCache
) {
41 //MarkerType markerType = (MarkerType)this.definedTermDao.findByUuid(UUID.fromString("b4b1b2ab-89a8-4ce6-8110-d60b8b1bc433")); //Marker "complete"
42 //this.markerTypes.addAll(CdmStore.getTermManager().getPreferredMarkerTypes());
43 this.featureNodeContainerCache
= featureNodeContainerCache
;
49 * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
52 public Object
[] getChildren(Object parentElement
) {
53 if (parentElement
instanceof TaxonEditorInput
) {
54 return getDescriptions((TaxonEditorInput
) parentElement
).toArray();
56 else if (parentElement
instanceof TaxonDescription
) {
57 if ( ! ((TaxonDescription
) parentElement
).isImageGallery()) {
58 TaxonDescription description
= (TaxonDescription
) parentElement
;
60 FeatureNodeContainerTree containerTree
= getContainerTreeForDesription(description
);
62 return containerTree
.getRoot().getChildren().toArray();
65 else if (parentElement
instanceof FeatureNodeContainer
){
66 FeatureNodeContainer container
= (FeatureNodeContainer
) parentElement
;
67 if(container
.isLeaf()){
68 return container
.getDescriptionElements().toArray();
70 return container
.getChildren().toArray();
77 private FeatureNodeContainerTree
getContainerTreeForDesription(TaxonDescription description
){
78 if(! featureNodeContainerCache
.containsKey(description
)){
79 FeatureNodeContainerTree containerTree
= new FeatureNodeContainerTree(description
, getFeatureTree(description
));
80 featureNodeContainerCache
.put(description
, containerTree
);
82 return featureNodeContainerCache
.get(description
);
87 public boolean hasChildren(Object element
) {
88 if (element
instanceof TaxonDescription
){
89 TaxonDescription description
= (TaxonDescription
) element
;
90 FeatureNodeContainerTree containerTree
= featureNodeContainerCache
.get(description
);
91 if(containerTree
!= null && containerTree
.getRoot() != null){
92 return containerTree
.getRoot().getChildren().size() != 0;
95 return getChildren(element
).length
!= 0;
99 * Retrieves the feature tree associated with the given description
101 * TODO as of now this is always the same thing because feature trees may not be associated
102 * to descriptions yet.
107 private FeatureTree
getFeatureTree(DescriptionBase description
){
108 FeatureTree featureTree
= null;
110 // TODO change this to the feature tree associated with this taxon description
111 if (description
.hasStructuredData()){
112 featureTree
= PreferencesUtil
.getDefaultFeatureTreeForStructuredDescription();
114 featureTree
= PreferencesUtil
.getDefaultFeatureTreeForTextualDescription();
117 // create a transient tree with all features if none was selected
118 if(featureTree
== null){
119 featureTree
= FeatureTree
.NewInstance(TermStore
.getTerms(Feature
.class));
126 * Get all descriptions associated with the given TaxonEditorInput
128 * @param parentElement
131 //CdmStore.getService(IDescriptionService.class).listTaxonDescriptions(input.getTaxonNode().getTaxon(), null, null, null, null, null, null)
132 private List
<DescriptionBase
> getDescriptions(TaxonEditorInput parentElement
) {
133 //this.markerTypes.addAll(CdmStore.getTermManager().getPreferredMarkerTypes());
134 this.markerTypes
.addAll(CdmStore
.getTermManager().getPreferredTerms(MarkerType
.class));
135 Taxon taxon
= parentElement
.getTaxon();
136 Set
<MarkerType
> typesToDisdplay
= new HashSet
<MarkerType
>();
137 List
<DescriptionBase
> descriptions
= new ArrayList
<DescriptionBase
>();
138 List
<TaxonDescription
> usesDescriptions
= new ArrayList
<TaxonDescription
>();
140 /*for (MarkerType markerType : markerTypes) {
141 if (markerType.toString().equals("complete")) {
142 typesToDisdplay.add(markerType);
145 //usesDescriptions = CdmStore.getService(IDescriptionService.class).listTaxonDescriptions(taxon, null, null, typesToDisdplay, null, null, null);
146 //for(DescriptionBase description : CdmStore.getService(IDescriptionService.class).listTaxonDescriptions(taxon, null, null, typesToDisdplay, null, null, null)){
147 for(DescriptionBase description
: taxon
.getDescriptions()){
148 if(! description
.isImageGallery()){
149 Set
<Marker
> descriptionMarkers
= description
.getMarkers();
150 if(descriptionMarkers
!= null) {
151 for (Marker marker
: descriptionMarkers
) {
152 //TODO Use the GetbyUUID method
153 if(marker
.getMarkerType().getTitleCache().equals("use")) {
154 descriptions
.add(description
);
164 * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
167 public Object
getParent(Object element
) {
172 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
175 public Object
[] getElements(Object inputElement
) {
176 return getChildren(inputElement
);
180 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
185 public void dispose() {
186 featureNodeContainerCache
.clear();
190 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
193 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {}