2 * Copyright (C) 2018 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.editor
.view
.checklist
.e4
;
11 import java
.util
.ArrayList
;
12 import java
.util
.HashMap
;
13 import java
.util
.HashSet
;
14 import java
.util
.List
;
18 import org
.eclipse
.nebula
.widgets
.nattable
.data
.IColumnPropertyAccessor
;
20 import eu
.etaxonomy
.cdm
.api
.service
.dto
.TaxonDistributionDTO
;
21 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
22 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
23 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTerm
;
24 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
25 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
33 public class DistributionColumnAccessor
implements IColumnPropertyAccessor
<TaxonDistributionDTO
> {
34 private DistributionEditor editor
;
35 public static final String DEFAULT_ENTRY
= "";
37 public DistributionColumnAccessor(DistributionEditor editor
) {
46 public Object
getDataValue(TaxonDistributionDTO rowObject
, int columnIndex
) {
47 switch (columnIndex
) {
49 return rowObject
.getNameCache();
51 if (editor
.isShowRank()){
52 return rowObject
.getRankString();
59 NamedArea area
= editor
.getAreaToColumnIndexMap().get(columnIndex
);
61 //TODO: do not get the distribution objcts, but the label of the status.
62 Map
<NamedArea
, Set
<DescriptionElementBase
>> distributionMap
= editor
.taxonDistributionMap
.get(rowObject
.getTaxonUuid());
63 if (distributionMap
!= null){
64 Set
<DescriptionElementBase
> distributionsForArea
= editor
.taxonDistributionMap
.get(rowObject
.getTaxonUuid()).get(area
);
65 if (distributionsForArea
== null){
68 if (distributionsForArea
.size() == 1){
69 return distributionsForArea
.iterator().next();
71 if (distributionsForArea
.size() > 1){
72 List
<String
> labels
= new ArrayList();
73 distributionsForArea
.forEach(desc
-> labels
.add(((Distribution
)desc
).getStatus().getLabel()));
86 public int getColumnCount() {
87 return editor
.getPropertyToLabelMap().size();
94 public String
getColumnProperty(int columnIndex
) {
95 return editor
.getPropertyToLabelMap().get(columnIndex
);
102 public int getColumnIndex(String propertyName
){
103 return editor
.getPropertyToLabelMap().indexOf(propertyName
);
111 public void setDataValue(TaxonDistributionDTO taxonWrapper
, int columnIndex
, Object newValue
) {
112 if (newValue
instanceof PresenceAbsenceTerm
){
113 NamedArea area
=editor
.getAreaToColumnIndexMap().get(columnIndex
);
114 Map
<NamedArea
, Set
<DescriptionElementBase
>> distributionMap
= editor
.taxonDistributionMap
.get(taxonWrapper
.getTaxonUuid());
115 if (distributionMap
== null){
116 distributionMap
= new HashMap();
117 editor
.taxonDistributionMap
.put(taxonWrapper
.getTaxonUuid(),distributionMap
);
119 Set
<DescriptionElementBase
> distributions
= distributionMap
.get(area
);
120 if (distributions
!= null && !distributions
.isEmpty()){
121 DescriptionElementBase desc
= distributions
.iterator().next();
122 if (desc
instanceof Distribution
){
123 if (((PresenceAbsenceTerm
)newValue
).getId() == 0){
124 desc
.getInDescription().removeElement(desc
);
125 distributions
.remove(desc
);
127 ((Distribution
)desc
).setStatus((PresenceAbsenceTerm
)newValue
);
131 if (distributions
== null){
132 distributions
= new HashSet();
133 distributionMap
.put(area
, distributions
);
135 Distribution dist
= Distribution
.NewInstance(area
, (PresenceAbsenceTerm
)newValue
);
136 Set
<TaxonDescription
> descs
= taxonWrapper
.getDescriptionsWrapper().getDescriptions();
137 TaxonDescription desc
;
138 if (descs
.size() >= 1){
139 desc
= descs
.iterator().next();
141 desc
= TaxonDescription
.NewInstance();
142 taxonWrapper
.getDescriptionsWrapper().getDescriptions().add(desc
);
144 desc
.addElement(dist
);
145 editor
.part
.getCdmEntitySession().load(desc
, true);
146 distributions
.add(dist
);