package eu.etaxonomy.taxeditor.editor.view.descriptive;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
-import eu.etaxonomy.cdm.api.service.ITermService;
import eu.etaxonomy.cdm.model.common.Marker;
-import eu.etaxonomy.cdm.model.common.MarkerType;
import eu.etaxonomy.cdm.model.description.DescriptionBase;
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
import eu.etaxonomy.cdm.model.description.Feature;
import eu.etaxonomy.cdm.model.description.FeatureTree;
import eu.etaxonomy.cdm.model.description.IDescribable;
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
-import eu.etaxonomy.taxeditor.editor.UsageTermCollection;
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
import eu.etaxonomy.taxeditor.model.FeatureNodeContainerTree;
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
-import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.store.TermStore;
+import eu.etaxonomy.taxeditor.store.UsageTermCollection;
/**
* <p>DescriptiveContentProvider class.</p>
protected static final Object[] NO_CHILDREN = new Object[0];
protected Map<DescriptionBase<?>, FeatureNodeContainerTree> featureNodeContainerCache;
private boolean showOnlyIndividualAssociations;
+ private static FeatureTree defaultFeatureTree = null;
public DescriptiveContentProvider(Map<DescriptionBase<?>, FeatureNodeContainerTree> featureNodeContainerCache) {
this(featureNodeContainerCache, false);
FeatureNodeContainer container = (FeatureNodeContainer) parentElement;
if(container.isLeaf()){
List<DescriptionElementBase> descriptionElements = container.getDescriptionElements();
- if(showOnlyIndividualAssociations){
- List<DescriptionElementBase> filteredDescriptionElements = new ArrayList<DescriptionElementBase>();
- for (DescriptionElementBase descriptionElement : descriptionElements) {
- if(descriptionElement instanceof IndividualsAssociation){
- filteredDescriptionElements.add(descriptionElement);
- }
+ List<IndividualsAssociation> individualAssociations = new ArrayList<IndividualsAssociation>();
+ for (DescriptionElementBase descriptionElement : descriptionElements) {
+ if(descriptionElement instanceof IndividualsAssociation){
+ individualAssociations.add((IndividualsAssociation) descriptionElement);
}
- descriptionElements = filteredDescriptionElements;
+ }
+ //sort individual associations by title cache of associated specimens
+ Collections.sort(individualAssociations, new Comparator<IndividualsAssociation>() {
+
+ @Override
+ public int compare(IndividualsAssociation o1, IndividualsAssociation o2) {
+ if(o1==null || o1.getAssociatedSpecimenOrObservation()==null){
+ return -1;
+ }
+ if(o2==null || o2.getAssociatedSpecimenOrObservation()==null){
+ return 1;
+ }
+ return o1.getAssociatedSpecimenOrObservation().compareTo(o2.getAssociatedSpecimenOrObservation());
+ }
+ });
+ if(showOnlyIndividualAssociations){
+ descriptionElements = new ArrayList<DescriptionElementBase>(individualAssociations);
}
return descriptionElements.toArray();
}else{
* @return
*/
private FeatureTree getFeatureTree(DescriptionBase description){
- FeatureTree featureTree = null;
+ if(defaultFeatureTree == null) {
+ defaultFeatureTree = FeatureTree.NewInstance(TermStore.getTerms(Feature.class));
+ }
+ FeatureTree featureTree;
// TODO change this to the feature tree associated with this taxon description
if (description.hasStructuredData()){
featureTree = PreferencesUtil.getDefaultFeatureTreeForStructuredDescription();
// create a transient tree with all features if none was selected
if(featureTree == null){
- featureTree = FeatureTree.NewInstance(TermStore.getTerms(Feature.class));
+ featureTree = defaultFeatureTree;
}
return featureTree;
List<DescriptionBase<?>> resultDescriptions = new ArrayList<DescriptionBase<?>>();
for(DescriptionBase<?> description : elementDescriptions){
if(! description.isImageGallery()){
- MarkerType useMarkertype = (MarkerType) CdmStore.getService(ITermService.class).find(UsageTermCollection.uuidUseMarkerType);
Set<Marker> descriptionMarkers = description.getMarkers();
if(descriptionMarkers != null && !descriptionMarkers.isEmpty()) {
for (Marker marker: descriptionMarkers) {
- if(!(marker.getMarkerType().equals(useMarkertype))) {
+ if(marker.getMarkerType() != null && !(marker.getMarkerType().getUuid().equals(UsageTermCollection.uuidUseMarkerType))) {
resultDescriptions.add(description);
}
}
return resultDescriptions;
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
- */
/** {@inheritDoc} */
@Override
public Object getParent(Object element) {
return null;
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- */
/** {@inheritDoc} */
@Override
public Object[] getElements(Object inputElement) {
return getChildren(inputElement);
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- */
/**
* <p>dispose</p>
*/
featureNodeContainerCache.clear();
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
- */
/** {@inheritDoc} */
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}