ref #8146 Restrict character matrix to characters
authorPatrick Plitzner <p.plitzner@bgbm.org>
Thu, 28 Feb 2019 15:55:58 +0000 (16:55 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Thu, 28 Feb 2019 15:55:58 +0000 (16:55 +0100)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CategoricalChartTooltip.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/QuantitativeChartTooltip.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/SpecimenColumnPropertyAccessor.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/categorical/CategoricalComboBoxDataProvider.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/categorical/CategoricalDataCellEditor.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialogEditor.java

index a1f3d57a8fa1b870882277b9dfc67c79364b1c3f..04434a3f29c3ed1f4665ca8dc371e1bc8fb5c5dd 100644 (file)
@@ -58,7 +58,7 @@ public class CategoricalChartTooltip extends ToolTip {
 
         int colPos = matrix.getNatTable().getColumnPositionByX(event.x);
         int colIndex = matrix.getNatTable().getColumnIndexByPosition(colPos);
-        Feature feature = matrix.getIndexToFeatureMap().get(colIndex);
+        Feature feature = matrix.getIndexToCharacterMap().get(colIndex);
         CategoricalDataHistogram histogram = matrix.getFeatureToHistogramMap().get(feature);
 
         Composite tooltip;
@@ -82,7 +82,7 @@ public class CategoricalChartTooltip extends ToolTip {
         //get histogram for column
         int colPos = matrix.getNatTable().getColumnPositionByX(event.x);
         int colIndex = matrix.getNatTable().getColumnIndexByPosition(colPos);
-        Feature feature = matrix.getIndexToFeatureMap().get(colIndex);
+        Feature feature = matrix.getIndexToCharacterMap().get(colIndex);
         CategoricalDataHistogram histogram = matrix.getFeatureToHistogramMap().get(feature);
 
         // set chart title
@@ -129,7 +129,7 @@ public class CategoricalChartTooltip extends ToolTip {
         int colPos = matrix.getNatTable().getColumnPositionByX(event.x);
         int colIndex = matrix.getNatTable().getColumnIndexByPosition(colPos);
         int rowPos = matrix.getNatTable().getRowPositionByY(event.y);
-        Feature feature = matrix.getIndexToFeatureMap().get(colIndex);
+        Feature feature = matrix.getIndexToCharacterMap().get(colIndex);
 
         if(matrix.isShowTooltips()
                 && rowPos==1
index 9b46710d70fdcb7ca11c4828fcf83606b3ad9510..343536d2514d5ebce746120dcc461e25436ee12c 100644 (file)
@@ -98,6 +98,7 @@ import eu.etaxonomy.cdm.api.application.CdmApplicationState;
 import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
 import eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO;
 import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
 import eu.etaxonomy.cdm.model.description.Character;
 import eu.etaxonomy.cdm.model.description.DescriptionBase;
@@ -151,7 +152,7 @@ public class CharacterMatrix extends Composite {
 
     private NatTable natTable;
 
-    private Map<Integer, Feature> indexToFeatureMap = new HashMap<>();
+    private Map<Integer, Character> indexToCharacterMap = new HashMap<>();
 
     private Map<Feature, List<State>> categoricalFeatureToStateMap = new HashMap<>();
 
@@ -169,7 +170,7 @@ public class CharacterMatrix extends Composite {
 
     private FreezeLayer freezeLayer;
 
-    private List<Character> features;
+    private List<Character> characters;
 
     private CharacterMatrixPart part;
 
@@ -270,35 +271,35 @@ public class CharacterMatrix extends Composite {
         natTable.doCommand(new ClientAreaResizeCommand(natTable));
     }
 
-    private List<Character> initFeatureList(FeatureNode node){
-        List<Character> features = new ArrayList<>();
+    private List<Character> initCharacterList(FeatureNode node){
+        List<Character> characters = new ArrayList<>();
         node.getChildNodes().forEach(childNode->
                 {
-                    DefinedTermBase feature = childNode.getTerm();
+                    DefinedTermBase term = childNode.getTerm();
                     // FIXME #8146 this is currently checked via the termType of the tree
                     // in the init() method. This may be solved by adding generics to FeatureNode
                     // so that getTerm is typified. This would make this check obsolete
-                    if(feature.isInstanceOf(Character.class)){
-                        features.add((Character) feature);
+                    if(term.isInstanceOf(Character.class)){
+                        characters.add(HibernateProxyHelper.deproxy(term, Character.class));
                     }
-                    features.addAll(initFeatureList(childNode));
+                    characters.addAll(initCharacterList(childNode));
                 });
-        return features;
+        return characters;
     }
 
     public void initDescriptiveDataSet(DescriptiveDataSet descriptiveDataSet){
         this.descriptiveDataSet = descriptiveDataSet;
         //get features/columns stored in descriptive data set
         FeatureTree tree = descriptiveDataSet.getDescriptiveSystem();
-        features = initFeatureList(tree.getRoot());
+        characters = initCharacterList(tree.getRoot());
 
         //init state data for categorical features
-        features.forEach(feature->
+        characters.forEach(character->
         {
-            if(feature.isSupportsCategoricalData()){
+            if(character.isSupportsCategoricalData()){
                 List<State> supportedStates = new ArrayList<>();
-                feature.getSupportedCategoricalEnumerations().forEach(voc->supportedStates.addAll(voc.getTerms()));
-                categoricalFeatureToStateMap.put(feature, supportedStates);
+                character.getSupportedCategoricalEnumerations().forEach(voc->supportedStates.addAll(voc.getTerms()));
+                categoricalFeatureToStateMap.put(character, supportedStates);
             }
         });
         descriptions = new BasicEventList<>();
@@ -369,9 +370,9 @@ public class CharacterMatrix extends Composite {
         propertyToLabelMap.put(COLLECTOR_COLUMN, Messages.CharacterMatrix_COLLECTOR_NO);
         propertyToLabelMap.put(IDENTIFIER_COLUMN, Messages.CharacterMatrix_IDENTIFIER);
         propertyToLabelMap.put(COUNTRY_COLUMN, Messages.CharacterMatrix_COUNTRY);
-        for(int i=0;i<features.size();i++){
-            Feature feature = features.get(i);
-            initLabels(i, feature);
+        for(int i=0;i<characters.size();i++){
+            Character character = characters.get(i);
+            initLabels(i, character);
         }
 
         // layer for event handling of GlazedLists and PropertyChanges
@@ -392,11 +393,11 @@ public class CharacterMatrix extends Composite {
         //regoster labels with summary prefix for summary layer
         ColumnOverrideLabelAccumulator summaryColumnLabelAccumulator =new ColumnOverrideLabelAccumulator(bodyDataLayer);
         summaryRowLayer.setConfigLabelAccumulator(summaryColumnLabelAccumulator);
-        for(int i=0;i<features.size();i++){
-            Feature feature = features.get(i);
+        for(int i=0;i<characters.size();i++){
+            Character character = characters.get(i);
             summaryColumnLabelAccumulator.registerColumnOverrides(
                     i+LEADING_COLUMN_COUNT,
-                    SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX+MatrixUtility.getProperty(feature));
+                    SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX+MatrixUtility.getProperty(character));
         }
         // because the horizontal dependency is the ViewportLayer
         // we need to set the composite dependency to false
@@ -562,24 +563,24 @@ public class CharacterMatrix extends Composite {
         }
     }
 
-    private void initLabels(int index, Feature feature) {
-        indexToFeatureMap.put(index+LEADING_COLUMN_COUNT, feature);
+    private void initLabels(int index, Character character) {
+        indexToCharacterMap.put(index+LEADING_COLUMN_COUNT, character);
 
-        String featureLabel = feature.getLabel();
-        String property = featureLabel;
+        String label = character.getLabel();
+        String property = label;
         //show unit for quantitative data
-        if(feature.isSupportsQuantitativeData()){
-            Set<MeasurementUnit> recommendedMeasurementUnits = feature.getRecommendedMeasurementUnits();
+        if(character.isSupportsQuantitativeData()){
+            Set<MeasurementUnit> recommendedMeasurementUnits = character.getRecommendedMeasurementUnits();
             if(recommendedMeasurementUnits.size()>1){
                 MessagingUtils.warningDialog(Messages.CharacterMatrix_INIT_PROBLEM, CharacterMatrix.class,
-                        String.format(Messages.CharacterMatrix_INIT_PROBLEM_MESSAGE, feature.getLabel()));
+                        String.format(Messages.CharacterMatrix_INIT_PROBLEM_MESSAGE, character.getLabel()));
             }
             if(recommendedMeasurementUnits.size()==1){
                 MeasurementUnit unit = recommendedMeasurementUnits.iterator().next();
-                featureLabel += " ["+unit.getIdInVocabulary()+"]"; //$NON-NLS-1$ //$NON-NLS-2$
+                label += " ["+unit.getIdInVocabulary()+"]"; //$NON-NLS-1$ //$NON-NLS-2$
             }
         }
-        propertyToLabelMap.put(property, featureLabel);
+        propertyToLabelMap.put(property, label);
     }
 
     public void loadDescriptions(DescriptiveDataSet descriptiveDataSet) {
@@ -660,8 +661,8 @@ public class CharacterMatrix extends Composite {
         return categoricalFeatureToStateMap.get(feature);
     }
 
-    public Map<Integer, Feature> getIndexToFeatureMap() {
-        return indexToFeatureMap;
+    public Map<Integer, Character> getIndexToCharacterMap() {
+        return indexToCharacterMap;
     }
 
     public LinkedMap<String, String> getPropertyToLabelMap() {
@@ -723,7 +724,7 @@ public class CharacterMatrix extends Composite {
     }
 
     public List<Character> getFeatures() {
-        return features;
+        return characters;
     }
 
     public Map<Feature, CategoricalDataHistogram> getFeatureToHistogramMap() {
index 14a1acccc2089660ad226b6275a0a96a3173c71a..1a930b521b2fa28bc746e39160af6e5b07d483f5 100644 (file)
@@ -58,7 +58,7 @@ public class QuantitativeChartTooltip extends DefaultToolTip {
 
         int colPos = matrix.getNatTable().getColumnPositionByX(event.x);
         int colIndex = matrix.getNatTable().getColumnIndexByPosition(colPos);
-        Feature feature = matrix.getIndexToFeatureMap().get(colIndex);
+        Feature feature = matrix.getIndexToCharacterMap().get(colIndex);
         QuantitativeDataStatistics dataStatistics = matrix.getFeatureToQuantDataStatisticsMap().get(feature);
 
         Composite tooltip;
@@ -83,7 +83,7 @@ public class QuantitativeChartTooltip extends DefaultToolTip {
         //get statistics for column
         int colPos = matrix.getNatTable().getColumnPositionByX(event.x);
         int colIndex = matrix.getNatTable().getColumnIndexByPosition(colPos);
-        Feature feature = matrix.getIndexToFeatureMap().get(colIndex);
+        Feature feature = matrix.getIndexToCharacterMap().get(colIndex);
         QuantitativeDataStatistics quantitativeDataStatistics = matrix.getFeatureToQuantDataStatisticsMap().get(feature);
         List<DescriptiveStatistics> statistics = quantitativeDataStatistics.getStatistics();
 
@@ -136,7 +136,7 @@ public class QuantitativeChartTooltip extends DefaultToolTip {
         int colPos = matrix.getNatTable().getColumnPositionByX(event.x);
         int colIndex = matrix.getNatTable().getColumnIndexByPosition(colPos);
         int rowPos = matrix.getNatTable().getRowPositionByY(event.y);
-        Feature feature = matrix.getIndexToFeatureMap().get(colIndex);
+        Feature feature = matrix.getIndexToCharacterMap().get(colIndex);
 
         if(matrix.isShowTooltips()
                 && rowPos==1
index fbd34673ad8acf4755cf05b996f419de1c40f862..3fda17c536d8ceacc891190bdb63a671c5dd69b6 100644 (file)
@@ -52,14 +52,14 @@ public class SpecimenColumnPropertyAccessor implements IColumnPropertyAccessor<O
             default:
                 break;
             }
-            Feature feature = matrix.getIndexToFeatureMap().get(columnIndex);
+            Feature feature = matrix.getIndexToCharacterMap().get(columnIndex);
             return rowWrapper.getDataValueForFeature(feature);
         } else if(rowObject instanceof TaxonRowWrapperDTO){
             TaxonRowWrapperDTO taxonWrapper = (TaxonRowWrapperDTO)rowObject;
             if(columnIndex==0){
                 return taxonWrapper.getDescription();
             }
-            Feature feature = matrix.getIndexToFeatureMap().get(columnIndex);
+            Feature feature = matrix.getIndexToCharacterMap().get(columnIndex);
             return taxonWrapper.getDataValueForFeature(feature);
 
         }
@@ -73,7 +73,7 @@ public class SpecimenColumnPropertyAccessor implements IColumnPropertyAccessor<O
     public void setDataValue(Object rowObject, int columnIndex, Object newValue) {
         if(rowObject instanceof RowWrapperDTO){
             RowWrapperDTO rowWrapper = (RowWrapperDTO)rowObject;
-            Feature feature = matrix.getIndexToFeatureMap().get(columnIndex);
+            Feature feature = matrix.getIndexToCharacterMap().get(columnIndex);
             rowWrapper.setDataValueForFeature(feature, newValue);
         }
     }
index 645158c1f4efebb102eb4426c955de5d2f3492fb..4985a9a0fff6412069e061b7532777570f411d94 100644 (file)
@@ -34,7 +34,7 @@ public class CategoricalComboBoxDataProvider implements IComboBoxDataProvider {
 
     @Override
     public List<?> getValues(int columnIndex, int rowIndex) {
-        Feature feature = matrix.getIndexToFeatureMap().get(columnIndex);
+        Feature feature = matrix.getIndexToCharacterMap().get(columnIndex);
         List<State> supportedStatesForCategoricalFeature = matrix.getSupportedStatesForCategoricalFeature(feature);
         maxVisibleItems = Math.max(3, Math.min(supportedStatesForCategoricalFeature.size()-1, 10));
         return supportedStatesForCategoricalFeature;
index d9492203e7382974f6fc7746707af2be0a03b868..f29abe64d74fefcc7ceaeb20a6a73fbad0d064e6 100644 (file)
@@ -41,7 +41,7 @@ public class CategoricalDataCellEditor extends ComboBoxCellEditor{
         if(canonicalValue==null){
             Object rowWrapper = matrix.getBodyDataProvider().getRowObject(this.getRowIndex());
             if(rowWrapper instanceof RowWrapperDTO){
-                Feature feature = matrix.getIndexToFeatureMap().get(getColumnIndex());
+                Feature feature = matrix.getIndexToCharacterMap().get(getColumnIndex());
                 ((RowWrapperDTO) rowWrapper).addCategoricalData(feature);
             }
         }
index 215b4be1da6f505d79d7431f487457c9fa63f818..b65e98463f92498690deaf690375be25374e5f17 100644 (file)
@@ -89,7 +89,7 @@ public class QuantitativeDataDialogEditor extends AbstractDialogCellEditor {
             ICellEditHandler editHandler, ILayerCell cell, IConfigRegistry configRegistry) {
         this.initialInput = null;
         Object rowObject = matrix.getBodyDataProvider().getRowObject(cell.getRowIndex());
-        Feature feature = matrix.getIndexToFeatureMap().get(cell.getColumnIndex());
+        Feature feature = matrix.getIndexToCharacterMap().get(cell.getColumnIndex());
         QuantitativeData quantitativeData = null;
         if(rowObject instanceof RowWrapperDTO){
             if(cell.getDataValue() instanceof QuantitativeData){