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.TaxonDescription;
-import eu.etaxonomy.cdm.model.taxon.Taxon;
-import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
+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;
public class DescriptiveContentProvider implements ITreeContentProvider {
protected static final Object[] NO_CHILDREN = new Object[0];
- protected Map<TaxonDescription, FeatureNodeContainerTree> featureNodeContainerCache;
+ protected Map<DescriptionBase<?>, FeatureNodeContainerTree> featureNodeContainerCache;
+ private boolean showOnlyIndividualAssociations;
+ public DescriptiveContentProvider(Map<DescriptionBase<?>, FeatureNodeContainerTree> featureNodeContainerCache) {
+ this(featureNodeContainerCache, false);
+ }
/**
* <p>Constructor for DescriptiveContentProvider.</p>
*
* @param featureNodeContainerCache a {@link java.util.Map} object.
*/
- public DescriptiveContentProvider(Map<TaxonDescription, FeatureNodeContainerTree> featureNodeContainerCache) {
+ public DescriptiveContentProvider(Map<DescriptionBase<?>, FeatureNodeContainerTree> featureNodeContainerCache, boolean showOnlyIndividualAssociations) {
this.featureNodeContainerCache = featureNodeContainerCache;
+ this.showOnlyIndividualAssociations = showOnlyIndividualAssociations;
}
/* (non-Javadoc)
/** {@inheritDoc} */
@Override
public Object[] getChildren(Object parentElement) {
- if (parentElement instanceof TaxonEditorInput) {
- return getDescriptions((TaxonEditorInput) parentElement).toArray();
+ if (parentElement instanceof IDescribable<?>) {
+ return getDescriptions((IDescribable<?>) parentElement).toArray();
}
- else if (parentElement instanceof TaxonDescription) {
- if ( ! ((TaxonDescription) parentElement).isImageGallery()) {
- TaxonDescription description = (TaxonDescription) parentElement;
+ else if (parentElement instanceof DescriptionBase<?>) {
+ if ( ! ((DescriptionBase<?>) parentElement).isImageGallery()) {
+ DescriptionBase<?> description = (DescriptionBase<?>) parentElement;
FeatureNodeContainerTree containerTree = getContainerTreeForDesription(description);
-
- return containerTree.getRoot().getChildren().toArray();
+ List<FeatureNodeContainer> children = containerTree.getRoot().getChildren();
+ //filter out containers with no children
+ List<FeatureNodeContainer> childrenWithChildren = new ArrayList<FeatureNodeContainer>();
+ for (FeatureNodeContainer featureNodeContainer : children) {
+ if(getChildren(featureNodeContainer).length>0){
+ childrenWithChildren.add(featureNodeContainer);
+ }
+ }
+ return childrenWithChildren.toArray();
}
}
else if (parentElement instanceof FeatureNodeContainer){
FeatureNodeContainer container = (FeatureNodeContainer) parentElement;
if(container.isLeaf()){
- return container.getDescriptionElements().toArray();
+ List<DescriptionElementBase> descriptionElements = container.getDescriptionElements();
+ if(showOnlyIndividualAssociations){
+ List<DescriptionElementBase> filteredDescriptionElements = new ArrayList<DescriptionElementBase>();
+ for (DescriptionElementBase descriptionElement : descriptionElements) {
+ if(descriptionElement instanceof IndividualsAssociation){
+ filteredDescriptionElements.add(descriptionElement);
+ }
+ }
+ descriptionElements = filteredDescriptionElements;
+ }
+ return descriptionElements.toArray();
}else{
return container.getChildren().toArray();
}
return NO_CHILDREN;
}
- private FeatureNodeContainerTree getContainerTreeForDesription(TaxonDescription description){
+ private FeatureNodeContainerTree getContainerTreeForDesription(DescriptionBase<?> description){
if(! featureNodeContainerCache.containsKey(description)){
FeatureNodeContainerTree containerTree = new FeatureNodeContainerTree(description, getFeatureTree(description));
featureNodeContainerCache.put(description, containerTree);
/** {@inheritDoc} */
@Override
public boolean hasChildren(Object element) {
- if (element instanceof TaxonDescription){
- TaxonDescription description = (TaxonDescription) element;
+ if (element instanceof DescriptionBase<?>){
+ DescriptionBase<?> description = (DescriptionBase<?>) element;
FeatureNodeContainerTree containerTree = featureNodeContainerCache.get(description);
if(containerTree != null && containerTree.getRoot() != null){
return containerTree.getRoot().getChildren().size() != 0;
return featureTree;
}
- /**
- * Get all descriptions associated with the given TaxonEditorInput
- *
- * @param parentElement
- * @return
- */
- protected List<DescriptionBase> getDescriptions(TaxonEditorInput parentElement) {
- Taxon taxon = parentElement.getTaxon();
- List<DescriptionBase> descriptions = new ArrayList<DescriptionBase>();
- for(DescriptionBase description : taxon.getDescriptions()){
+ /**
+ * Get all descriptions associated with the given object
+ * @param parentElement
+ * @return
+ */
+ protected List<DescriptionBase<?>> getDescriptions(IDescribable<?> parentElement) {
+ Set<? extends DescriptionBase<?>> elementDescriptions = parentElement.getDescriptions();
+ 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))) {
- descriptions.add(description);
+ resultDescriptions.add(description);
}
}
}
else {
- descriptions.add(description);
+ resultDescriptions.add(description);
}
}
-
}
- return descriptions;
- }
+ return resultDescriptions;
+ }
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
+ public void toggleShowOnlyIndividualAssociations() {
+ showOnlyIndividualAssociations = !showOnlyIndividualAssociations;
+ }
+
}