Project

General

Profile

« Previous | Next » 

Revision 77aef047

Added by Patrick Plitzner about 5 years ago

ref #8146 Restrict character matrix to characters

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CategoricalChartTooltip.java
58 58

  
59 59
        int colPos = matrix.getNatTable().getColumnPositionByX(event.x);
60 60
        int colIndex = matrix.getNatTable().getColumnIndexByPosition(colPos);
61
        Feature feature = matrix.getIndexToFeatureMap().get(colIndex);
61
        Feature feature = matrix.getIndexToCharacterMap().get(colIndex);
62 62
        CategoricalDataHistogram histogram = matrix.getFeatureToHistogramMap().get(feature);
63 63

  
64 64
        Composite tooltip;
......
82 82
        //get histogram for column
83 83
        int colPos = matrix.getNatTable().getColumnPositionByX(event.x);
84 84
        int colIndex = matrix.getNatTable().getColumnIndexByPosition(colPos);
85
        Feature feature = matrix.getIndexToFeatureMap().get(colIndex);
85
        Feature feature = matrix.getIndexToCharacterMap().get(colIndex);
86 86
        CategoricalDataHistogram histogram = matrix.getFeatureToHistogramMap().get(feature);
87 87

  
88 88
        // set chart title
......
129 129
        int colPos = matrix.getNatTable().getColumnPositionByX(event.x);
130 130
        int colIndex = matrix.getNatTable().getColumnIndexByPosition(colPos);
131 131
        int rowPos = matrix.getNatTable().getRowPositionByY(event.y);
132
        Feature feature = matrix.getIndexToFeatureMap().get(colIndex);
132
        Feature feature = matrix.getIndexToCharacterMap().get(colIndex);
133 133

  
134 134
        if(matrix.isShowTooltips()
135 135
                && rowPos==1
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java
98 98
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
99 99
import eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO;
100 100
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
101
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
101 102
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
102 103
import eu.etaxonomy.cdm.model.description.Character;
103 104
import eu.etaxonomy.cdm.model.description.DescriptionBase;
......
151 152

  
152 153
    private NatTable natTable;
153 154

  
154
    private Map<Integer, Feature> indexToFeatureMap = new HashMap<>();
155
    private Map<Integer, Character> indexToCharacterMap = new HashMap<>();
155 156

  
156 157
    private Map<Feature, List<State>> categoricalFeatureToStateMap = new HashMap<>();
157 158

  
......
169 170

  
170 171
    private FreezeLayer freezeLayer;
171 172

  
172
    private List<Character> features;
173
    private List<Character> characters;
173 174

  
174 175
    private CharacterMatrixPart part;
175 176

  
......
270 271
        natTable.doCommand(new ClientAreaResizeCommand(natTable));
271 272
    }
