Revision 5c025bd1
Added by Patrick Plitzner over 6 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/CharacterMatrix.java | ||
---|---|---|
1 | 1 |
/** |
2 |
* Copyright (C) 2017 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
2 |
* Copyright (C) 2017 EDIT
|
|
3 |
* European Distributed Institute of Taxonomy
|
|
4 |
* http://www.e-taxonomy.eu
|
|
5 |
*
|
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms.
|
|
8 |
*/
|
|
9 | 9 |
package eu.etaxonomy.taxeditor.editor.workingSet.matrix; |
10 | 10 |
|
11 | 11 |
import java.io.File; |
... | ... | |
140 | 140 |
* |
141 | 141 |
*/ |
142 | 142 |
public class CharacterMatrix implements IE4SavablePart, IPartContentHasDetails, IConversationEnabled, IDirtyMarkable, |
143 |
ICdmEntitySessionEnabled{
|
|
143 |
ICdmEntitySessionEnabled{ |
|
144 | 144 |
|
145 | 145 |
private static final List<String> WS_PROPERTY_PATH = Arrays.asList(new String[] { |
146 | 146 |
"descriptions", //$NON-NLS-1$ |
... | ... | |
257 | 257 |
^ |
258 | 258 |
DataLayer |
259 | 259 |
|
260 |
*
|
|
260 |
* |
|
261 | 261 |
|
262 | 262 |
*/ |
263 | 263 |
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider); |
... | ... | |
327 | 327 |
// delegates the sorting to the SortedList |
328 | 328 |
final SortHeaderLayer<SpecimenDescription> sortHeaderLayer = new SortHeaderLayer<>( |
329 | 329 |
columnHeaderLayer, |
330 |
new GlazedListsSortModel<>(
|
|
331 |
sortedList,
|
|
332 |
columnPropertyAccessor,
|
|
333 |
configRegistry,
|
|
334 |
columnHeaderDataLayer));
|
|
330 |
new GlazedListsSortModel<>( |
|
331 |
sortedList, |
|
332 |
columnPropertyAccessor, |
|
333 |
configRegistry, |
|
334 |
columnHeaderDataLayer)); |
|
335 | 335 |
|
336 | 336 |
|
337 | 337 |
/** |
... | ... | |
372 | 372 |
natTable.addConfiguration(new DefaultNatTableStyleConfiguration()); |
373 | 373 |
|
374 | 374 |
//FIXME: this is for DEBUG ONLY |
375 |
// natTable.addConfiguration(new DebugMenuConfiguration(natTable)); |
|
375 |
// natTable.addConfiguration(new DebugMenuConfiguration(natTable));
|
|
376 | 376 |
|
377 | 377 |
// override the default sort configuration and change the mouse bindings |
378 | 378 |
// to sort on a single click |
... | ... | |
617 | 617 |
SpecimenDescription newDesription = SpecimenDescription.NewInstance(specimen); |
618 | 618 |
newDesription.setTitleCache("WorkingSet "+workingSet.getLabel()+": "+newDesription.generateTitle(), true); |
619 | 619 |
|
620 |
//check for equals description element (same feature and TODO: same values) |
|
621 |
matchingDescriptionElements.forEach(element -> |
|
622 |
{ |
|
623 |
if(matchingDescriptionElements.contains(element)){ |
|
624 |
MessagingUtils.informationDialog("Multiple data found", |
|
625 |
String.format("Multiple description elements" |
|
626 |
// + " with different values " |
|
627 |
+ "found for feature %s. " |
|
628 |
+ "Data will not be copied to new specimen description", element.getFeature().getLabel())); |
|
620 |
//check for equals description element (same feature and same values) |
|
621 |
Map<Feature, List<DescriptionElementBase>> featureToElementMap = new HashMap<>(); |
|
622 |
for(DescriptionElementBase element:matchingDescriptionElements){ |
|
623 |
List<DescriptionElementBase> list = featureToElementMap.get(element.getFeature()); |
|
624 |
if(list==null){ |
|
625 |
list = new ArrayList<>(); |
|
629 | 626 |
} |
627 |
list.add(element); |
|
628 |
featureToElementMap.put(element.getFeature(), list); |
|
629 |
} |
|
630 |
Set<DescriptionElementBase> descriptionElementsToClone = new HashSet<>(); |
|
631 |
for(Feature feature:featureToElementMap.keySet()){ |
|
632 |
List<DescriptionElementBase> elements = featureToElementMap.get(feature); |
|
633 |
//no duplicate description elements found for this feature |
|
634 |
if(elements.size()==1){ |
|
635 |
descriptionElementsToClone.add(elements.get(0)); |
|
636 |
} |
|
637 |
//duplicates found -> check if all are equal |
|
630 | 638 |
else{ |
631 |
DescriptionElementBase clone; |
|
632 |
try { |
|
633 |
clone = element.clone(newDesription); |
|
634 |
clone.getSources().forEach(source -> source.setOriginalNameString(DescriptionHelper.getLabel(element))); |
|
635 |
} catch (CloneNotSupportedException e) { |
|
636 |
MessagingUtils.error(CharacterMatrix.class, e); |
|
639 |
DescriptionElementBase match = null; |
|
640 |
for (DescriptionElementBase descriptionElementBase : elements) { |
|
641 |
if(match==null){ |
|
642 |
match = descriptionElementBase; |
|
643 |
} |
|
644 |
else if(!new DescriptionElementCompareWrapper(match).equals(new DescriptionElementCompareWrapper(descriptionElementBase))){ |
|
645 |
match = null; |
|
646 |
MessagingUtils.informationDialog("Multiple data found", |
|
647 |
String.format("Multiple description elements with different values " |
|
648 |
+ "found for feature '%s'.\nData will not be copied to new specimen description.", feature.getLabel())); |
|
649 |
break; |
|
650 |
} |
|
651 |
} |
|
652 |
if(match!=null){ |
|
653 |
descriptionElementsToClone.add(match); |
|
637 | 654 |
} |
638 | 655 |
} |
639 |
}); |
|
656 |
} |
|
657 |
//clone matching descriptionElements |
|
658 |
for (DescriptionElementBase descriptionElementBase : descriptionElementsToClone) { |
|
659 |
DescriptionElementBase clone; |
|
660 |
try { |
|
661 |
clone = descriptionElementBase.clone(newDesription); |
|
662 |
clone.getSources().forEach(source -> source.setOriginalNameString(DescriptionHelper.getLabel(descriptionElementBase))); |
|
663 |
} catch (CloneNotSupportedException e) { |
|
664 |
MessagingUtils.error(CharacterMatrix.class, e); |
|
665 |
} |
|
666 |
} |
|
640 | 667 |
return newDesription; |
641 | 668 |
|
642 | 669 |
} |
Also available in: Unified diff
ref #7196 Check existing data value-wise