*/
package eu.etaxonomy.taxeditor.editor.view.checklist.e4;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO;
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
+import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
import eu.etaxonomy.cdm.model.description.Distribution;
-import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
import eu.etaxonomy.cdm.model.description.TaxonDescription;
import eu.etaxonomy.cdm.model.location.NamedArea;
-
+import eu.etaxonomy.cdm.model.metadata.DistributionDescription;
+import eu.etaxonomy.taxeditor.event.EventUtility;
+import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
/**
* @author k.luther
* @since 28.11.2018
- *
*/
public class DistributionColumnAccessor implements IColumnPropertyAccessor<TaxonDistributionDTO> {
- private DistributionEditor editor;
+
public static final String DEFAULT_ENTRY = "";
+ private DistributionEditor editor;
+
public DistributionColumnAccessor(DistributionEditor editor) {
this.editor = editor;
}
-
- /**
- * {@inheritDoc}
- */
@Override
public Object getDataValue(TaxonDistributionDTO rowObject, int columnIndex) {
+// editor.setActualNameCache(rowObject.getNameCache());
switch (columnIndex) {
case 0:
return rowObject.getNameCache();
case 1:
if (editor.isShowRank()){
return rowObject.getRankString();
+ }else{
+ return rowObject.getConcatenatedSynonyms();
+ }
+ case 2:
+ if (editor.isShowRank()){
+ return rowObject.getConcatenatedSynonyms();
}else{
break;
}
return distributionsForArea.iterator().next();
}
if (distributionsForArea.size() > 1){
+ List<String> labels = new ArrayList();
+ distributionsForArea.forEach(desc -> labels.add(((Distribution)desc).getStatus().getLabel()));
return distributionsForArea;
}
}
}
-
- /**
- * {@inheritDoc}
- */
@Override
public int getColumnCount() {
return editor.getPropertyToLabelMap().size();
}
- /**
- * {@inheritDoc}
- */
@Override
public String getColumnProperty(int columnIndex) {
return editor.getPropertyToLabelMap().get(columnIndex);
}
- /**
- * {@inheritDoc}
- */
@Override
public int getColumnIndex(String propertyName){
return editor.getPropertyToLabelMap().indexOf(propertyName);
}
-
- /**
- * {@inheritDoc}
- */
@Override
public void setDataValue(TaxonDistributionDTO taxonWrapper, int columnIndex, Object newValue) {
- if (newValue instanceof PresenceAbsenceTerm){
+ if (newValue instanceof StatusHelper){
NamedArea area =editor.getAreaToColumnIndexMap().get(columnIndex);
Map<NamedArea, Set<DescriptionElementBase>> distributionMap = editor.taxonDistributionMap.get(taxonWrapper.getTaxonUuid());
if (distributionMap == null){
distributionMap = new HashMap();
editor.taxonDistributionMap.put(taxonWrapper.getTaxonUuid(),distributionMap);
}
+ Distribution dist = null;
Set<DescriptionElementBase> distributions = distributionMap.get(area);
if (distributions != null && !distributions.isEmpty()){
DescriptionElementBase desc = distributions.iterator().next();
if (desc instanceof Distribution){
- if (((PresenceAbsenceTerm)newValue).getId() == 0){
+ if (((StatusHelper)newValue).term.getId() == 0){
desc.getInDescription().removeElement(desc);
distributions.remove(desc);
}else {
- ((Distribution)desc).setStatus((PresenceAbsenceTerm)newValue);
+ ((Distribution)desc).setStatus(((StatusHelper)newValue).term);
}
}
}else{
+ if (((StatusHelper)newValue).term.getId() == 0){
+ return;
+ }
if (distributions == null){
distributions = new HashSet();
distributionMap.put(area, distributions);
}
- Distribution dist = Distribution.NewInstance(area, (PresenceAbsenceTerm)newValue);
+ dist = Distribution.NewInstance(area, ((StatusHelper)newValue).term);
Set<TaxonDescription> descs = taxonWrapper.getDescriptionsWrapper().getDescriptions();
- TaxonDescription desc;
+ TaxonDescription desc = null;
if (descs.size() >= 1){
- desc = descs.iterator().next();
+ Iterator<TaxonDescription> itDesc = descs.iterator();
+ while(itDesc.hasNext()) {
+ TaxonDescription next = itDesc.next();
+ if (next.isDefault()) {
+ desc = next;
+ break;
+ }
+ }
+
+ if (desc == null) {
+ if (PreferencesUtil.getDescriptionForChecklistEditor().equals(DistributionDescription.AlwaysDefault)){
+ desc = TaxonDescription.NewInstance();
+ desc.setDefault(true);
+ taxonWrapper.getDescriptionsWrapper().getDescriptions().add(desc);
+ }else {
+ desc = descs.iterator().next();
+ }
+ }
}else {
- desc = TaxonDescription.NewInstance(taxonWrapper.getTaxon());
+ desc = TaxonDescription.NewInstance();
+ desc.setDefault(true);
+
taxonWrapper.getDescriptionsWrapper().getDescriptions().add(desc);
}
+ if (editor.getDefaultSource() != null){
+ dist.addSource(DescriptionElementSource.NewPrimarySourceInstance(editor.getDefaultSource(), null));
+ }
desc.addElement(dist);
+ if(desc.isPersisted()){
+ editor.part.getCdmEntitySession().load(desc, true);
+ }
distributions.add(dist);
+// EventUtility.postEvent(WorkbenchEventConstants.REFRESH_DETAILS_DISTRIBUTION, taxonWrapper.getNameCache());
}
+ editor.setActualNameCache(taxonWrapper.getNameCache());
+ editor.descriptionsToSave.add(taxonWrapper);
}
+ EventUtility.postEvent(WorkbenchEventConstants.REFRESH_DETAILS, true);
}
-
-}
+}
\ No newline at end of file