272 273

  
273
    private List<Character> initFeatureList(FeatureNode node){
274
        List<Character> features = new ArrayList<>();
274
    private List<Character> initCharacterList(FeatureNode node){
275
        List<Character> characters = new ArrayList<>();
275 276
        node.getChildNodes().forEach(childNode->
276 277
                {
277
                    DefinedTermBase feature = childNode.getTerm();
278
                    DefinedTermBase term = childNode.getTerm();
278 279
                    // FIXME #8146 this is currently checked via the termType of the tree
279 280
                    // in the init() method. This may be solved by adding generics to FeatureNode
280 281
                    // so that getTerm is typified. This would make this check obsolete
281
                    if(feature.isInstanceOf(Character.class)){
282
                        features.add((Character) feature);
282
                    if(term.isInstanceOf(Character.class)){
283
                        characters.add(HibernateProxyHelper.deproxy(term, Character.class));
283 284
                    }
284
                    features.addAll(initFeatureList(childNode));
285
                    characters.addAll(initCharacterList(childNode));
285 286
                });
286
        return features;
287
        return characters;
287 288
    }
288 289

  
289 290
    public void initDescriptiveDataSet(DescriptiveDataSet descriptiveDataSet){
290 291
        this.descriptiveDataSet = descriptiveDataSet;
291 292
        //get features/columns stored in descriptive data set
292 293
        FeatureTree tree = descriptiveDataSet.getDescriptiveSystem();
293
        features = initFeatureList(tree.getRoot());
294
        characters = initCharacterList(tree.getRoot());
294 295

  
295 296
        //init state data for categorical features
296
        features.forEach(feature->
297
        characters.forEach(character->
297 298
        {
298
            if(feature.isSupportsCategoricalData()){
299
            if(character.isSupportsCategoricalData()){
299 300
                List<State> supportedStates = new ArrayList<>();
300
                feature.getSupportedCategoricalEnumerations().forEach(voc->supportedStates.addAll(voc.getTerms()));
301
                categoricalFeatureToStateMap.put(feature, supportedStates);
301
                character.getSupportedCategoricalEnumerations().forEach(voc->supportedStates.addAll(voc.getTerms()));
302
                categoricalFeatureToStateMap.put(character, supportedStates);
302 303
            }
303 304
        });
304 305
        descriptions = new BasicEventList<>();
......
369 370
        propertyToLabelMap.put(COLLECTOR_COLUMN, Messages.CharacterMatrix_COLLECTOR_NO);
370 371
        propertyToLabelMap.put(IDENTIFIER_COLUMN, Messages.CharacterMatrix_IDENTIFIER);
371 372
        propertyToLabelMap.put(COUNTRY_COLUMN, Messages.CharacterMatrix_COUNTRY);
372
        for(int i=0;i<features.size();i++){
373
            Feature feature = features.get(i);
374
            initLabels(i, feature);
373
        for(int i=0;i<characters.size();i++){
374
            Character character = characters.get(i);
375
            initLabels(i, character);
375 376
        }
376 377

  
377 378
        // layer for event handling of GlazedLists and PropertyChanges
......
392 393
        //regoster labels with summary prefix for summary layer
393 394
        ColumnOverrideLabelAccumulator summaryColumnLabelAccumulator =new ColumnOverrideLabelAccumulator(bodyDataLayer);
394 395
        summaryRowLayer.setConfigLabelAccumulator(summaryColumnLabelAccumulator);
395
        for(int i=0;i<features.size();i++){
396
            Feature feature = features.get(i);
396
        for(int i=0;i<characters.size();i++){
397
            Character character = characters.get(i);
397 398
            summaryColumnLabelAccumulator.registerColumnOverrides(
398 399
                    i+LEADING_COLUMN_COUNT,
399
                    SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX+MatrixUtility.getProperty(feature));
400
                    SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX+MatrixUtility.getProperty(character));
400 401
        }
401 402
        // because the horizontal dependency is the ViewportLayer
402 403
        // we need to set the composite dependency to false
......
562 563
        }
563 564
    }
564 565

  
565
    private void initLabels(int index, Feature feature) {
566
        indexToFeatureMap.put(index+LEADING_COLUMN_COUNT, feature);
566
    private void initLabels(int index, Character character) {
567
        indexToCharacterMap.put(index+LEADING_COLUMN_COUNT, character);
567 568

  
568
        String featureLabel = feature.getLabel();
569
        String property = featureLabel;
569
        String label = character.getLabel();
570
        String property = label;
570 571
        //show unit for quantitative data
571
        if(feature.isSupportsQuantitativeData()){
572
            Set<MeasurementUnit> recommendedMeasurementUnits = feature.getRecommendedMeasurementUnits();
572
        if(character.isSupportsQuantitativeData()){
573
            Set<MeasurementUnit> recommendedMeasurementUnits = character.getRecommendedMeasurementUnits();
573 574
            if(recommendedMeasurementUnits.size()>1){
574 575
                MessagingUtils.warningDialog(Messages.CharacterMatrix_INIT_PROBLEM, CharacterMatrix.class,
575
                        String.format(Messages.CharacterMatrix_INIT_PROBLEM_MESSAGE, feature.getLabel()));
576
                        String.format(Messages.CharacterMatrix_INIT_PROBLEM_MESSAGE, character.getLabel()));
576 577
            }
577 578
            if(recommendedMeasurementUnits.size()==1){
578 579
                MeasurementUnit unit = recommendedMeasurementUnits.iterator().next();
579
                featureLabel += " ["+unit.getIdInVocabulary()+"]"; //$NON-NLS-1$ //$NON-NLS-2$
580
                label += " ["+unit.getIdInVocabulary()+"]"; //$NON-NLS-1$ //$NON-NLS-2$
580 581
            }
581 582
        }
582
        propertyToLabelMap.put(property, featureLabel);
583
        propertyToLabelMap.put(property, label);
583 584
    }
584 585

  
585 586
    public void loadDescriptions(DescriptiveDataSet descriptiveDataSet) {
......
660 661
        return categoricalFeatureToStateMap.get(feature);
661 662
    }
662 663

  
663
    public Map<Integer, Feature> getIndexToFeatureMap() {
664
        return indexToFeatureMap;
664
    public Map<Integer, Character> getIndexToCharacterMap() {
665
        return indexToCharacterMap;
665 666
    }
666 667

  
667 668
    public LinkedMap<String, String> getPropertyToLabelMap() {
......
723 724
    }
724 725

  
725 726
    public List<Character> getFeatures() {
726
        return features;
727
        return characters;
727 728
    }
728 729

  
729 730
    public Map<Feature, CategoricalDataHistogram> getFeatureToHistogramMap() {
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/QuantitativeChartTooltip.java
58 58

  
59 59
        int colPos = matrix.getNatTable().getColumnPositionByX(event.x);
60 60
        int colIndex = matrix.getNatTable().getColumnIndexByPosition(colPos);
61
        Feature feature = matrix.getIndexToFeatureMap().get(colIndex);
61
        Feature feature = matrix.getIndexToCharacterMap().get(colIndex);
62 62
        QuantitativeDataStatistics dataStatistics = matrix.getFeatureToQuantDataStatisticsMap().get(feature);
63 63

  
64 64
        Composite tooltip;
......
83 83
        //get statistics for column
84 84
        int colPos = matrix.getNatTable().getColumnPositionByX(event.x);
85 85
        int colIndex = matrix.getNatTable().getColumnIndexByPosition(colPos);
86
        Feature feature = matrix.getIndexToFeatureMap().get(colIndex);
86
        Feature feature = matrix.getIndexToCharacterMap().get(colIndex);
87 87
        QuantitativeDataStatistics quantitativeDataStatistics = matrix.getFeatureToQuantDataStatisticsMap().get(feature);
88 88
        List<DescriptiveStatistics> statistics = quantitativeDataStatistics.getStatistics();
89 89

  
......
136 136
        int colPos = matrix.getNatTable().getColumnPositionByX(event.x);
137 137
        int colIndex = matrix.getNatTable().getColumnIndexByPosition(colPos);
138 138
        int rowPos = matrix.getNatTable().getRowPositionByY(event.y);
139
        Feature feature = matrix.getIndexToFeatureMap().get(colIndex);
139
        Feature feature = matrix.getIndexToCharacterMap().get(colIndex);
140 140

  
141 141
        if(matrix.isShowTooltips()
142 142
                && rowPos==1
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/SpecimenColumnPropertyAccessor.java
52 52
            default:
53 53
                break;
54 54
            }
55
            Feature feature = matrix.getIndexToFeatureMap().get(columnIndex);
55
            Feature feature = matrix.getIndexToCharacterMap().get(columnIndex);
56 56
            return rowWrapper.getDataValueForFeature(feature);
57 57
        } else if(rowObject instanceof TaxonRowWrapperDTO){
58 58
            TaxonRowWrapperDTO taxonWrapper = (TaxonRowWrapperDTO)rowObject;
59 59
            if(columnIndex==0){
60 60
                return taxonWrapper.getDescription();
61 61
            }
62
            Feature feature = matrix.getIndexToFeatureMap().get(columnIndex);
62
            Feature feature = matrix.getIndexToCharacterMap().get(columnIndex);
63 63
            return taxonWrapper.getDataValueForFeature(feature);
64 64

  
65 65
        }
......
73 73
    public void setDataValue(Object rowObject, int columnIndex, Object newValue) {
74 74
        if(rowObject instanceof RowWrapperDTO){
75 75
            RowWrapperDTO rowWrapper = (RowWrapperDTO)rowObject;
76
            Feature feature = matrix.getIndexToFeatureMap().get(columnIndex);
76
            Feature feature = matrix.getIndexToCharacterMap().get(columnIndex);
77 77
            rowWrapper.setDataValueForFeature(feature, newValue);
78 78
        }
79 79
    }
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/categorical/CategoricalComboBoxDataProvider.java
34 34

  
35 35
    @Override
36 36
    public List<?> getValues(int columnIndex, int rowIndex) {
37
        Feature feature = matrix.getIndexToFeatureMap().get(columnIndex);
37
        Feature feature = matrix.getIndexToCharacterMap().get(columnIndex);
38 38
        List<State> supportedStatesForCategoricalFeature = matrix.getSupportedStatesForCategoricalFeature(feature);
39 39
        maxVisibleItems = Math.max(3, Math.min(supportedStatesForCategoricalFeature.size()-1, 10));
40 40
        return supportedStatesForCategoricalFeature;
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/categorical/CategoricalDataCellEditor.java
41 41
        if(canonicalValue==null){
42 42
            Object rowWrapper = matrix.getBodyDataProvider().getRowObject(this.getRowIndex());
43 43
            if(rowWrapper instanceof RowWrapperDTO){
44
                Feature feature = matrix.getIndexToFeatureMap().get(getColumnIndex());
44
                Feature feature = matrix.getIndexToCharacterMap().get(getColumnIndex());
45 45
                ((RowWrapperDTO) rowWrapper).addCategoricalData(feature);
46 46
            }
47 47
        }
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/quantitative/QuantitativeDataDialogEditor.java
89 89
            ICellEditHandler editHandler, ILayerCell cell, IConfigRegistry configRegistry) {
90 90
        this.initialInput = null;
91 91
        Object rowObject = matrix.getBodyDataProvider().getRowObject(cell.getRowIndex());
92
        Feature feature = matrix.getIndexToFeatureMap().get(cell.getColumnIndex());
92
        Feature feature = matrix.getIndexToCharacterMap().get(cell.getColumnIndex());
93 93
        QuantitativeData quantitativeData = null;
94 94
        if(rowObject instanceof RowWrapperDTO){
95 95
            if(cell.getDataValue() instanceof QuantitativeData){

Also available in: Unified diff