*/
package eu.etaxonomy.taxeditor.view.derivateSearch;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
+import eu.etaxonomy.cdm.api.service.molecular.ISequenceService;
+import eu.etaxonomy.cdm.format.CdmFormatter;
+import eu.etaxonomy.cdm.format.ICdmFormatter.FormatKey;
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.common.DefinedTerm;
import eu.etaxonomy.cdm.model.molecular.DnaSample;
import eu.etaxonomy.cdm.model.molecular.Sequence;
import eu.etaxonomy.cdm.model.molecular.SingleRead;
+import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
private static final String NO_SAMPLE_DESIGNATION = "[no sample designation]";
- private Set<SingleRead> multiLinkSingleReads;
+ private static Set<SingleRead> multiLinkSingleReads;
+
+ private static Map<DerivedUnit, Collection<SpecimenTypeDesignation>> typeDesignations;
private ConversationHolder conversation;
/** {@inheritDoc} */
@Override
public String getText(Object element) {
- return getDerivateText(element);
+ if(element instanceof TreeNode){
+ element = ((TreeNode) element).getValue();
+ }
+ CdmFormatter formatter = new CdmFormatter(
+ FormatKey.GATHERING_COUNTRY, FormatKey.SPACE,
+ FormatKey.GATHERING_LOCALITY_TEXT, FormatKey.SPACE,
+ FormatKey.GATHERING_DATE, FormatKey.SPACE,
+ FormatKey.GATHERING_COLLECTOR, FormatKey.SPACE,
+ FormatKey.FIELD_NUMBER, FormatKey.SPACE,
+ FormatKey.COLLECTION_CODE, FormatKey.SPACE,
+ FormatKey.MOST_SIGNIFICANT_IDENTIFIER, FormatKey.SPACE,
+ FormatKey.KIND_OF_UNIT, FormatKey.SPACE,
+ FormatKey.SAMPLE_DESIGNATION, FormatKey.SPACE,
+ FormatKey.SINGLE_READ_PRIMER, FormatKey.SPACE,
+ FormatKey.SEQUENCE_DNA_MARKER, FormatKey.SPACE,
+ FormatKey.AMPLIFICATION_LABEL, FormatKey.SPACE,
+ FormatKey.MEDIA_TITLE, FormatKey.SPACE,
+ FormatKey.MEDIA_ARTIST, FormatKey.SPACE
+ );
+ return formatter.format(element);
}
/** {@inheritDoc} */
derivate = node.getValue();
}
- conversation.bind();
+ if(conversation!=null){
+ conversation.bind();
+ }
final String emptyString = "";
final String separator = " ";
FieldUnit fieldUnit = (FieldUnit)derivate;
if(fieldUnit.getGatheringEvent()!=null){
GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
- if(CdmStore.getService(IOccurrenceService.class).exists(fieldUnit.getUuid()) && !conversation.getSession().contains(gatheringEvent)){
- fieldUnit = (FieldUnit) CdmStore.getService(IOccurrenceService.class).load(fieldUnit.getUuid());
- gatheringEvent = fieldUnit.getGatheringEvent();
- }
label += gatheringEvent.getCountry()!=null?gatheringEvent.getCountry().getLabel()+separator:emptyString;
label += gatheringEvent.getLocality()!=null?gatheringEvent.getLocality().getText()+separator:emptyString;
label += gatheringEvent.getGatheringDate()!=null?gatheringEvent.getGatheringDate()+separator:emptyString;
else if(derivate instanceof DerivedUnit){
DerivedUnit derivedUnit = (DerivedUnit)derivate;
if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.PreservedSpecimen){
- java.util.Collection<FieldUnit> fieldUnits = CdmStore.getService(IOccurrenceService.class).getFieldUnits(derivedUnit.getUuid());
- if(fieldUnits!=null && !fieldUnits.isEmpty()){
- FieldUnit fieldUnit = fieldUnits.iterator().next();
- GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
-// gatheringEvent = HibernateProxyHelper.deproxy(gatheringEvent, GatheringEvent.class);
- if(gatheringEvent!=null){
- label += gatheringEvent.getCollector()!=null?gatheringEvent.getCollector()+separator:emptyString;
+ //check for type designation
+ if(typeDesignations.get(derivedUnit)==null){
+ for (SpecimenTypeDesignation specimenTypeDesignation : CdmStore.getService(IOccurrenceService.class).listTypeDesignations(derivedUnit, null, null, null, null)) {
+ addTypeDesignation(derivedUnit, specimenTypeDesignation);
}
- label += fieldUnit.getFieldNumber()!=null?fieldUnit.getFieldNumber()+separator:emptyString;
}
+ //java.util.Collection<FieldUnit> fieldUnits = CdmStore.getService(IOccurrenceService.class).getFieldUnits(derivedUnit.getUuid());
+ //TODO : This is not generic anymore for performance reasons
+ Set<SpecimenOrObservationBase> originals = derivedUnit.getOriginals();
+ if(originals!=null && originals.size() ==1) {
+ SpecimenOrObservationBase specimen = originals.iterator().next();
+ if(specimen instanceof FieldUnit) {
+ FieldUnit fieldUnit = (FieldUnit)specimen;
+ GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
+ if(gatheringEvent!=null){
+ label += gatheringEvent.getCollector()!=null?gatheringEvent.getCollector()+separator:emptyString;
+ }
+ label += fieldUnit.getFieldNumber()!=null?fieldUnit.getFieldNumber()+separator:emptyString;
+ }
+ }
+
eu.etaxonomy.cdm.model.occurrence.Collection collection = derivedUnit.getCollection();
if(collection!=null){
label += collection.getCode()!=null?"("+collection.getCode()+")"+separator:emptyString;
}
- String mostSignificantIdentifier = CdmStore.getService(IOccurrenceService.class).getMostSignificantIdentifier(derivedUnit);
+ String mostSignificantIdentifier = derivedUnit.getMostSignificantIdentifier();
label += mostSignificantIdentifier!=null?mostSignificantIdentifier+separator:emptyString;
}
else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.TissueSample){
return label;
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ColumnLabelProvider#getImage(java.lang.Object)
- */
@Override
public Image getImage(Object element) {
if(element instanceof TreeNode){
boolean hasCharacterData = false;
if(cdmBase.isInstanceOf(SpecimenOrObservationBase.class)){
SpecimenOrObservationBase<?> specimen = HibernateProxyHelper.deproxy(cdmBase, SpecimenOrObservationBase.class);
- if(!CdmStore.getService(IOccurrenceService.class).getCharacterDataForSpecimen(specimen).isEmpty()){
+ if(specimen.hasCharacterData()){
hasCharacterData = true;
}
}
}
else if(cdmBase.isInstanceOf(DerivedUnit.class)){
DerivedUnit derivedUnit = HibernateProxyHelper.deproxy(element, DerivedUnit.class);
+
if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.FieldUnit){
return hasCharacterData?ImageResources.getImage(ImageResources.FIELD_UNIT_CHARACTER_DATA):ImageResources.getImage(ImageResources.FIELD_UNIT);
}
return hasCharacterData?ImageResources.getImage(ImageResources.TISSUE_SAMPLE_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.TISSUE_SAMPLE_DERIVATE);
}
else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.PreservedSpecimen){
+ if(typeDesignations.get(derivedUnit)!=null && !typeDesignations.get(derivedUnit).isEmpty()){
+ return ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE_TYPE);
+ }
return hasCharacterData?ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE);
}
else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.Media){
}
else if(cdmBase.isInstanceOf(SingleRead.class)){
- if(multiLinkSingleReads.contains(element)){
+ if(multiLinkSingleReads!=null && multiLinkSingleReads.contains(element)){
return ImageResources.getImage(ImageResources.SINGLE_READ_DERIVATE_MULTILINK);
}
else{
return null;
}
- /**
- * @param multiLinkSingleReads2
- */
- public void setMultiLinkSingleReads(Set<SingleRead> multiLinkSingleReads) {
- this.multiLinkSingleReads = multiLinkSingleReads;
+ private static void addTypeDesignation(DerivedUnit derivedUnit, SpecimenTypeDesignation typeDesignation){
+ Collection<SpecimenTypeDesignation> list = typeDesignations.get(derivedUnit);
+ if(list==null){
+ list = new ArrayList<SpecimenTypeDesignation>();
+ }
+ list.add(typeDesignation);
+ typeDesignations.put(derivedUnit, list);
+ }
+
+ public static Set<SingleRead> getMultiLinkSingleReads() {
+ return multiLinkSingleReads;
+ }
+
+ public void updateLabelCache(Collection<SpecimenOrObservationBase<?>> rootElements) {
+ DerivateLabelProvider.multiLinkSingleReads = new HashSet<SingleRead>();
+ DerivateLabelProvider.typeDesignations = new HashMap<DerivedUnit, Collection<SpecimenTypeDesignation>>();
+ for(Entry<SingleRead, Collection<Sequence>> entry:CdmStore.getService(ISequenceService.class).getSingleReadSequencesMap().entrySet()){
+ if(entry.getValue().size()>1){
+ multiLinkSingleReads.add(entry.getKey());
+ }
+ }
+ if(rootElements!=null){
+ Collection<DerivedUnit> derivedUnits = new ArrayList<DerivedUnit>();
+ for (SpecimenOrObservationBase specimenOrObservationBase : rootElements) {
+ derivedUnits.addAll(CdmStore.getService(IOccurrenceService.class).getAllChildDerivatives(specimenOrObservationBase.getUuid()));
+ if(specimenOrObservationBase.isInstanceOf(DerivedUnit.class)){
+ derivedUnits.add(HibernateProxyHelper.deproxy(specimenOrObservationBase, DerivedUnit.class));
+ }
+ }
+ typeDesignations = CdmStore.getService(IOccurrenceService.class).listTypeDesignations(derivedUnits, null, null, null, null);
+ }
}
}