import eu.etaxonomy.taxeditor.editor.workingSet.matrix.quantitative.QuantitativeDataCellEditor;
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.quantitative.QuantitativeDataDisplayConverter;
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.supplementalInfo.SupplementalInfoDisplayConverter;
+import eu.etaxonomy.taxeditor.model.DescriptionHelper;
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
import eu.etaxonomy.taxeditor.model.ImageResources;
}
private SpecimenDescription getDescriptionForWorkingSet(SpecimenOrObservationBase specimen){
- Set<SpecimenDescription> descriptions = specimen.getDescriptions();
- if(descriptions!=null){
- Set<Feature> features = workingSet.getDescriptiveSystem().getDistinctFeatures();
- for (SpecimenDescription specimenDescription : descriptions) {
- Set<Feature> specimenDescriptionFeatures = new HashSet<>();
- for (DescriptionElementBase descriptionElementBase : specimenDescription.getElements()) {
- specimenDescriptionFeatures.add(descriptionElementBase.getFeature());
- }
- if(specimenDescriptionFeatures.containsAll(features)){
- return specimenDescription;
+ Set<Feature> wsFeatures = workingSet.getDescriptiveSystem().getDistinctFeatures();
+ List<DescriptionElementBase> matchingDescriptionElements = new ArrayList<>();
+
+ for (SpecimenDescription specimenDescription : (Set<SpecimenDescription>) specimen.getDescriptions()) {
+ Set<Feature> specimenDescriptionFeatures = new HashSet<>();
+ //gather specimen description features and check for match with WS features
+ for (DescriptionElementBase specimenDescriptionElement : specimenDescription.getElements()) {
+ Feature feature = specimenDescriptionElement.getFeature();
+ specimenDescriptionFeatures.add(feature);
+ if(wsFeatures.contains(feature)){
+ matchingDescriptionElements.add(specimenDescriptionElement);
}
}
+ //if description with the exact same features is found return the description
+ if(specimenDescriptionFeatures.equals(wsFeatures)){
+ return specimenDescription;
+ }
}
//Create new specimen description if no match was found
setDirty();
SpecimenDescription newDesription = SpecimenDescription.NewInstance(specimen);
- newDesription.setTitleCache("WorkingSet "+workingSet.getLabel()+" "+newDesription.generateTitle(), true);
+ newDesription.setTitleCache("WorkingSet "+workingSet.getLabel()+": "+newDesription.generateTitle(), true);
+
+ //check for equals description element (same feature and TODO: same values)
+ matchingDescriptionElements.forEach(element ->
+ {
+ if(matchingDescriptionElements.contains(element)){
+ MessagingUtils.informationDialog("Multiple data found",
+ String.format("Multiple description elements"
+ // + " with different values "
+ + "found for feature %s. "
+ + "Data will not be copied to new specimen description", element.getFeature().getLabel()));
+ }
+ else{
+ DescriptionElementBase clone;
+ try {
+ clone = element.clone(newDesription);
+ clone.getSources().forEach(source -> source.setOriginalNameString(DescriptionHelper.getLabel(element)));
+ } catch (CloneNotSupportedException e) {
+ MessagingUtils.error(CharacterMatrix.class, e);
+ }
+ }
+ });
return newDesription;
}