Revision ad2e9ab4
Added by Katja Luther over 5 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionColumnAccessor.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.taxeditor.editor.view.checklist.e4; |
10 | 10 |
|
11 |
import java.util.ArrayList; |
|
11 | 12 |
import java.util.HashMap; |
12 | 13 |
import java.util.HashSet; |
14 |
import java.util.List; |
|
13 | 15 |
import java.util.Map; |
14 | 16 |
import java.util.Set; |
15 | 17 |
|
... | ... | |
67 | 69 |
return distributionsForArea.iterator().next(); |
68 | 70 |
} |
69 | 71 |
if (distributionsForArea.size() > 1){ |
70 |
return distributionsForArea; |
|
72 |
List<String> labels = new ArrayList(); |
|
73 |
distributionsForArea.forEach(desc -> labels.add(((Distribution)desc).getStatus().getLabel())); |
|
74 |
return labels; |
|
71 | 75 |
} |
72 | 76 |
} |
73 | 77 |
return null; |
... | ... | |
134 | 138 |
if (descs.size() >= 1){ |
135 | 139 |
desc = descs.iterator().next(); |
136 | 140 |
}else { |
137 |
desc = TaxonDescription.NewInstance(taxonWrapper.getTaxon());
|
|
141 |
desc = TaxonDescription.NewInstance(); |
|
138 | 142 |
taxonWrapper.getDescriptionsWrapper().getDescriptions().add(desc); |
139 | 143 |
} |
140 | 144 |
desc.addElement(dist); |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionEditor.java | ||
---|---|---|
81 | 81 |
import eu.etaxonomy.cdm.model.common.TermIdInVocabularyComparator; |
82 | 82 |
import eu.etaxonomy.cdm.model.common.TermLanguageComparator; |
83 | 83 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
84 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
|
85 | 84 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
86 | 85 |
import eu.etaxonomy.cdm.model.description.Distribution; |
87 | 86 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
... | ... | |
136 | 135 |
EventList<TaxonDistributionDTO> taxonList; |
137 | 136 |
Map<UUID,Map<NamedArea,Set<DescriptionElementBase>>> taxonDistributionMap = new HashMap(); |
138 | 137 |
|
139 |
Set<TaxonDescription> descriptionsToSave;
|
|
138 |
List<TaxonDistributionDTO> descriptionsToSave = new ArrayList();
|
|
140 | 139 |
|
141 | 140 |
|
142 | 141 |
SortedSet<DefinedTermBase> areas; |
... | ... | |
213 | 212 |
} |
214 | 213 |
|
215 | 214 |
|
216 |
public Set<TaxonDescription> getDescriptionsToSave() {
|
|
215 |
public List<TaxonDistributionDTO> getDescriptionsToSave() {
|
|
217 | 216 |
return descriptionsToSave; |
218 | 217 |
} |
219 | 218 |
|
220 |
public void setDescriptionsToSave(Set<TaxonDescription> descriptionsToSave) {
|
|
219 |
public void setDescriptionsToSave(List<TaxonDistributionDTO> descriptionsToSave) {
|
|
221 | 220 |
this.descriptionsToSave = descriptionsToSave; |
222 | 221 |
} |
223 | 222 |
|
... | ... | |
437 | 436 |
|
438 | 437 |
@Override |
439 | 438 |
public void widgetSelected(SelectionEvent event) { |
440 |
defaultSource = ReferenceSelectionDialog.select(AbstractUtility.getShell(), null);
|
|
439 |
defaultSource = part.getCdmEntitySession().load(ReferenceSelectionDialog.select(AbstractUtility.getShell(), null), true);
|
|
441 | 440 |
|
442 | 441 |
String defaultSourceStr = (defaultSource == null) ? "" : "Default Source Reference: " + defaultSource.getTitleCache(); |
443 | 442 |
if (defaultSourceStr.length()> 100){ |
... | ... | |
487 | 486 |
} |
488 | 487 |
taxonList.stream().forEach(wrapper->DistributionEditor.this.taxonList.add(wrapper)); |
489 | 488 |
statusLabel.setText(ELEMENT_COUNT + (taxonList != null ? taxonList.size() : UNKNOWN)); |
490 |
Iterator<TaxonDistributionDTO> iterator = this.taxonList.iterator(); |
|
491 |
while (iterator.hasNext()){ |
|
492 |
TaxonDistributionDTO dto = iterator.next(); |
|
493 |
TaxonDescriptionDTO descriptionDto = dto.getDescriptionsWrapper(); |
|
494 |
for (TaxonDescription desc: descriptionDto.getDescriptions()){ |
|
495 |
for (DescriptionElementBase descElement: desc.getElements()){ |
|
496 |
if (descElement instanceof Distribution){ |
|
497 |
Map<NamedArea, Set<DescriptionElementBase>> distributionsMap = taxonDistributionMap.get(dto.getTaxonUuid()); |
|
498 |
|
|
499 |
if (distributionsMap == null){ |
|
500 |
distributionsMap = new HashMap(); |
|
501 |
taxonDistributionMap.put(dto.getTaxonUuid(), distributionsMap); |
|
502 |
} |
|
503 |
Set<DescriptionElementBase> distributions = distributionsMap.get(((Distribution) descElement).getArea()); |
|
504 |
if (distributions == null){ |
|
505 |
distributions = new HashSet(); |
|
506 |
distributionsMap.put(((Distribution)descElement).getArea(), distributions); |
|
507 |
} |
|
508 |
distributions.add(descElement); |
|
509 |
|
|
510 |
} |
|
511 |
} |
|
512 |
} |
|
513 |
} |
|
489 |
createTaxonDistributionMap(); |
|
514 | 490 |
} |
515 | 491 |
|
492 |
protected void createTaxonDistributionMap() { |
|
493 |
Iterator<TaxonDistributionDTO> iterator = this.taxonList.iterator(); |
|
494 |
while (iterator.hasNext()){ |
|
495 |
TaxonDistributionDTO dto = iterator.next(); |
|
496 |
TaxonDescriptionDTO descriptionDto = dto.getDescriptionsWrapper(); |
|
497 |
for (TaxonDescription desc: descriptionDto.getDescriptions()){ |
|
498 |
if(this.part.getCdmEntitySession()!=null){ |
|
499 |
this.part.getCdmEntitySession().load(desc, true); |
|
500 |
} |
|
501 |
for (DescriptionElementBase descElement: desc.getElements()){ |
|
502 |
if (descElement instanceof Distribution){ |
|
503 |
Map<NamedArea, Set<DescriptionElementBase>> distributionsMap = taxonDistributionMap.get(dto.getTaxonUuid()); |
|
504 |
|
|
505 |
if (distributionsMap == null){ |
|
506 |
distributionsMap = new HashMap(); |
|
507 |
taxonDistributionMap.put(dto.getTaxonUuid(), distributionsMap); |
|
508 |
} |
|
509 |
Set<DescriptionElementBase> distributions = distributionsMap.get(((Distribution) descElement).getArea()); |
|
510 |
if (distributions == null){ |
|
511 |
distributions = new HashSet(); |
|
512 |
distributionsMap.put(((Distribution)descElement).getArea(), distributions); |
|
513 |
} |
|
514 |
distributions.add(descElement); |
|
516 | 515 |
|
517 |
|
|
518 |
public List<DescriptionBase> getDistributions() { |
|
519 |
List<DescriptionBase> descriptions = new ArrayList(); |
|
520 |
|
|
521 |
taxonList.forEach(taxonDto -> taxonDto.getDescriptionsWrapper().getDescriptions().forEach(taxDesc -> descriptions.add(taxDesc))); |
|
522 |
|
|
523 |
for (DescriptionBase description: descriptions){ |
|
524 |
List<DescriptionElementBase> toDelete = new ArrayList(); |
|
525 |
for (Object desc: description.getElements()){ |
|
526 |
if (desc instanceof Distribution){ |
|
527 |
Distribution distribution = (Distribution) desc; |
|
528 |
if (distribution.getStatus() == null || !distribution.getStatus().isPersited()){ |
|
529 |
toDelete.add(distribution); |
|
516 |
} |
|
530 | 517 |
} |
531 | 518 |
} |
532 | 519 |
} |
533 |
for (DescriptionElementBase element: toDelete){ |
|
534 |
description.removeElement(element); |
|
535 |
} |
|
520 |
} |
|
536 | 521 |
|
537 |
} |
|
538 | 522 |
|
539 | 523 |
|
540 |
return descriptions; |
|
541 | 524 |
|
542 |
} |
|
543 | 525 |
|
544 | 526 |
private void initLabels() { |
545 | 527 |
|
... | ... | |
678 | 660 |
return defaultSource; |
679 | 661 |
} |
680 | 662 |
|
663 |
/** |
|
664 |
* @param result |
|
665 |
*/ |
|
666 |
public void reloadDistributions() { |
|
667 |
loadDistributions(taxonList); |
|
668 |
|
|
669 |
} |
|
670 |
|
|
681 | 671 |
|
682 | 672 |
|
683 | 673 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionEditorPart.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.taxeditor.editor.view.checklist.e4; |
10 | 10 |
|
11 |
import java.util.ArrayList; |
|
11 | 12 |
import java.util.Arrays; |
12 | 13 |
import java.util.Collection; |
14 |
import java.util.HashSet; |
|
13 | 15 |
import java.util.List; |
14 | 16 |
import java.util.Map; |
17 |
import java.util.Set; |
|
15 | 18 |
import java.util.UUID; |
16 | 19 |
|
17 | 20 |
import javax.annotation.PostConstruct; |
... | ... | |
172 | 175 |
|
173 | 176 |
@Override |
174 | 177 |
public List<DescriptionBase> getRootEntities() { |
175 |
return editor.getDistributions(); |
|
178 |
List<DescriptionBase> rootEntities = new ArrayList(); |
|
179 |
editor.taxonList.forEach(dto -> rootEntities.addAll(dto.getDescriptionsWrapper().getDescriptions())); |
|
180 |
return rootEntities; |
|
176 | 181 |
} |
177 | 182 |
|
178 | 183 |
/** |
... | ... | |
213 | 218 |
return conversation; |
214 | 219 |
} |
215 | 220 |
|
221 |
|
|
216 | 222 |
@Persist |
217 | 223 |
@Override |
218 | 224 |
public void save(IProgressMonitor monitor) { |
219 |
List<MergeResult<DescriptionBase>> result =CdmStore.getService(IDescriptionService.class).merge(editor.getDistributions(), true); |
|
220 |
// for (MergeResult mergeRes: result){ |
|
221 |
// mergeRes.getNewEntities() |
|
222 |
// } |
|
223 |
conversation.commit(); |
|
224 |
//editor.getDescriptionsToSave().clear(); |
|
225 |
|
|
226 |
dirty.setDirty(false); |
|
225 |
saveDistributions(); |
|
226 |
dirty.setDirty(false); |
|
227 |
} |
|
228 |
|
|
229 |
protected void saveDistributions() { |
|
230 |
Set<TaxonDistributionDTO> coll = new HashSet(); |
|
231 |
editor.taxonList.forEach(dto->coll.add(dto)); |
|
232 |
List<MergeResult<DescriptionBase>> result = CdmStore.getService(IDescriptionService.class).mergeDescriptionElements(coll, true); |
|
233 |
for (MergeResult<DescriptionBase> mergeRes: result ){ |
|
234 |
cdmEntitySession.load(mergeRes, true); |
|
235 |
} |
|
236 |
// editor.createTaxonDistributionMap(); |
|
237 |
conversation.commit(); |
|
238 |
this.dirty.setDirty(false); |
|
239 |
editor.getDescriptionsToSave().clear(); |
|
227 | 240 |
} |
228 | 241 |
|
229 | 242 |
/** |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/StatusDataCellEditor.java | ||
---|---|---|
27 | 27 |
import eu.etaxonomy.cdm.model.description.Distribution; |
28 | 28 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
29 | 29 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
30 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
31 | 30 |
|
32 | 31 |
/** |
33 | 32 |
* @author k.luther |
... | ... | |
64 | 63 |
}else if (elements.size() == 1){ |
65 | 64 |
DescriptionElementBase base = elements.iterator().next(); |
66 | 65 |
Distribution distr = (Distribution) base; |
66 |
editor.descriptionsToSave.add( (TaxonDistributionDTO) rowWrapper); |
|
67 | 67 |
//TODO set value corresponding to preference |
68 | 68 |
if (distr.getStatus() != null){ |
69 | 69 |
if (distr.getStatus().getLabel() == ""){ |
70 | 70 |
distr.setStatus(null); |
71 | 71 |
super.setCanonicalValue(""); |
72 |
|
|
72 | 73 |
}else{ |
73 | 74 |
super.setCanonicalValue(distr.getStatus().getLabel()); |
74 | 75 |
} |
... | ... | |
96 | 97 |
distributionMap.put(area, elements); |
97 | 98 |
} |
98 | 99 |
elements.add(newDistribution); |
99 |
// ((TaxonDistributionDTO) rowWrapper).getDistributionMap().put(area, elements); |
|
100 | 100 |
Set<TaxonDescription> descriptionSet = ((TaxonDistributionDTO) rowWrapper).getDescriptionsWrapper().getDescriptions(); |
101 | 101 |
Iterator<TaxonDescription> iterator = descriptionSet.iterator(); |
102 | 102 |
if (iterator.hasNext()){ |
103 |
iterator.next().addElement(newDistribution); |
|
103 |
TaxonDescription desc = iterator.next(); |
|
104 |
desc.addElement(newDistribution); |
|
105 |
editor.descriptionsToSave.add((TaxonDistributionDTO) rowWrapper); |
|
104 | 106 |
}else{ |
105 |
Taxon taxon = ((TaxonDistributionDTO) rowWrapper).getTaxon(); |
|
106 |
TaxonDescription desc = TaxonDescription.NewInstance(taxon);
|
|
107 |
|
|
108 |
TaxonDescription desc = TaxonDescription.NewInstance(); |
|
107 | 109 |
desc.addElement(newDistribution); |
108 | 110 |
((TaxonDistributionDTO) rowWrapper).getDescriptionsWrapper().getDescriptions().add(desc); |
111 |
editor.descriptionsToSave.add((TaxonDistributionDTO) rowWrapper); |
|
109 | 112 |
} |
110 | 113 |
} |
111 | 114 |
} |
Also available in: Unified diff
ref #7854: continue session handling in distribution editor