commit 7cc57f1d2068c7e1da04b77b3b6a68be604363dc
Author: Patrick Plitzner <p.plitzner@bgbm.org>
Date:   Thu Apr 18 13:30:41 2019 +0200

    ref #8242 Refactor states to use DTOs

diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java
index b1d5c05d7..e586da756 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java
@@ -11,7 +11,6 @@ package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix;
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -96,6 +95,7 @@ import ca.odell.glazedlists.EventList;
 import ca.odell.glazedlists.SortedList;
 import ca.odell.glazedlists.TreeList;
 import eu.etaxonomy.cdm.api.application.CdmApplicationState;
+import eu.etaxonomy.cdm.api.service.IVocabularyService;
 import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
 import eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO;
 import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
@@ -107,7 +107,9 @@ import eu.etaxonomy.cdm.model.description.MeasurementUnit;
 import eu.etaxonomy.cdm.model.description.State;
 import eu.etaxonomy.cdm.model.term.FeatureNode;
 import eu.etaxonomy.cdm.model.term.FeatureTree;
+import eu.etaxonomy.cdm.model.term.TermVocabulary;
 import eu.etaxonomy.cdm.persistence.dto.SpecimenNodeWrapper;
+import eu.etaxonomy.cdm.persistence.dto.TermDto;
 import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
 import eu.etaxonomy.taxeditor.editor.l10n.Messages;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
