Project

General

Profile

Revision 7cc57f1d

ID7cc57f1d2068c7e1da04b77b3b6a68be604363dc
Parent baf7d6f0
Child 9b0a1cb8

Added by Patrick Plitzner over 1 year ago

ref #8242 Refactor states to use DTOs

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java
11 11
import java.io.File;
12 12
import java.util.ArrayList;
13 13
import java.util.Collection;
14
import java.util.Collections;
15 14
import java.util.HashMap;
16 15
import java.util.List;
17 16
import java.util.Map;
......
96 95
import ca.odell.glazedlists.SortedList;
97 96
import ca.odell.glazedlists.TreeList;
98 97
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
98
import eu.etaxonomy.cdm.api.service.IVocabularyService;
99 99
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
100 100
import eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO;
101 101
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
......
107 107
import eu.etaxonomy.cdm.model.description.State;
108 108
import eu.etaxonomy.cdm.model.term.FeatureNode;
109 109
import eu.etaxonomy.cdm.model.term.FeatureTree;
110
import eu.etaxonomy.cdm.model.term.TermVocabulary;
110 111
import eu.etaxonomy.cdm.persistence.dto.SpecimenNodeWrapper;
112
import eu.etaxonomy.cdm.persistence.dto.TermDto;
111 113
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
112 114
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
113 115
import eu.etaxonomy.taxeditor.model.MessagingUtils;
......
153 155

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

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

  
158 160
    private LinkedMap<String, String> propertyToLabelMap = new LinkedMap<>();
159 161

  
......
287 289
        characters = initCharacterList(tree.getRoot());
288 290

  
289 291
        //init state data for categorical features
290
        characters.forEach(character->
291
        {
292
            if(character.isSupportsCategoricalData()){
293
                List<State> supportedStates = new ArrayList<>();
294
                character.getSupportedCategoricalEnumerations().forEach(voc->supportedStates.addAll(voc.getTerms()));
295
                Collections.sort(supportedStates, (state1, state2)->state1.getLabel().compareTo(state2.getLabel()));
296
                categoricalFeatureToStateMap.put(character, supportedStates);
297
            }
298
        });
292
        characters.forEach(character->fetchSupportedStates(character));
293

  
299 294
        descriptions = new BasicEventList<>();
300 295

  
301 296
    }
302 297

  
298
    private void fetchSupportedStates(Character character) {
299
        if(character.isSupportsCategoricalData()){
300
            List<TermDto> supportedStates = new ArrayList<>();
301
            Set<TermVocabulary<State>> supportedCategoricalEnumerations = character.getSupportedCategoricalEnumerations();
302
            for (TermVocabulary<State> termVocabulary : supportedCategoricalEnumerations) {
303
                supportedStates.addAll(CdmStore.getService(IVocabularyService.class).getTerms(termVocabulary.getUuid()));
304
            }
305
//            Collections.sort(supportedStates, (state1, state2)->state1.getLabel().compareTo(state2.getLabel()));
306
            categoricalFeatureToStateMap.put(character, supportedStates);
307
        }
308
    }
309

  
303 310
    private void createLayers(boolean treeView) {
304 311
        SortedList<Object> sortedList = new SortedList<>(descriptions, new MatrixRowComparator());
305 312
        // wrap the SortedList with the TreeList
......
651 658
        createTable(isTreeView, freezeLayer.isFrozen());
652 659
    }
653 660

  
654
    public List<State> getSupportedStatesForCategoricalFeature(Feature feature){
661
    public List<TermDto> getSupportedStatesForCategoricalFeature(Feature feature){
655 662
        return categoricalFeatureToStateMap.get(feature);
656 663
    }
657 664

  
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/SpecimenColumnPropertyAccessor.java
8 8
*/
9 9
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix;
10 10

  
11
import java.util.ArrayList;
12
import java.util.Collection;
13
import java.util.List;
14
import java.util.UUID;
15
import java.util.stream.Collectors;
16

  
11 17
import org.eclipse.nebula.widgets.nattable.data.IColumnPropertyAccessor;
12 18

  
19
import eu.etaxonomy.cdm.api.service.ITermService;
13 20
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
14 21
import eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO;
15 22
import eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO;
16 23
import eu.etaxonomy.cdm.model.description.Feature;
24
import eu.etaxonomy.cdm.model.description.State;
25
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
26
import eu.etaxonomy.cdm.persistence.dto.TermDto;
27
import eu.etaxonomy.taxeditor.store.CdmStore;
17 28

  
18 29
/**
19 30
 * Property accessor class which maps setting and getting data for
......
74 85
        if(rowObject instanceof RowWrapperDTO){
75 86
            RowWrapperDTO rowWrapper = (RowWrapperDTO)rowObject;
76 87
            Feature feature = matrix.getIndexToCharacterMap().get(columnIndex);
77
            rowWrapper.setDataValueForFeature(feature, newValue);
88
            if(newValue instanceof Collection && ((Collection) newValue).stream().allMatch(o->o instanceof TermDto)){
89
                List<TermDto> dtos = (List<TermDto>)newValue;
90
                List<UUID> termUuids = dtos.stream().map(dto->dto.getUuid()).collect(Collectors.toList());
91
                List<DefinedTermBase> terms = CdmStore.getService(ITermService.class).load(termUuids, null);
92
                List<State> states = new ArrayList<>();
93
                for (DefinedTermBase definedTermBase : terms) {
94
                    if(definedTermBase instanceof State){
95
                        states.add((State) definedTermBase);
96
                    }
97
                }
98
                rowWrapper.setDataValueForFeature(feature, states);
99
            }
78 100
        }
79 101
    }
80 102

  
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/categorical/CategoricalComboBoxDataProvider.java
14 14
import org.eclipse.nebula.widgets.nattable.edit.editor.IComboBoxDataProvider;
15 15

  
16 16
import eu.etaxonomy.cdm.model.description.Feature;
17
import eu.etaxonomy.cdm.model.description.State;
17
import eu.etaxonomy.cdm.persistence.dto.TermDto;
18 18
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrix;
19 19

  
20 20
/**
......
34 34
    @Override
35 35
    public List<?> getValues(int columnIndex, int rowIndex) {
36 36
        Feature feature = matrix.getIndexToCharacterMap().get(columnIndex);
37
        List<State> supportedStatesForCategoricalFeature = matrix.getSupportedStatesForCategoricalFeature(feature);
37
        List<TermDto> supportedStatesForCategoricalFeature = matrix.getSupportedStatesForCategoricalFeature(feature);
38 38
        return supportedStatesForCategoricalFeature;
39 39
    }
40 40

  
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/categorical/CategoricalDataDisplayConverter.java
14 14

  
15 15
import eu.etaxonomy.cdm.model.description.CategoricalData;
16 16
import eu.etaxonomy.cdm.model.description.State;
17
import eu.etaxonomy.cdm.persistence.dto.TermDto;
18
import eu.etaxonomy.cdm.remote.l10n.TermRepresentation_L10n;
17 19

  
18 20
/**
19 21
 * Converts CategoricalData and States of one cell of the character matrix to a
......
39 41
        else if(canonicalValue instanceof State){
40 42
            return ((State) canonicalValue).getLabel();
41 43
        }
44
        else if(canonicalValue instanceof TermDto){
45
            ((TermDto) canonicalValue).localize(new TermRepresentation_L10n());
46
            return ((TermDto) canonicalValue).getRepresentation_L10n();
47
        }
42 48
        else if (canonicalValue instanceof Collection) {
43 49
            // Collection.toString() will add [ and ] around
44 50
            // the values in the Collection

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)