+/**\r
+ * Copyright (C) 2011 EDIT\r
+ * European Distributed Institute of Taxonomy \r
+ * http://www.e-taxonomy.eu\r
+ * \r
+ * The contents of this file are subject to the Mozilla Public License Version 1.1\r
+ * See LICENSE.TXT at the top of this package for the full license terms.\r
+ */\r
package eu.etaxonomy.taxeditor.editor.view.uses;\r
\r
import java.util.ArrayList;\r
import java.util.List;\r
import java.util.Map;\r
import java.util.Set;\r
-import java.util.UUID;\r
\r
import org.eclipse.jface.viewers.ITreeContentProvider;\r
import org.eclipse.jface.viewers.Viewer;\r
\r
-import eu.etaxonomy.cdm.api.service.IDescriptionService;\r
+import eu.etaxonomy.cdm.api.service.ITermService;\r
import eu.etaxonomy.cdm.model.common.Marker;\r
import eu.etaxonomy.cdm.model.common.MarkerType;\r
import eu.etaxonomy.cdm.model.description.DescriptionBase;\r
+import eu.etaxonomy.cdm.model.description.Feature;\r
import eu.etaxonomy.cdm.model.description.FeatureTree;\r
import eu.etaxonomy.cdm.model.description.TaxonDescription;\r
import eu.etaxonomy.cdm.model.taxon.Taxon;\r
-import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao;\r
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;\r
+import eu.etaxonomy.taxeditor.editor.UsageTermCollection;\r
+import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveContentProvider;\r
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;\r
import eu.etaxonomy.taxeditor.model.FeatureNodeContainerTree;\r
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;\r
import eu.etaxonomy.taxeditor.store.CdmStore;\r
import eu.etaxonomy.taxeditor.store.TermStore;\r
\r
-public class UsesContentProvider implements ITreeContentProvider {\r
+/**\r
+ * The class provides the required content to the Uses View\r
+ * @author a.theys \r
+ * @created mar 13, 2012\r
+ * @version 1.0\r
+ */\r
+public class UsesContentProvider extends DescriptiveContentProvider implements ITreeContentProvider {\r
\r
- private static final Object[] NO_CHILDREN = new Object[0];\r
- private Map<TaxonDescription, FeatureNodeContainerTree> featureNodeContainerCache;\r
Set<MarkerType> markerTypes = new HashSet<MarkerType>();\r
\r
/**\r
* @param featureNodeContainerCache a {@link java.util.Map} object.\r
*/\r
public UsesContentProvider(Map<TaxonDescription, FeatureNodeContainerTree> featureNodeContainerCache) {\r
- //MarkerType markerType = (MarkerType)this.definedTermDao.findByUuid(UUID.fromString("b4b1b2ab-89a8-4ce6-8110-d60b8b1bc433")); //Marker "complete"\r
- //this.markerTypes.addAll(CdmStore.getTermManager().getPreferredMarkerTypes());\r
+ super(featureNodeContainerCache);\r
this.featureNodeContainerCache = featureNodeContainerCache;\r
}\r
- \r
-\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)\r
- */\r
- /** {@inheritDoc} */\r
- public Object[] getChildren(Object parentElement) {\r
- if (parentElement instanceof TaxonEditorInput) {\r
- return getDescriptions((TaxonEditorInput) parentElement).toArray(); \r
- }\r
- else if (parentElement instanceof TaxonDescription) {\r
- if ( ! ((TaxonDescription) parentElement).isImageGallery()) {\r
- TaxonDescription description = (TaxonDescription) parentElement;\r
- \r
- FeatureNodeContainerTree containerTree = getContainerTreeForDesription(description);\r
- \r
- return containerTree.getRoot().getChildren().toArray();\r
- }\r
- }\r
- else if (parentElement instanceof FeatureNodeContainer){\r
- FeatureNodeContainer container = (FeatureNodeContainer) parentElement;\r
- if(container.isLeaf()){\r
- return container.getDescriptionElements().toArray();\r
- }else{\r
- return container.getChildren().toArray();\r
- }\r
- }\r
- \r
- return NO_CHILDREN;\r
- }\r
- \r
- private FeatureNodeContainerTree getContainerTreeForDesription(TaxonDescription description){\r
- if(! featureNodeContainerCache.containsKey(description)){\r
- FeatureNodeContainerTree containerTree = new FeatureNodeContainerTree(description, getFeatureTree(description));\r
- featureNodeContainerCache.put(description, containerTree);\r
- }\r
- return featureNodeContainerCache.get(description);\r
- }\r
-\r
- /** {@inheritDoc} */\r
- @Override\r
- public boolean hasChildren(Object element) {\r
- if (element instanceof TaxonDescription){\r
- TaxonDescription description = (TaxonDescription) element;\r
- FeatureNodeContainerTree containerTree = featureNodeContainerCache.get(description);\r
- if(containerTree != null && containerTree.getRoot() != null){\r
- return containerTree.getRoot().getChildren().size() != 0;\r
- }\r
- } \r
- return getChildren(element).length != 0;\r
- }\r
- \r
- /**\r
- * Retrieves the feature tree associated with the given description\r
- * \r
- * TODO as of now this is always the same thing because feature trees may not be associated \r
- * to descriptions yet.\r
- * \r
- * @param description\r
- * @return\r
- */\r
- private FeatureTree getFeatureTree(DescriptionBase description){\r
- FeatureTree featureTree = null;\r
- \r
- // TODO change this to the feature tree associated with this taxon description\r
- if (description.hasStructuredData()){ \r
- featureTree = PreferencesUtil.getDefaultFeatureTreeForStructuredDescription();\r
- }else{\r
- featureTree = PreferencesUtil.getDefaultFeatureTreeForTextualDescription();\r
- }\r
- \r
- // create a transient tree with all features if none was selected\r
- if(featureTree == null){\r
- featureTree = FeatureTree.NewInstance(TermStore.getFeatures());\r
- }\r
- \r
- return featureTree;\r
- }\r
\r
/**\r
* Get all descriptions associated with the given TaxonEditorInput\r
* @param parentElement\r
* @return\r
*/\r
- //CdmStore.getService(IDescriptionService.class).listTaxonDescriptions(input.getTaxonNode().getTaxon(), null, null, null, null, null, null)\r
- private List<DescriptionBase> getDescriptions(TaxonEditorInput parentElement) {\r
- this.markerTypes.addAll(CdmStore.getTermManager().getPreferredMarkerTypes());\r
+ @Override\r
+ protected List<DescriptionBase> getDescriptions(TaxonEditorInput parentElement) {\r
+ this.markerTypes.addAll(CdmStore.getTermManager().getPreferredTerms(MarkerType.class));\r
Taxon taxon = parentElement.getTaxon();\r
- Set<MarkerType> typesToDisdplay = new HashSet<MarkerType>();\r
List<DescriptionBase> descriptions = new ArrayList<DescriptionBase>();\r
- List<TaxonDescription> usesDescriptions = new ArrayList<TaxonDescription>();\r
\r
- /*for (MarkerType markerType : markerTypes) {\r
- if (markerType.toString().equals("complete")) {\r
- typesToDisdplay.add(markerType);\r
- }\r
- }*/\r
- //usesDescriptions = CdmStore.getService(IDescriptionService.class).listTaxonDescriptions(taxon, null, null, typesToDisdplay, null, null, null);\r
- //for(DescriptionBase description : CdmStore.getService(IDescriptionService.class).listTaxonDescriptions(taxon, null, null, typesToDisdplay, null, null, null)){\r
for(DescriptionBase description : taxon.getDescriptions()){\r
if(! description.isImageGallery()){\r
+ MarkerType useMarkertype = (MarkerType) CdmStore.getService(ITermService.class).find(UsageTermCollection.uuidUseMarkerType);\r
Set<Marker> descriptionMarkers = description.getMarkers();\r
if(descriptionMarkers != null) {\r
for (Marker marker: descriptionMarkers) {\r
- if(marker.getMarkerType().getTitleCache().equals("use")) {\r
+ if(marker.getMarkerType().equals(useMarkertype)) {\r
descriptions.add(description);\r
}\r
}\r
return descriptions;\r
}\r
\r
- /* (non-Javadoc)\r
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)\r
- */\r
- /** {@inheritDoc} */\r
- public Object getParent(Object element) {\r
- return null;\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)\r
- */\r
- /** {@inheritDoc} */\r
- public Object[] getElements(Object inputElement) {\r
- return getChildren(inputElement);\r
- }\r
- \r
- /* (non-Javadoc)\r
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()\r
- */\r
- /**\r
- * <p>dispose</p>\r
- */\r
- public void dispose() {\r
- featureNodeContainerCache.clear();\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)\r
- */\r
- /** {@inheritDoc} */\r
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} \r
-\r
}\r