@@ -153,7 +155,7 @@ public class CharacterMatrix extends Composite {
 
     private Map<Integer, Character> indexToCharacterMap = new HashMap<>();
 
-    private Map<Feature, List<State>> categoricalFeatureToStateMap = new HashMap<>();
+    private Map<Feature, List<TermDto>> categoricalFeatureToStateMap = new HashMap<>();
 
     private LinkedMap<String, String> propertyToLabelMap = new LinkedMap<>();
 
@@ -287,19 +289,24 @@ public class CharacterMatrix extends Composite {
         characters = initCharacterList(tree.getRoot());
 
         //init state data for categorical features
-        characters.forEach(character->
-        {
-            if(character.isSupportsCategoricalData()){
-                List<State> supportedStates = new ArrayList<>();
-                character.getSupportedCategoricalEnumerations().forEach(voc->supportedStates.addAll(voc.getTerms()));
-                Collections.sort(supportedStates, (state1, state2)->state1.getLabel().compareTo(state2.getLabel()));
-                categoricalFeatureToStateMap.put(character, supportedStates);
-            }
-        });
+        characters.forEach(character->fetchSupportedStates(character));
+
         descriptions = new BasicEventList<>();
 
     }
 
+    private void fetchSupportedStates(Character character) {
+        if(character.isSupportsCategoricalData()){
+            List<TermDto> supportedStates = new ArrayList<>();
+            Set<TermVocabulary<State>> supportedCategoricalEnumerations = character.getSupportedCategoricalEnumerations();
+            for (TermVocabulary<State> termVocabulary : supportedCategoricalEnumerations) {
+                supportedStates.addAll(CdmStore.getService(IVocabularyService.class).getTerms(termVocabulary.getUuid()));
+            }
+//            Collections.sort(supportedStates, (state1, state2)->state1.getLabel().compareTo(state2.getLabel()));
+            categoricalFeatureToStateMap.put(character, supportedStates);
+        }
+    }
+
     private void createLayers(boolean treeView) {
         SortedList<Object> sortedList = new SortedList<>(descriptions, new MatrixRowComparator());
         // wrap the SortedList with the TreeList
@@ -651,7 +658,7 @@ public class CharacterMatrix extends Composite {
         createTable(isTreeView, freezeLayer.isFrozen());
     }
 
-    public List<State> getSupportedStatesForCategoricalFeature(Feature feature){
+    public List<TermDto> getSupportedStatesForCategoricalFeature(Feature feature){
         return categoricalFeatureToStateMap.get(feature);
     }
 
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/SpecimenColumnPropertyAccessor.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/SpecimenColumnPropertyAccessor.java
index 3fda17c53..cb3227a0e 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/SpecimenColumnPropertyAccessor.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/SpecimenColumnPropertyAccessor.java
@@ -8,12 +8,23 @@
 */
 package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix;
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.UUID;
+import java.util.stream.Collectors;
+
 import org.eclipse.nebula.widgets.nattable.data.IColumnPropertyAccessor;
 
+import eu.etaxonomy.cdm.api.service.ITermService;
 import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
 import eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO;
 import eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO;
 import eu.etaxonomy.cdm.model.description.Feature;
+import eu.etaxonomy.cdm.model.description.State;
+import eu.etaxonomy.cdm.model.term.DefinedTermBase;
+import eu.etaxonomy.cdm.persistence.dto.TermDto;
+import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
  * Property accessor class which maps setting and getting data for
@@ -74,7 +85,18 @@ public class SpecimenColumnPropertyAccessor implements IColumnPropertyAccessor<O
         if(rowObject instanceof RowWrapperDTO){
             RowWrapperDTO rowWrapper = (RowWrapperDTO)rowObject;
             Feature feature = matrix.getIndexToCharacterMap().get(columnIndex);
-            rowWrapper.setDataValueForFeature(feature, newValue);
+            if(newValue instanceof Collection && ((Collection) newValue).stream().allMatch(o->o instanceof TermDto)){
+                List<TermDto> dtos = (List<TermDto>)newValue;
+                List<UUID> termUuids = dtos.stream().map(dto->dto.getUuid()).collect(Collectors.toList());
+                List<DefinedTermBase> terms = CdmStore.getService(ITermService.class).load(termUuids, null);
+                List<State> states = new ArrayList<>();
+                for (DefinedTermBase definedTermBase : terms) {
+                    if(definedTermBase instanceof State){
+                        states.add((State) definedTermBase);
+                    }
+                }
+                rowWrapper.setDataValueForFeature(feature, states);
+            }
         }
     }
 
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/categorical/CategoricalComboBoxDataProvider.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/categorical/CategoricalComboBoxDataProvider.java
index feb256ca9..dee41c68a 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/categorical/CategoricalComboBoxDataProvider.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/categorical/CategoricalComboBoxDataProvider.java
@@ -14,7 +14,7 @@ import java.util.List;
 import org.eclipse.nebula.widgets.nattable.edit.editor.IComboBoxDataProvider;
 
 import eu.etaxonomy.cdm.model.description.Feature;
-import eu.etaxonomy.cdm.model.description.State;
+import eu.etaxonomy.cdm.persistence.dto.TermDto;
 import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrix;
 
 /**
@@ -34,7 +34,7 @@ public class CategoricalComboBoxDataProvider implements IComboBoxDataProvider {
     @Override
     public List<?> getValues(int columnIndex, int rowIndex) {
         Feature feature = matrix.getIndexToCharacterMap().get(columnIndex);
-        List<State> supportedStatesForCategoricalFeature = matrix.getSupportedStatesForCategoricalFeature(feature);
+        List<TermDto> supportedStatesForCategoricalFeature = matrix.getSupportedStatesForCategoricalFeature(feature);
         return supportedStatesForCategoricalFeature;
     }
 
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/categorical/CategoricalDataDisplayConverter.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/categorical/CategoricalDataDisplayConverter.java
index 26714d7a1..8afc77378 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/categorical/CategoricalDataDisplayConverter.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/categorical/CategoricalDataDisplayConverter.java
@@ -14,6 +14,8 @@ import org.eclipse.nebula.widgets.nattable.data.convert.DisplayConverter;
 
 import eu.etaxonomy.cdm.model.description.CategoricalData;
 import eu.etaxonomy.cdm.model.description.State;
+import eu.etaxonomy.cdm.persistence.dto.TermDto;
+import eu.etaxonomy.cdm.remote.l10n.TermRepresentation_L10n;
 
 /**
  * Converts CategoricalData and States of one cell of the character matrix to a
@@ -39,6 +41,10 @@ public class CategoricalDataDisplayConverter extends DisplayConverter {
         else if(canonicalValue instanceof State){
             return ((State) canonicalValue).getLabel();
         }
+        else if(canonicalValue instanceof TermDto){
+            ((TermDto) canonicalValue).localize(new TermRepresentation_L10n());
+            return ((TermDto) canonicalValue).getRepresentation_L10n();
+        }
         else if (canonicalValue instanceof Collection) {
             // Collection.toString() will add [ and ] around
             // the values in the Collection
